| java.lang.Object org.apache.turbine.util.template.SelectorBox
SelectorBox | public class SelectorBox (Code) | | This class is for generating a SelectorBox. It is good when used
with WM because you can stuff it into the context and then just
call it to generate the HTML. It can be used in other cases as
well, but WM is the best case for it right now.
For example code showing the usage for this module, please see
the toString() method below to see how it would be refered to from
WM.
// get the roles for a user
RoleSet userRoles = new DefaultAccessControl().getRoles(loginid, null);
if ( userRoles != null )
{
context.put("hasRoleSet", Boolean.TRUE);
// get an array of the users roles
Role[] usersRoles = userRoles.getRolesArray();
// get an array of all the roles in the system
Role[] allRoles = ((RoleSet)RolePeer.retrieveSet()).getRolesArray();
Object[] names = new Object[allRoles.length];
Object[] values = new Object[allRoles.length];
for ( int i=0;i<allRoles.length; i++ )
{
names[i] = new Integer(allRoles[i].getPrimaryKey()).toString();
values[i] = allRoles[i].getName();
}
SelectorBox sb = new SelectorBox("roleSetBox", names, values);
sb.buildBooleans(usersRoles, allRoles);
context.put("roleSetBox", sb);
}
else
{
context.put("hasRoleSet", Boolean.FALSE);
}
author: Jon S. Stevens version: $Id: SelectorBox.java 534527 2007-05-02 16:10:59Z tv $ |
Constructor Summary | |
public | SelectorBox(String name, Object[] names, Object[] values) Generic constructor, builds a select box with a default size of
1 and no selected items. | public | SelectorBox(String name, Object[] names, Object[] values, int size) Generic constructor builds a select box. | public | SelectorBox(String name, Object[] names, Object[] values, boolean[] selected) Generic constructor builds a select box. | public | SelectorBox(String name, Object[] names, Object[] values, int size, boolean[] selected) Primary constructor for everything. |
Method Summary | |
public void | buildBooleans(Object[] selectedSet, Object[] entireSet) Pass in an array of selected items and the entire set of items
and it will determine which items in the selected set are also
in the entireset and then build a boolean[] up that is the same
size as the entireSet with markings to tell whether or not the
items are marked or not. | public void | reset() Resets the internal state of the SelectorBox. | public SelectorBox | setMultiple(boolean val) This allows you to set the multiple attribute to the select
element. | public SelectorBox | setName(String name) This allows one to set the name= attribute to the select
element.
Parameters: name - A String with the name. | public SelectorBox | setOnChange(String script) | public SelectorBox | setSelected(boolean[] bools) This allows one to set the array of selected booleans. | public SelectorBox | setSelected(Object name) This will set all elements as unselected, except for the
element(s) with the given name.
Parameters: name - The name to appear as selected. | public SelectorBox | setSize(int size) This allows one to set the size of the select element.
Parameters: size - An int with the size. | public String | toString(int size) This builds out the select box at a certain size. | public String | toString() This builds out the select box at a certain size. |
SelectorBox | public SelectorBox(String name, Object[] names, Object[] values)(Code) | | Generic constructor, builds a select box with a default size of
1 and no selected items.
Parameters: name - A String with the name for the select box. Parameters: names - An Object[] with the names. Parameters: values - An Object[] with the values. |
SelectorBox | public SelectorBox(String name, Object[] names, Object[] values, int size)(Code) | | Generic constructor builds a select box.
Parameters: name - A String with the name for the select box. Parameters: names - An Object[] with the names. Parameters: values - An Object[] with the values. Parameters: size - An int specifying the size. |
SelectorBox | public SelectorBox(String name, Object[] names, Object[] values, boolean[] selected)(Code) | | Generic constructor builds a select box.
Parameters: name - A String with the name for the select box. Parameters: names - An Object[] with the names. Parameters: values - An Object[] with the values. Parameters: selected - A boolean[] with the selected items. |
SelectorBox | public SelectorBox(String name, Object[] names, Object[] values, int size, boolean[] selected)(Code) | | Primary constructor for everything.
Parameters: name - A String with the name for the select box. Parameters: names - An Object[] with the names. Parameters: values - An Object[] with the values. Parameters: size - An int specifying the size. Parameters: selected - A boolean[] with the selected items. |
buildBooleans | public void buildBooleans(Object[] selectedSet, Object[] entireSet)(Code) | | Pass in an array of selected items and the entire set of items
and it will determine which items in the selected set are also
in the entireset and then build a boolean[] up that is the same
size as the entireSet with markings to tell whether or not the
items are marked or not. It uses toString().equalsIgnoreCase()
on the Object in the Object[] to determine if the items are
equal.
Parameters: selectedSet - An Object[]. Parameters: entireSet - An Object[]. |
reset | public void reset()(Code) | | Resets the internal state of the SelectorBox.
|
setMultiple | public SelectorBox setMultiple(boolean val)(Code) | | This allows you to set the multiple attribute to the select
element. Example usage from within WM is like this:
$selectBox.setMultiple(true).toString(4)
Parameters: val - True if multiple selection should be allowed. A SelectorBox (self). |
setName | public SelectorBox setName(String name)(Code) | | This allows one to set the name= attribute to the select
element.
Parameters: name - A String with the name. A SelectorBox (self). |
setOnChange | public SelectorBox setOnChange(String script)(Code) | | This allows one to set an onChange attribute on the select tag
Parameters: script - A string with the script to put in onChange A SelectorBox (self). |
setSelected | public SelectorBox setSelected(boolean[] bools)(Code) | | This allows one to set the array of selected booleans.
Parameters: an - array of booleans A SelectorBox (self). |
setSelected | public SelectorBox setSelected(Object name)(Code) | | This will set all elements as unselected, except for the
element(s) with the given name.
Parameters: name - The name to appear as selected. A SelectorBox (self). |
setSize | public SelectorBox setSize(int size)(Code) | | This allows one to set the size of the select element.
Parameters: size - An int with the size. A SelectorBox (self). |
toString | public String toString(int size)(Code) | | This builds out the select box at a certain size. To use this
element in WM, you simply build this object in your java code,
put it into the context and then call $selectBox.toString(5).
Parameters: size - An int with the size. A String with the HTML code. |
toString | public String toString()(Code) | | This builds out the select box at a certain size. To use this
element in WM, you simply build this object in your java code,
put it into the context and then call $selectBox and it will
build it with the default size of 1.
A String with the HTML code. |
|
|