dev@jsftemplating.java.net

Re: JSFTemplating: Table Handler example

From: Ken Paulsen <Ken.Paulsen_at_Sun.COM>
Date: Fri, 19 Jan 2007 14:33:57 -0800

Sorry!

Ken

Karam Singh Badesha wrote:
> Ken,
> I think you forgot to add the file. Please attach the file and send
> email again.
>
> thanks
> Karam
>
> Ken Paulsen wrote:
>>
>> Hi Karam,
>>
>> Attached is an example table.jsf file that I have used to try out a
>> few basic things. All the data is defined in the .jsf file so, it
>> makes it simple to see what is required. There are additional
>> features that are implemented as well that you may not need. Anyway,
>> take a look and feel free to ask questions. One thing I will point
>> out is that the "data" property for the TableRowGroup factory expects
>> a List of List of Object (List<List<Object>>)... in the example the
>> "Obect" type is "Map". The outer list is used to allow multiple
>> sources to provide row information. The inner list contains rows.
>> The Object is data for the row.
>>
>> Good luck!
>>
>> Ken
>>
>> Karam Singh Badesha wrote:
>>> Hi,
>>> Can someone please show some example handler code with only 2rows
>>> and 2cols without any input? I just want to see how to fill in the
>>> data for table. Your help is greatly appreciated. I looked at some
>>> admingui example code but I still can't get the basics about how to
>>> fill the table.
>>>
>>> thanks
>>> Karam


<sun:page>
    <sun:html>
<!beforeCreate

    ######################
    ## CREATE DATA ##
    ######################

    // Row 1
    createMap(result=>$attribute{row1});
    mapPut(map="$attribute{row1}" key="a" value="Row1 Col A");
    mapPut(map="$attribute{row1}" key="b" value="Row1 Col B");
    mapPut(map="$attribute{row1}" key="c" value="Row1 Col C");
    // Row 2
    createMap(result=>$attribute{row2});
    mapPut(map="$attribute{row2}" key="a" value="Row2 Col A");
    mapPut(map="$attribute{row2}" key="b" value="Row2 Col B");
    mapPut(map="$attribute{row2}" key="c" value="Row2 Col C");
    // Row 3
    createMap(result=>$attribute{row3});
    mapPut(map="$attribute{row3}" key="a" value="Row3 Col A");
    mapPut(map="$attribute{row3}" key="b" value="Row3 Col B");
    mapPut(map="$attribute{row3}" key="c" value="Row3 Col C");
    // Row 4
    createMap(result=>$attribute{row4});
    mapPut(map="$attribute{row4}" key="a" value="Row4 Col A");
    mapPut(map="$attribute{row4}" key="b" value="Row4 Col B");
    mapPut(map="$attribute{row4}" key="c" value="Row4 Col C");
    // Row 5
    createMap(result=>$attribute{row5});
    mapPut(map="$attribute{row5}" key="a" value="Row5 Col A");
    mapPut(map="$attribute{row5}" key="b" value="Row5 Col B");
    mapPut(map="$attribute{row5}" key="c" value="Row5 Col C");

    // Create List of Map (List of the rows)
    setPageSessionAttribute(key='listOfRows' value={"$attribute{row1}" "${row2}" "${row3}" "${row4}" "${row5}"} );

    // Row 1 (again, different obj.)
    createMap(result=>$attribute{rowA});
    mapPut(map="$attribute{rowA}" key="selected" value="$boolean{false}");
    mapPut(map="$attribute{rowA}" key="foo" value="Other Obj: A - foo");
    mapPut(map="$attribute{rowA}" key="bar" value="Other Obj: A - bar");
    // Row 2 (again, different obj.)
    createMap(result=>$attribute{rowB});
    mapPut(map="$attribute{rowB}" key="selected" value="$boolean{false}");
    mapPut(map="$attribute{rowB}" key="foo" value="Other Obj: B - foo");
    mapPut(map="$attribute{rowB}" key="bar" value="Other Obj: B - bar");
    // Row 3 (again, different obj.)
    createMap(result=>$attribute{rowC});
    mapPut(map="$attribute{rowC}" key="selected" value="$boolean{false}");
    mapPut(map="$attribute{rowC}" key="foo" value="Other Obj: C - foo");
    mapPut(map="$attribute{rowC}" key="bar" value="Other Obj: C - bar");
    // Row 4 (again, different obj.)
    createMap(result=>$attribute{rowD});
    mapPut(map="$attribute{rowD}" key="selected" value="$boolean{false}");
    mapPut(map="$attribute{rowD}" key="foo" value="Other Obj: D - foo");
    mapPut(map="$attribute{rowD}" key="bar" value="Other Obj: D - bar");
    // Row 5 (again, different obj.)
    createMap(result=>$attribute{rowE});
    mapPut(map="$attribute{rowE}" key="selected" value="$boolean{false}");
    mapPut(map="$attribute{rowE}" key="foo" value="Other Obj: E - foo");
    mapPut(map="$attribute{rowE}" key="bar" value="Other Obj: E - bar");

    // Create List of Map (List of more rows)
    setPageSessionAttribute(key='moreRows' value={"$attribute{rowA}" "${rowB}" "${rowC}", "${rowD}", "${rowE}"});
