org.sakaiproject.jsf.renderer.PopupRenderer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsf-widgets Show documentation
Show all versions of jsf-widgets Show documentation
This is the Maven project for the custom JSF widgets.
The widgets and the resources projects are closely tied together.
These widgets will be deployed as a jar file containing Sakai JSF widgets
(components).
Web applications can include this jar in order to use the Sakai JSF
widgets in a JSF tool.
/**********************************************************************************
* $URL$
* $Id$
***********************************************************************************
*
* Copyright (c) 2003, 2004, 2005, 2006, 2008 The Sakai Foundation
*
* Licensed under the Educational Community License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.opensource.org/licenses/ECL-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**********************************************************************************/
package org.sakaiproject.jsf.renderer;
import java.io.IOException;
import java.util.Iterator;
import javax.faces.component.UIComponent;
import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.render.Renderer;
import org.sakaiproject.jsf.util.RendererUtil;
/**
* Description:
* This class is the class that renders the popup
* custom tag.
* Copyright: Copyright (c) 2004
* Organization: Sakai Project
* @author Ed Smiley
* @version $Id$
*/
public class PopupRenderer
extends Renderer {
public boolean supportsComponentType(UIComponent component) {
return (component instanceof UIOutput);
}
public void decode(FacesContext context, UIComponent component) {
}
/**
* This component renders its children
* @return true
*/
public boolean getRendersChildren()
{
return true;
}
/**
* Do nothing if a button, otherwise, default.
* @param context FacesContext
* @param component UIComponent
* @throws IOException
*/
public void encodeChildren(FacesContext context, UIComponent component) throws
IOException {
String buttonSwitch = (String) RendererUtil.getAttribute(context, component, "useButton");
boolean useButton = Boolean.getBoolean(
RendererUtil.makeSwitchString(buttonSwitch, false, true, true, false, false, false));
if (useButton)
{
return;
}
else
{
Iterator iter = component.getChildren().iterator();
while (iter.hasNext()) {
UIComponent kid = (UIComponent) iter.next();
RendererUtil.encodeRecursive(context, kid);
}
}
}
/**
* Faces render output method .
* Method Generator: org.sakaiproject.tool.assessment.devtoolsRenderMaker
*
* @param context FacesContext
for the current request
* @param component UIComponent
being rendered
*
* @throws IOException if an input/output error occurs
*/
public void encodeBegin(FacesContext context, UIComponent component) throws
IOException {
if ( !component.isRendered())
{
return;
}
ResponseWriter writer = context.getResponseWriter();
String id = (String) component.getClientId(context);
String title = (String) RendererUtil.getAttribute(context, component, "title");
String url = (String) RendererUtil.getAttribute(context, component, "url");
String target = (String) RendererUtil.getAttribute(context, component, "target");
String toolbar = (String) RendererUtil.getAttribute(context, component, "toolbar");
String menubar = (String) RendererUtil.getAttribute(context, component, "menubar");
String personalbar = (String) RendererUtil.getAttribute(context, component, "personalbar");
// temporary workaround ClassCastException
String width = null;//(String) RendererUtil.getAttribute(context, component, "width");
String height = null; //(String) RendererUtil.getAttribute(context, component, "height");
String scrollbars = (String) RendererUtil.getAttribute(context, component, "scrollbars");
String resizable = (String) RendererUtil.getAttribute(context, component, "resizable");
if (title == null) {
title = " ";
}
if (target == null) {
target = "sakai_popup"; /** todo: put in resource*/
}
if (width == null) {
width = "650";
}
if (height == null) {
height = "375";
}
toolbar = RendererUtil.makeSwitchString(toolbar, false, true, true, true, false, false);
menubar = RendererUtil.makeSwitchString(menubar, false, true, true, true, false, false);
personalbar = RendererUtil.makeSwitchString(personalbar, false, true, true, true, false, false);
scrollbars = RendererUtil.makeSwitchString(scrollbars, false, true, true, true, false, false);
resizable = RendererUtil.makeSwitchString(resizable, false, true, true, true, false, false);
String buttonSwitch = (String) RendererUtil.getAttribute(context, component, "useButton");
boolean useButton = Boolean.getBoolean(
RendererUtil.makeSwitchString(buttonSwitch, false, true, true, false, false, false));
if (useButton) {
writer.write("");
writer.write("");
}
else {
writer.write("");
writer.write("");
writer.write(title);
}
}
/**
* Render end of ANCHOR.
*
* @param context FacesContext for the request we are processing
* @param component UIComponent to be rendered
*
* @param context FacesContext
for the current request
* @param component UIComponent
being rendered
*
* @throws IOException if an input/output error occurs
*/
public void encodeEnd(FacesContext context, UIComponent component) throws
IOException {
if (!component.isRendered())
{
return;
}
ResponseWriter writer = context.getResponseWriter();
String buttonSwitch = (String) RendererUtil.getAttribute(context, component, "useButton");
boolean useButton = Boolean.getBoolean(
RendererUtil.makeSwitchString(buttonSwitch, false, true, true, false, false, false));
if (!useButton) {
writer.write("");
}
}
}