use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class UtilHandlers method mapGet.
/**
* <p> Returns the value to which the input map maps the input key. </p>
*
* <p> Input value: "Map" -- Type: <code>java.util.Map</code>
* <p> Input value: "Key" -- Type: <code>Object</code>
* <p> Output value: "Value" -- Type: <code>Object</code></p>
* @param handlerCtx The HandlerContext.
*/
@Handler(id = "mapGet", input = { @HandlerInput(name = "Map", type = Map.class, required = true), @HandlerInput(name = "Key", type = Object.class, required = true) }, output = { @HandlerOutput(name = "Value", type = Object.class) })
public static void mapGet(HandlerContext handlerCtx) {
Map map = (Map) handlerCtx.getInputValue("Map");
Object key = (Object) handlerCtx.getInputValue("Key");
handlerCtx.setOutputValue("Value", (Object) map.get(key));
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class UtilHandlers method convertListToCommaString.
@Handler(id = "convertListToCommaString", input = { @HandlerInput(name = "list", type = List.class, required = true) }, output = { @HandlerOutput(name = "commaString", type = String.class) })
public static void convertListToCommaString(HandlerContext handlerCtx) {
List list = (List) handlerCtx.getInputValue("list");
String commaString = "";
if ((list != null) && list.size() > 0) {
commaString = GuiUtil.listToString(list, ",");
}
handlerCtx.setOutputValue("commaString", commaString);
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class UtilHandlers method foreach.
/**
* <p> This handler provides the foreach loop functionality. You should
* specify a request attribute 'var' that will be used as the key for
* storing each token in the list. You can then retrieve each value
* as the loop iterates by requesting the request scoped attribute
* keyed by the value you supplied for 'var'. You must also specify
* the <code>List<Object></code> to iterate over.</p>
* @param handlerCtx
* @return
*/
@Handler(id = "foreach", input = { @HandlerInput(name = "var", type = String.class, required = false, defaultValue = "idx"), @HandlerInput(name = "list", type = Collection.class, required = true) })
public static boolean foreach(HandlerContext handlerCtx) {
String var = (String) handlerCtx.getInputValue("var");
Collection<Object> list = (Collection<Object>) handlerCtx.getInputValue("list");
List<com.sun.jsftemplating.layout.descriptors.handler.Handler> handlers = handlerCtx.getHandler().getChildHandlers();
if (handlers.size() > 0) {
// We have child handlers in the loop... execute while we iterate
LayoutElement elt = handlerCtx.getLayoutElement();
Map<String, Object> requestMap = handlerCtx.getFacesContext().getExternalContext().getRequestMap();
if (list != null) {
for (Object obj : list) {
requestMap.put(var, obj);
// Ignore whats returned by the handler... we need to return
// false anyway to prevent children from being executed again
// FIXME: Consider supporting a "break" type of functionality
elt.dispatchHandlers(handlerCtx, handlers);
}
}
}
// This will prevent the child handlers from executing again
return false;
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class UtilHandlers method listAdd.
/**
* <p> Adds the given value to a <code>List</code></p>
* <p> Input list: "list" -- Type: <code>java.util.List</code>
* <p> Input value: "value" -- Type: <code>java.lang.Object</code>
* <p> Input value: "index" -- Type: <code>Integer</code>
*
* @param handlerCtx The HandlerContext
*/
@Handler(id = "listAdd", input = { @HandlerInput(name = "list", type = List.class), @HandlerInput(name = "value", type = Object.class, required = true), @HandlerInput(name = "index", type = Integer.class), @HandlerInput(name = "sort", type = boolean.class, defaultValue = "false") }, output = { @HandlerOutput(name = "result", type = List.class) })
public static void listAdd(HandlerContext handlerCtx) {
List list = (List) handlerCtx.getInputValue("list");
Integer index = (Integer) handlerCtx.getInputValue("index");
if (list == null) {
list = new ArrayList();
}
if (index == null) {
list.add(handlerCtx.getInputValue("value"));
} else {
list.add(index, handlerCtx.getInputValue("value"));
}
boolean sort = (Boolean) handlerCtx.getInputValue("sort");
if (sort) {
Collections.sort(list);
}
handlerCtx.setOutputValue("result", list);
}
use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.
the class UtilHandlers method mapJoin.
@Handler(id = "mapJoin", input = { @HandlerInput(name = "map", type = Map.class, required = true), @HandlerInput(name = "sep", type = String.class, defaultValue = ","), @HandlerInput(name = "skipBlankValues", type = Boolean.class, defaultValue = "true") }, output = { @HandlerOutput(name = "result", type = String.class) })
public static void mapJoin(HandlerContext handlerCtx) {
Map map = (Map) handlerCtx.getInputValue("map");
String sep = (String) handlerCtx.getInputValue("sep");
Boolean skipBlankValues = (Boolean) handlerCtx.getInputValue("skipBlankValues");
String sepHolder = "";
assert (map != null);
StringBuilder result = new StringBuilder();
for (Map.Entry entry : (Set<Map.Entry>) map.entrySet()) {
Object value = entry.getValue();
if (skipBlankValues && ((value == null) || (value.toString().isEmpty()))) {
continue;
}
result.append(sepHolder).append(entry.getKey()).append("=").append(entry.getValue());
sepHolder = sep;
}
handlerCtx.setOutputValue("result", result.toString());
}
Aggregations