/>

        <sun:head id="head" />
        <sun:body>
            <sun:form id="form">
                <sun:alert id="alert1" summary="" details="" />
                "<style type="text/css">\
                    .wideTable table {width: 100%}\
                </style>

                <sun:markup tag="div" styleClass="wideTable">

                <sun:propertySheet id="ps1">
                    <sun:propertySheetSection id="pss1">
                        <sun:property id="prop1" overlapLabel="#{true}">

                <sun:table style="width:100%" id="basicTable" title="Test Table" deselectMultipleButton="#{true}" selectMultipleButton="#{true}" paginateButton="#{true}" paginationControls="#{true}">
                    <!facet actionsTop>
                        <sun:button text="Delete">
                            <!command
                                getUIComponent(clientId="form:ps1:pss1:prop1:basicTable:rowGroup1", component=>$attribute{trg});
                                getSelectedTableRowKeys(tableRowGroup="${trg}" rowKeys=>$attribute{rowKeys});
                                deleteTableRows(tableRowGroup="${trg}" rowKeys="${rowKeys}");
                                commitTableRowGroup(tableRowGroup="${trg}");
                            />
                        </sun:button>
                    </facet>

                    // NOTE: The {} on the outside of the ""'s create a List of the List(s) of rows
                    <sun:tableRowGroup id="rowGroup1" data={"$pageSession{listOfRows}", "$pageSession{moreRows}"} sourceVar="td" selected="#{td.value.selected}">
                        <sun:tableColumn headerText="Selected" selectId="selCb" id="selcol" sort="#{td.value.selected}">
                            <sun:checkbox id="selCb" value="#{td.value.selected}" />
                        </sun:tableColumn>
                        <sun:tableColumn headerText="Col 1" id="col1">
                            <staticText id="col1St" value="Val: #{td.value.a}" />
                            <event>
                                <!beforeEncode
                                    setAttribute(key="more" value="$attribute{more}A");
                                    setAttribute(key="coolList" value={"$attribute{more}", "b", "c"});
                                />
                            </event>
                            <foreach key="cool" list="#{coolList}">
                                "<br />
                                <sun:hyperlink url="http://www.google.com/search?q=#{cool}" text="Search google for '#{cool}'" />
                            </foreach>
                        </sun:tableColumn>
                        <sun:tableColumn headerText="Col 2" id="col2">
                            <staticText id="col2St" value="#{td.value.foo}" />
                        </sun:tableColumn>
                    </sun:tableRowGroup>
                </sun:table>
                        </sun:property>
                    </sun:propertySheetSection>
                </sun:propertySheet>
                </sun:markup>
            </sun:form>
        </sun:body>
    </sun:html>
</sun:page>