dev@jsftemplating.java.net

Re: JSFTemplating: Table Handler example

From: Ken Paulsen <Ken.Paulsen_at_Sun.COM>
Date: Fri, 19 Jan 2007 15:51:55 -0800

The sun:tableRowGroup factory has some special code to make using the
table easier (really! ;) ). This code hides the fact that you need to
create a DataProvider to reference your data. To use this, you must
pass in your List<List<Object>> via the "data" property. You are
passing it via the "sourceData" property. The sourceData property *is*
a valid property of this component, but if you choose to use this, you
must pass in a DataProvider object.

So... to follow my example, switch to use "data". To follow Woodstock
examples, switch to use a DataProvider object.

I hope this help!

Ken

Karam Singh Badesha wrote:
> Ken,
> I think I am getting closer to the working table. Now nothing shows up
> for the table on my page. Here is what I have at the top:
>
> <!beforeCreate
> getReleases(lavaReleases=>$attribute{lavaReleasesList});
> getBuilds(lavaBuilds=>$attribute{lavaBuildsList});
> getProjects(lavaProjects=>$attribute{lavaProjectsList});
> getTable1Data(table1Data=>$pageSession{table1DataList});
> />
>
> Here is what I have in the sun:table code:
>
> <sun:table id="table1"
> clearSortButton="#{true}"
> sortPanelToggleButton="#{true}"
> paginateButton="#{true}"
> title="#{msgs.table1_header}">
> <sun:tableRowGroup id="rowGroup1"
> sourceData={"$pageSession{table1DataList}"}
> sourceVar="tRow">
> <sun:tableColumn id="col1"
> alignKey="first"
> headerText="#{msgs.table1_col1_header}"
> rowHeader="#{true}"
> sort="first">
> <sun:staticText text="#{tRow.value.one}"/>
> </sun:tableColumn>
> <sun:tableColumn id="col2"
> alignKey="second"
> headerText="#{msgs.table1_col2_header}"
> rowHeader="#{true}"
> sort="">
> <sun:staticText text="#{tRow.value.two}"/>
> </sun:tableColumn>
> <sun:tableColumn id="col3"
> alignKey="last"
> headerText="#{msgs.table1_col3_header}"
> rowHeader="#{true}"
> sort="">
> <sun:staticText text="#{tRow.value.three}"/>
> </sun:tableColumn>
> </sun:tableRowGroup>
> </sun:table>
>
> And the handler code is already in the email. What am I missing here
> to make it work?
>
> thanks
> Karam
>
> Ken Paulsen wrote:
>>
>> Hi Karam,
>>
>> It needs to be a List<List<HashTable>>. What you have will probably
>> work, if you specify:
>>
>> <sun:tableRowGroup data={"$pageSession{listOfHashTable}"} ... >
>>
>> Where $pageSession{listOfHashTable} is the output of your handler.
>> The {} around the ""'s will cause JSFTemplating to create a List to
>> contain your List of HashTable... which is what the "data" property
>> requires.
>>
>> Ken
>>
>> Karam Singh Badesha wrote:
>>> So I could have a list of object Hashtable?
>>>
>>> I have the following:
>>>
>>> @Handler(id="getTable1Data",
>>> output={
>>> @HandlerOutput(name="table1Data", type=java.util.List.class)
>>> })
>>> public static void fetchTable1Data(HandlerContext context) {
>>> Hashtable numbers1 = new Hashtable();
>>> Hashtable numbers2 = new Hashtable();
>>> numbers1.put("one", new Integer(1));
>>> numbers1.put("two", new Integer(2));
>>> numbers1.put("three", new Integer(3));
>>> numbers2.put("one", new Integer(1));
>>> numbers2.put("two", new Integer(2));
>>> numbers2.put("three", new Integer(3));
>>> // Do business logic...
>>> List t1Data = new ArrayList();
>>> t1Data.add(0,numbers1);
>>> t1Data.add(1,numbers2);
>>> // Set the output.
>>> context.setOutputValue("table1Data", t1Data);
>>> }
>>>
>>> Is this wrong?
>>>
>>> thanks,
>>> Karam
>>>
>>> Ken Paulsen wrote:
>>>> 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>
>>>>