Search in sources :

Example 56 with Handler

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));
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) Handler(com.sun.jsftemplating.annotation.Handler)

Example 57 with Handler

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);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Handler(com.sun.jsftemplating.annotation.Handler)

Example 58 with Handler

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&lt;Object&gt;</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;
}
Also used : LayoutElement(com.sun.jsftemplating.layout.descriptors.LayoutElement) Collection(java.util.Collection) Handler(com.sun.jsftemplating.annotation.Handler) Handler(com.sun.jsftemplating.annotation.Handler)

Example 59 with Handler

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);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Handler(com.sun.jsftemplating.annotation.Handler)

Example 60 with Handler

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());
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) Map(java.util.Map) Handler(com.sun.jsftemplating.annotation.Handler)

Aggregations

Handler (com.sun.jsftemplating.annotation.Handler)167 ArrayList (java.util.ArrayList)85 Map (java.util.Map)85 List (java.util.List)82 HashMap (java.util.HashMap)81 TreeMap (java.util.TreeMap)14 IOException (java.io.IOException)12 Date (java.util.Date)9 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)8 LayoutViewHandler (com.sun.jsftemplating.layout.LayoutViewHandler)8 Image (com.sun.pkg.client.Image)8 ListIterator (java.util.ListIterator)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 FacesContext (javax.faces.context.FacesContext)7 AttributeList (javax.management.AttributeList)7 RestResponse (org.glassfish.admingui.common.util.RestResponse)7 URL (java.net.URL)6 IntegrationPoint (org.glassfish.admingui.connector.IntegrationPoint)6 MultipleListDataProvider (com.sun.jsftemplating.component.dataprovider.MultipleListDataProvider)5 TableRowGroup (com.sun.webui.jsf.component.TableRowGroup)5