Search in sources :

Example 11 with Handler

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

Example 12 with Handler

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

Example 13 with Handler

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);
        }
    }
}
Also used : HashMap(java.util.HashMap) MultipleListDataProvider(com.sun.jsftemplating.component.dataprovider.MultipleListDataProvider) ArrayList(java.util.ArrayList) List(java.util.List) TableRowGroup(com.sun.webui.jsf.component.TableRowGroup) ListIterator(java.util.ListIterator) Handler(com.sun.jsftemplating.annotation.Handler)

Example 14 with Handler

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);
}
Also used : Hyperlink(com.sun.webui.jsf.component.Hyperlink) Handler(com.sun.jsftemplating.annotation.Handler)

Example 15 with Handler

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);
}
Also used : Calendar(com.sun.webui.jsf.component.Calendar) 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