Base data model for breadCrumb, dropdownListBox and listBox.
Method |
Description |
Argument |
Return value |
---|---|---|---|
addItem |
Add item (entry) to the list |
(java.lang.String key, java.lang.String text) |
void |
addSelection |
Selects an item with the given key. Clicking on an selected item does NOT fire an event. |
(java.lang.String sel) |
void |
getKeyByIndex |
Returns the key of an item with specified index. |
(int index) |
java.lang.String |
getKeys |
Returns an iterator for all keys in the list. |
() |
java.util.Iterator |
getMultiSelection |
Returns the keys of the currently selected items. The model must be a multi selection model. |
() |
lang.String[] |
getNameofKeyColumn |
Returns the name of the column containing the key values if the list model is associated with a table (for example, JCOListModel). |
() |
java.lang.String |
getNameofTextColumn |
Gets the name of the column containing the visible texts if the list model is associated with a table (for example, JCOListModel). |
() |
java.lang.String |
getSingleSelection |
Gets the key of the currently selected item if the model is a single selection model. |
() |
java.lang.String |
getTextByIndex |
Returns the visible text of an item with the specified index. |
(int index) |
java.lang.String |
getTextForKey |
Returns the text associated with the key. |
(java.lang.String key) |
java.lang.String |
isSelected |
Returns the status (selected or not selected) for an item with the specified index. |
(int index) |
boolean |
isSelected |
Returns the status (selected or not selected) for an item with the specified index. |
(java.lang.String key) |
boolean |
isSingleSelection |
Returns the status of the model (Singleselect or Multiselect). |
() |
boolean |
removeSelection |
Deselects an item with the given key. |
(java.lang.String sel) |
void |
setNameOfKeyColumn |
Sets the name of the column containing the key values if the list model is associated with a table (for example, JCOListModel). This method has now visible effect. |
(java.lang.String n) |
void |
setNameOfTextColumn |
Sets the name of the column containing the visible texts if the list model is associated with a table (for example, JCOListModel). This method has now visible effect. |
(java.lang.String n) |
void |
setSelection |
Selects an item with the given key. The selection from previous selected items is removed. Clicking on an selected item does NOT fire an event. |
(java.lang.String key) |
void |
setSingleSelection |
Defines the selection mode for the model. Set to true one item can be selected at one time, set to false multiple entries can be selected. If the model is set to multiple select mode, no event for the control must be defined to avoid events when multiple selects are made. Multiple selects can be made by holding the <Shift> or <Strg>/<Ctrl> key down and click on the entries. |
(boolean selection) |
void |
size |
Returns the number of items/entries in the list. |
() |
int |
Setting the model
Syntax
import com.sap.htmlb.BreadCrumb; import com.sap.htmlb.IListModel; import com.sap.htmlb.DefaultListModel; public class BreadCrumbBean { private IListModel model; /* Constructor - set the basic item (Home) */ public BreadCrumbBean() { /* create model */ model = new DefaultListModel(); /* add items to the model */ model.addItem("start", "Start"); model.addItem("level1", "1stVisitedPage"); model.addItem("level2", "2ndVisitedPage"); model.addItem("actlevel", "ActualLevel"); /* pre select an item in the model */ model.addSelection("level1"); } /* get and set method for the model */ public IListModel getModel() { return this.model; } public void setModel(IListModel bc) { model = bc; } }
Getting selected items
The example assumes that a listBox in a JSP has the attribute 'onSelect' set, so that an event is fired when the user clicks in the list. We define a method 'onSelect' in the DynPage to handle the event. The method grabs the listBox id, retrieves the selected items and put the string of the selected items in a StringBuffer.
Syntax
public void onSelect(Event event) throws PageException { /* Handles event from the listbox get the listbox by name. The listbox id in the JSP is "LB_Pick" */ ListBox lb = (ListBox) this.getComponentByName("LB_Pick"); /* retrieve the items with method "getMultiSelection */ String[] selection = lb.getMultiSelection(); StringBuffer sel = new StringBuffer(); /* get number of items in selection with the "length" method - for loop to store it in StringBuffer */ for (int i = 0; i < selection.length; i++) { sel.append(selection[i] + " "); } }