Search in sources :

Example 1 with MultipleListDataProvider

use of com.sun.jsftemplating.component.dataprovider.MultipleListDataProvider 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 2 with MultipleListDataProvider

use of com.sun.jsftemplating.component.dataprovider.MultipleListDataProvider in project Payara by payara.

the class TableHandlers method deleteTableRows.

/**
 *	<p> This handler deletes the given <code>RowKey</code>s.</p>
 *
 *	@param	handlerCtx	The HandlerContext.
 */
@Handler(id = "deleteTableRows", input = { @HandlerInput(name = "tableRowGroup", type = TableRowGroup.class, required = true), @HandlerInput(name = "rowKeys", type = RowKey[].class, required = true) })
public static void deleteTableRows(HandlerContext handlerCtx) {
    TableRowGroup trg = (TableRowGroup) handlerCtx.getInputValue("tableRowGroup");
    RowKey[] keys = (RowKey[]) handlerCtx.getInputValue("rowKeys");
    MultipleListDataProvider dp = (MultipleListDataProvider) trg.getSourceData();
    for (RowKey key : keys) {
        dp.removeRow(key);
    }
}
Also used : RowKey(com.sun.data.provider.RowKey) MultipleListDataProvider(com.sun.jsftemplating.component.dataprovider.MultipleListDataProvider) TableRowGroup(com.sun.webui.jsf.component.TableRowGroup) Handler(com.sun.jsftemplating.annotation.Handler)

Example 3 with MultipleListDataProvider

use of com.sun.jsftemplating.component.dataprovider.MultipleListDataProvider in project Payara by payara.

the class TableHandlers method getSelectedSingleMapRows.

/**
 *	<p> This handler looks at the input TableRowGroup, checks which row is selected, and returns a list of the Map.
 *  <p> Each Map corresponding to one single row of the table.
 *  <p> This method only works for the table where each row consists of one single map since it only looks at the
 *  <p> first element that is returned by the getObject() method of <code>MultipleListDataProvider<code>.
 *
 *  <p> Input  value: "TableRowGroup" -- Type: <code> com.sun.webui.jsf.component.TableRowGroup</code></p>
 *  <p> Input  value: "selectedRows" -- Type: <code> java.util.List</code></p>
 *	@param	handlerCtx	The HandlerContext.
 */
@Handler(id = "getSelectedSingleMapRows", input = { @HandlerInput(name = "TableRowGroup", type = TableRowGroup.class, required = true) }, output = { @HandlerOutput(name = "selectedRows", type = List.class) })
public static void getSelectedSingleMapRows(HandlerContext handlerCtx) {
    TableRowGroup trg = (TableRowGroup) handlerCtx.getInputValue("TableRowGroup");
    MultipleListDataProvider dp = (MultipleListDataProvider) trg.getSourceData();
    List selectedList = new ArrayList();
    try {
        RowKey[] rowKeys = trg.getSelectedRowKeys();
        for (int i = 0; i < rowKeys.length; i++) {
            Object[] multiDataRows = (Object[]) dp.getObject(rowKeys[i]);
            Object oneMap = multiDataRows[0];
            selectedList.add(oneMap);
        }
        handlerCtx.setOutputValue("selectedRows", selectedList);
    } catch (Exception ex) {
        GuiUtil.prepareException(handlerCtx, ex);
    }
}
Also used : RowKey(com.sun.data.provider.RowKey) MultipleListDataProvider(com.sun.jsftemplating.component.dataprovider.MultipleListDataProvider) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TableRowGroup(com.sun.webui.jsf.component.TableRowGroup) Handler(com.sun.jsftemplating.annotation.Handler)

Example 4 with MultipleListDataProvider

use of com.sun.jsftemplating.component.dataprovider.MultipleListDataProvider in project Payara by payara.

the class TableHandlers method commitTableRowGroup.

/**
 *	<p> This handler commits the changes to a <code>TableRowGroup</code>'s
 *	    DataProvider.</p>
 *
 *	@param	handlerCtx	The HandlerContext.
 */
@Handler(id = "commitTableRowGroup", input = { @HandlerInput(name = "tableRowGroup", type = TableRowGroup.class, required = true) })
public static void commitTableRowGroup(HandlerContext handlerCtx) {
    TableRowGroup trg = (TableRowGroup) handlerCtx.getInputValue("tableRowGroup");
    MultipleListDataProvider dp = (MultipleListDataProvider) trg.getSourceData();
    dp.commitChanges();
}
Also used : MultipleListDataProvider(com.sun.jsftemplating.component.dataprovider.MultipleListDataProvider) TableRowGroup(com.sun.webui.jsf.component.TableRowGroup) Handler(com.sun.jsftemplating.annotation.Handler)

Example 5 with MultipleListDataProvider

use of com.sun.jsftemplating.component.dataprovider.MultipleListDataProvider in project Payara by payara.

the class TableHandlers method getAllSingleMapRows.

/**
 *	<p> This handler takes TableRowGroup as input and returns a List of Map objects.
 *  <p> The List returned contains Map objects with each Map representing one single row.
 *  <p> This method only works for tables where each row consists of one single map
 *
 *  <p> Input  value: "TableRowGroup" -- Type: <code> com.sun.webui.jsf.component.TableRowGroup</code></p>
 *  <p> Output  value: "Rows" -- Type: <code> java.util.List</code></p>
 *	@param	handlerCtx	The HandlerContext.
 */
@Handler(id = "getAllSingleMapRows", input = { @HandlerInput(name = "TableRowGroup", type = TableRowGroup.class, required = true) }, output = { @HandlerOutput(name = "Rows", type = List.class) })
public static void getAllSingleMapRows(HandlerContext handlerCtx) {
    TableRowGroup trg = (TableRowGroup) handlerCtx.getInputValue("TableRowGroup");
    MultipleListDataProvider dp = (MultipleListDataProvider) trg.getSourceData();
    List data = dp.getLists();
    try {
        handlerCtx.setOutputValue("Rows", data.get(0));
    } catch (Exception ex) {
        // TODO alert user, log exception
        System.out.println("!!!! getAllSingleMapRows() Throws Exception: " + ex.toString());
    }
}
Also used : MultipleListDataProvider(com.sun.jsftemplating.component.dataprovider.MultipleListDataProvider) ArrayList(java.util.ArrayList) List(java.util.List) TableRowGroup(com.sun.webui.jsf.component.TableRowGroup) Handler(com.sun.jsftemplating.annotation.Handler)

Aggregations

Handler (com.sun.jsftemplating.annotation.Handler)5 MultipleListDataProvider (com.sun.jsftemplating.component.dataprovider.MultipleListDataProvider)5 TableRowGroup (com.sun.webui.jsf.component.TableRowGroup)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 RowKey (com.sun.data.provider.RowKey)2 HashMap (java.util.HashMap)1 ListIterator (java.util.ListIterator)1