. Message for "Website" changes to "Web Project" for appropriate wizards and actions

. New JSF component called SelectList
 - This generic selection component displays a graphical list of items, each with an optional icon, label, description and tooltip.
 - The list has three selection modes; single select (radio), multi-select (checkbox) and 'active' selection mode.
 - The 'active' selection mode renders any child command components (such as ActionLink or CommandButton components) which can then data-bind to each row item in the list. i.e. to allow buttons or links with context for each item.
 - This various selection modes covers the usage for 4 different screens in the WCM wireframes
. Forms page (new step 2) added to Create Web Project wizard
 - this is currently mostly a test page for the SelectList component

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4236 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2006-10-26 17:42:08 +00:00
parent 07686ab8ce
commit 202f9d5957
11 changed files with 432 additions and 122 deletions

View File

@@ -19,44 +19,50 @@ package org.alfresco.web.ui.common.component;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.faces.component.NamingContainer;
import javax.faces.component.UICommand;
import javax.faces.component.UIComponent;
import javax.faces.component.UIForm;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.el.ValueBinding;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.FacesEvent;
import org.alfresco.web.ui.common.Utils;
/**
* The SelectList component displays a graphical list of items, each with a label and icon image.
* The list has three selection modes; single select (radio), multi-select (checkbox) and active
* selection mode (child action components).
*
* The value for the component is collection of UIListItem objects or a UIListItems instance.
*
* For passive single and multi-select modes, the selected value(s) can be retrieved from the component.
* For active selection mode, appropriate child components such as Command buttons or Action Links
* will be rendered for each item in the list, data-binding to the specified 'var' variable should be
* used to bind required params. It is then up to the developer to retrieve the selected item param
* from the actionListener of the appropriate child component.
*
* @author Kevin Roast
*/
public class UISelectList extends UICommand
public class UISelectList extends UIInput
{
private Boolean multiSelect;
private String buttonLabel;
private Boolean activeSelect;
// ------------------------------------------------------------------------------
// Construction
// Component Impl
/**
* Default Constructor
* Default constructor
*/
public UISelectList()
{
setRendererType(null);
}
// ------------------------------------------------------------------------------
// Component Impl
/**
* @see javax.faces.component.UIComponent#getFamily()
@@ -75,7 +81,7 @@ public class UISelectList extends UICommand
// standard component attributes are restored by the super class
super.restoreState(context, values[0]);
this.multiSelect = (Boolean)values[1];
this.buttonLabel = (String)values[2];
this.activeSelect = (Boolean)values[2];
}
/**
@@ -87,26 +93,38 @@ public class UISelectList extends UICommand
// standard component attributes are saved by the super class
values[0] = super.saveState(context);
values[1] = this.multiSelect;
values[2] = this.buttonLabel;
values[2] = this.activeSelect;
return (values);
}
/**
* @see javax.faces.render.Renderer#decode(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
* @see javax.faces.component.UIComponentBase#decode(javax.faces.context.FacesContext)
*/
public void decode(FacesContext context, UIComponent component)
public void decode(FacesContext context)
{
Map requestMap = context.getExternalContext().getRequestParameterMap();
String fieldId = getHiddenFieldName(context, component);
String value = (String)requestMap.get(fieldId);
Map valuesMap = context.getExternalContext().getRequestParameterValuesMap();
// we encoded the value to start with our Id
if (value != null && value.startsWith(component.getClientId(context) + NamingContainer.SEPARATOR_CHAR))
{
String selectedValue = value.substring(component.getClientId(context).length() + 1);
}
// save the selected values that match our component Id
setSubmittedValue((String[])valuesMap.get(getClientId(context)));
}
/**
* @see javax.faces.component.UIComponentBase#encodeChildren(javax.faces.context.FacesContext)
*/
public void encodeChildren(FacesContext context) throws IOException
{
// we encode child components explicity
}
/**
* @see javax.faces.component.UIComponentBase#getRendersChildren()
*/
public boolean getRendersChildren()
{
return true;
}
/**
* @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext)
*/
@@ -117,8 +135,29 @@ public class UISelectList extends UICommand
return;
}
// Prepare the data-binding variable "var" ready for the each cycle of
// renderering for the child components.
String var = (String)getAttributes().get("var");
Map requestMap = context.getExternalContext().getRequestMap();
ResponseWriter out = context.getResponseWriter();
out.write("<table cellspacing=0 cellpadding=0");
String style = (String)getAttributes().get("style");
if (style != null)
{
out.write(" style='");
out.write(style);
out.write('\'');
}
String styleClass = (String)getAttributes().get("styleClass");
if (styleClass != null)
{
out.write(" class=");
out.write(styleClass);
}
out.write('>');
// get the child components and look for compatible ListItem objects
for (Iterator i = getChildren().iterator(); i.hasNext(); /**/)
{
@@ -134,6 +173,10 @@ public class UISelectList extends UICommand
UIListItem item = (UIListItem)iter.next();
if (item.isRendered())
{
if (var != null)
{
requestMap.put(var, item);
}
renderItem(context, out, item);
}
}
@@ -145,10 +188,20 @@ public class UISelectList extends UICommand
{
// found a valid UIListItem child to render
UIListItem item = (UIListItem)child;
if (var != null)
{
requestMap.put(var, item);
}
renderItem(context, out, item);
}
}
}
if (var != null)
{
requestMap.remove(var);
}
out.write("</table>");
}
/**
@@ -159,14 +212,106 @@ public class UISelectList extends UICommand
* @param item UIListItem representing the item to render
*/
private void renderItem(FacesContext context, ResponseWriter out, UIListItem item)
throws IOException
{
}
/**
* @see javax.faces.component.UICommand#broadcast(javax.faces.event.FacesEvent)
*/
public void broadcast(FacesEvent event) throws AbortProcessingException
{
boolean activeSelect = isActiveSelect();
// begin the row, add tooltip if present
String tooltip = item.getTooltip();
out.write("<tr title=\"");
out.write(tooltip != null ? tooltip : "");
out.write("\">");
if (activeSelect == false)
{
// we are rendering passive select list, so either multi or single selection using
// checkboxes or radio button control respectively
boolean multiSelect = isMultiSelect();
String id = getClientId(context);
String itemValue = item.getValue().toString();
out.write("<td");
Utils.outputAttribute(out, getAttributes().get("itemStyle"), "style");
Utils.outputAttribute(out, getAttributes().get("itemStyleClass"), "class");
out.write(" width=16><input type='");
out.write(multiSelect ? "checkbox" : "radio");
out.write("' name='");
out.write(id);
out.write("' id='");
out.write(id);
out.write("' value='");
out.write(itemValue);
out.write('\'');
String[] value = (String[])getValue();
if (multiSelect)
{
if (value != null)
{
for (int i=0; i<value.length; i++)
{
if (value[i].equals(itemValue))
{
out.write(" CHECKED");
break;
}
}
}
}
else
{
if (value != null && value.length == 1 && value[0].equals(itemValue))
{
out.write(" CHECKED");
}
}
out.write("></td>");
}
// optional 32x32 pixel icon
String icon = item.getImage();
if (icon != null)
{
out.write("<td");
Utils.outputAttribute(out, getAttributes().get("itemStyle"), "style");
Utils.outputAttribute(out, getAttributes().get("itemStyleClass"), "class");
out.write(" width=34>"); // give pixel space around edges
out.write(Utils.buildImageTag(context, icon, 32, 32, ""));
out.write("</td>");
}
// label and description text
String description = item.getDescription();
out.write("<td");
Utils.outputAttribute(out, getAttributes().get("itemStyle"), "style");
Utils.outputAttribute(out, getAttributes().get("itemStyleClass"), "class");
out.write("><div style='padding:2px'>");
out.write(item.getLabel());
out.write("</div><div style='padding:2px'>");
if (description != null)
{
out.write(description);
}
out.write("</div></td>");
if (activeSelect)
{
// we are rendering an active select list with child components next to each item
// get the child components and look for compatible Command objects
out.write("<td");
Utils.outputAttribute(out, getAttributes().get("itemStyle"), "style");
Utils.outputAttribute(out, getAttributes().get("itemStyleClass"), "class");
out.write('>');
for (Iterator i = getChildren().iterator(); i.hasNext(); /**/)
{
UIComponent child = (UIComponent)i.next();
if (child instanceof UICommand)
{
out.write("<span style='padding:1px'>");
Utils.encodeRecursive(context, child);
out.write("</span>");
}
}
out.write("</td>");
}
}
@@ -208,25 +353,37 @@ public class UISelectList extends UICommand
}
/**
* @return Returns the action button label.
* Get the active selection mode flag
*
* @return true for active selection mode, false otherwise
*/
public String getButtonLabel()
public boolean isActiveSelect()
{
ValueBinding vb = getValueBinding("buttonLabel");
ValueBinding vb = getValueBinding("activeSelect");
if (vb != null)
{
this.buttonLabel = (String)vb.getValue(getFacesContext());
this.activeSelect = (Boolean)vb.getValue(getFacesContext());
}
return this.buttonLabel;
if (this.activeSelect != null)
{
return this.activeSelect.booleanValue();
}
else
{
// return the default
return false;
}
}
/**
* @param buttonLabel The action button label to set.
* Set true for active selection mode, false otherwise
*
* @param activeSelect True for active selection
*/
public void setButtonLabel(String buttonLabel)
public void setActiveSelect(boolean activeSelect)
{
this.buttonLabel = buttonLabel;
this.activeSelect = activeSelect;
}