use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class TableHandlers method getProperties.
/**
* <p> This handler converts the table List to a Properties map.
*
* @param handlerCtx The HandlerContext.
*/
@Handler(id = "getProperties", input = { @HandlerInput(name = "NewList", type = List.class, required = true) }, output = { @HandlerOutput(name = "AddProps", type = Map.class) })
public static void getProperties(HandlerContext handlerCtx) {
List newList = (List) handlerCtx.getInputValue("NewList");
ListIterator li = newList.listIterator();
Map addProps = new Properties();
while (li.hasNext()) {
Map props = (Map) li.next();
String name = (String) props.get("name");
if (name != null && (!name.trim().equals(""))) {
String value = (String) props.get("value");
if (value != null && (!value.trim().equals(""))) {
addProps.put(name, value);
}
}
}
handlerCtx.setOutputValue("AddProps", addProps);
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class TableHandlers method getTableListFromProperties.
/**
* <p> This handler takes in a HashMap, the name-value pair being the Properties.
* It turns each name-value pair to one hashMap, representing one row of table data,
* and returns the list of Map.
*
* <p> Input value: "Properties" -- Type: <code>java.util.Map</code>/</p>
* <p> Output value: "TableList" -- Type: <code>java.util.List</code>/</p>
* @param handlerCtx The HandlerContext.
*/
@Handler(id = "getTableListFromProperties", input = { @HandlerInput(name = "Properties", type = Map.class, required = true) }, output = { @HandlerOutput(name = "TableList", type = List.class) })
public static void getTableListFromProperties(HandlerContext handlerCtx) {
List data = new ArrayList();
Map<String, Object> props = (Map) handlerCtx.getInputValue("Properties");
if (props != null) {
for (Map.Entry<String, Object> e : props.entrySet()) {
HashMap oneRow = new HashMap();
Object value = e.getValue();
String valString = (value == null) ? "" : value.toString();
oneRow.put("name", e.getKey());
oneRow.put("value", valString);
oneRow.put("selected", false);
data.add(oneRow);
}
}
handlerCtx.setOutputValue("TableList", data);
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class TableHandlers method addRowToTable.
/**
* <p> This handler adds one row to table
* <p> Input value: "TableRowGroup" -- Type: <code> com.sun.webui.jsf.component.TableRowGroup</code></p>
* <p> Input value: "NameList" -- Type:<code>java.util.List</code></p>
* <p> Input value: "DefaultValueList" -- Type:<code>java.util.List</code></p>
* <p> Input value: "HasSelected" -- Type:<code>java.lang.Boolean</code></p>
* @param handlerCtx The HandlerContext.
*/
@Handler(id = "addRowToTable", input = { @HandlerInput(name = "TableRowGroup", type = TableRowGroup.class, required = true), @HandlerInput(name = "NameList", type = List.class), @HandlerInput(name = "HasSelected", type = Boolean.class), @HandlerInput(name = "DefaultValueList", type = List.class) })
public static void addRowToTable(HandlerContext handlerCtx) {
TableRowGroup trg = (TableRowGroup) handlerCtx.getInputValue("TableRowGroup");
List names = (List) handlerCtx.getInputValue("NameList");
List defaults = (List) handlerCtx.getInputValue("DefaultValueList");
Boolean hasSelected = (Boolean) handlerCtx.getInputValue("HasSelected");
MultipleListDataProvider dp = (MultipleListDataProvider) trg.getSourceData();
List data = dp.getLists();
ListIterator li = data.listIterator();
if (li.hasNext()) {
// Get the first List and create a new Map to represent the row
List list = (List) li.next();
Map<String, Object> map = new HashMap<String, Object>();
if (names != null) {
// Fill it up...
if (defaults != null) {
if (names.size() != defaults.size()) {
throw new IllegalArgumentException("NameList.size(" + names.size() + ") does not match DefaultValueList.size(" + defaults.size() + ")!");
}
ListIterator ni = names.listIterator();
ListIterator dv = defaults.listIterator();
while (ni.hasNext() && dv.hasNext()) {
String name = (String) ni.next();
String value = (String) dv.next();
if ("#{true}".equals(value)) {
map.put(name, true);
} else if ("#{false}".equals(value)) {
map.put(name, false);
} else {
map.put(name, value);
}
}
} else {
ListIterator ni = names.listIterator();
while (ni.hasNext()) {
String name = (String) ni.next();
map.put(name, "");
}
}
} else if (defaults == null) {
// Use a simple name/value default...
map.put("name", "");
map.put("value", "");
}
// Add the Map to the List
list.add(0, map);
// See if we have more lists of map... if so put selected in it
if (li.hasNext()) {
list = (List) li.next();
map = new HashMap<String, Object>();
list.add(0, map);
}
// Add selected column (either to the 1st or 2nd map)
if (hasSelected == null) {
map.put("selected", false);
} else {
if (hasSelected.booleanValue()) {
map.put("selected", false);
}
}
// Add something to the remaining Maps (if any)
while (li.hasNext()) {
list = (List) li.next();
map = new HashMap<String, Object>();
list.add(0, map);
}
}
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class WoodstockHandler method dummyHyperlinkArray.
@Handler(id = "dummyHyperlinkArray", output = { @HandlerOutput(name = "links", type = Hyperlink[].class) })
public static void dummyHyperlinkArray(HandlerContext handlerCtx) {
Hyperlink[] arr = new Hyperlink[1];
arr[0] = new Hyperlink();
arr[0].setText(">");
handlerCtx.setOutputValue("links", arr);
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class WoodstockHandler method getDatePattern.
/**
* <p>
* Returns the date pattern for this calendar component.
*/
@Handler(id = "getDatePattern", input = { @HandlerInput(name = "calendarComponent", type = com.sun.webui.jsf.component.Calendar.class, required = true) }, output = { @HandlerOutput(name = "pattern", type = String.class) })
public static void getDatePattern(HandlerContext handlerCtx) {
Calendar calendar = (Calendar) handlerCtx.getInputValue("calendarComponent");
String pattern = calendar.getDateFormatPattern();
if (pattern == null || pattern.length() == 0) {
pattern = calendar.getDatePicker().getDateFormatPattern();
if (pattern == null || pattern.length() == 0) {
// default pattern
pattern = "MM/dd/yyyy";
}
}
handlerCtx.setOutputValue("pattern", pattern);
}
Aggregations