dev@jsftemplating.java.net

Re: JSFTemplating: Table data not showing up

From: Ken Paulsen <Ken.Paulsen_at_Sun.COM>
Date: Sun, 28 Jan 2007 16:24:44 -0800

Karam Singh Badesha wrote:
> Ken,
> I am not sure from your email about which code goes where. Can you
> please break it down in steps (mainly which code in which file and if
> I need to change the input/ouput of the handler)?
>
> - I will still call the handler from the "command" event of the button?
Yes.
>
> - Do I need to change the handler call (inputs/ouputs), except change
> the output type to an attribute? Or it still is same as before?
> getTable1Data(lavaVersion="#{pageSession.lava}"
> buildVersion="#{pageSession.build}"
> lavaProject="#{pageSession.project}"
> table1Data=>$attribute{table1DataList});
Your old handler can remain unchanged. In your .jsf file you can change
it to use pageSession. You can do this after you get things working if
you'd like since leaving it as pageSession won't hurt anything.
> - I need to add your java code in my handler?
Or a different handler. You may want to break it up into a handler
called "updateTableData" or something like that. The new handler will
take the List<List<Object>> as an input.
> What is the import statement for tableRowGroup?
You can check the Woodstock documentation, but I think it's:

    com.sun.webui.jsf.component.TableRowGroup;

You will need to pass this in an input also. You can use the
"getUIComponent" handler to find the UIComponent if you don't have
another way to get it. See the JavaDoc for JSFTemplating for details
(or look at the "info.jsf" page for details). This handler is defined
in the ComponentHandlers class.
> Eventhough I have the MultipleListDataProvider in my WEB-INF/lib, it
> keeps saying it cannot detect package
> com.sun.enterprise.tools.admingui.dataprovider.
Did you rename the package to something else? The factory references
that package (the exception should also say that).
>
> - MultipleListDataProvider dp = (MultipleListDataProvider)
> tableRowGroup.getAttributes().get("sourceData");
> I don't have to change anything in the above line, correct?
Correct, but you have to have a reference to your "tableRowGroup" object.
>
> - dp.setLists(newData);
> At the end of my handler I just pass on my list of list of objects to
> dp.setLists, in my case, I just pass in "t1Data" (dp.setLists(t1Data))?
Yes, although I recommend you break up this functionality into 2
handlers so you can reuse the table update handler with other handlers
that retrieve table data. Your application is likely to have many
different handlers that get table data.

I hope this helps!

Ken
>
> List t1Data = new ArrayList();
> try {
> System.out.println("In fetchTable1Data try block...");
> DataAccessLayer dal = new DataAccessLayer();
> CachedRowSetImpl crs = dal.getFirstLevelUsageStats(lava,
> build, project);
> RowSetMetaDataImpl rsmd = (RowSetMetaDataImpl)
> crs.getMetaData();
> int count = rsmd.getColumnCount();
> //System.out.println("Column count is: " +
> rsmd.getColumnCount());
> int rows = 0;
> while(crs.next()) {
> System.out.println("In while loop: " + rows);
> Map rEntries = new Hashtable();
> for(int i=1;i<=count;i++)
> {
> //System.out.println(rsmd.getColumnName(i));
> System.out.println(crs.getObject(i));
> rEntries.put("col" +i, crs.getObject(i));
> }
> System.out.println(rEntries.get("col1").toString() + "
> : " +rEntries.get("col2").toString() + " : "
> +rEntries.get("col3").toString());
> t1Data.add(rows,rEntries);
> rows++;
> }
> System.out.println("Table rows: " + rows);
> } catch(SQLException e) {
> e.printStackTrace();
> }
> // Set the output.
> System.out.println("t1Data rows: " + t1Data.size());
> context.setOutputValue("table1Data", t1Data);
>
> - The code in the jsf file remains same:
> <sun:tableRowGroup
> id="rowGroup1"
> data={"#{requestScope.table1DataList}"}
> sourceVar="tRow"
>
> thanks,
> -Karam
>
> Ken Paulsen wrote:
>>
>> Hi Karam,
>>
>> The problem is the same issue that you had with the sun:dropDown
>> component. The factory is converting the data, and not holding on to
>> the original EL bindings. You can get your MultipleListDataProvider,
>> and set new data in it:
>>
>> MultipleListDataProvider dp = (MultipleListDataProvider)
>> tableRowGroup.getAttributes().get("sourceData");
>> dp.setLists(newData);
>>
>> "newData" should be a List of List of Object. This data can be
>> stored in request scope because this implementation of data provider
>> stores a reference to the data. DataProviders are stored on the
>> UIComponent (equivalent to pageSession). "newData" can be generated
>> from your handler below (getTable1Data), however, I think this is
>> only a List of Object. So when you pass it in to the handler in
>> which you place the above Java code, make sure you do something like
>> data={"#{requestScope.newData}"} (note the {}'s outside the quotes...
>> this wraps your parameter value in a List to provide you with a List
>> of List of Object.
>>
>> Ken
>>
>> Karam Singh Badesha wrote:
>>> Ken,
>>> This is not going to work for me as this handler takes input some
>>> pageSession variables which gets created in beforeCreate event which
>>> also gets updated with the ajax requests. I currently have couple of
>>> drop downs which use ajax to update each other and then there is a
>>> button. When a user presses that button, I need to recreate the
>>> table (after page refresh). So I am using "command" event to call
>>> the handler in the button and I expect it to refresh the table after
>>> the reload, but it doesn't work. Here is my button:
>>>
>>> <sun:button
>>> id="generateButton"
>>> text="#{msgs.button_generateText}"
>>> toolTip="#{msgs.button_generateText}"
>>> > <!command
>>> getTable1Data(lavaVersion="#{pageSession.lava}",
>>> buildVersion="#{pageSession.build}",
>>> lavaProject="#{pageSession.project}"
>>> table1Data=>$pageSession{table1DataList});
>>> />
>>> </sun:button>
>>>
>>> So how can I make this work.
>>>
>>> thanks
>>> Karam
>>>
>>> Ken Paulsen wrote:
>>>>
>>>> I assume you are calling your handler this in a "beforeCreate"
>>>> event? Try moving the handler to an <!initPage /> event at the top
>>>> of the page:
>>>>
>>>> <!initPage
>>>> yourHandler(...);
>>>> />
>>>>
>>>> Unlike "beforeCreate", "initPage" gets invoked every time the page
>>>> is refreshed. You can probably move your List into a request
>>>> attribute when you take this approach b/c you will be regenerating
>>>> the data every request.
>>>>
>>>> I hope this helps!
>>>>
>>>> Ken
>>>>
>>>> Karam Singh Badesha wrote:
>>>>> Found out what is happening here. Basically on my initial page
>>>>> load, there was no data for the table. Now when I select some
>>>>> other entries and click on a button, it is refreshing the page,
>>>>> but the table still shows the old data (in this case, nothing). I
>>>>> tried the default so that some data shows up and after
>>>>> resubmitting with different data, it doesn't refresh. Can this
>>>>> problem be solved? I need the fix by Mon as I need to demo this to
>>>>> our team.
>>>>>
>>>>> thanks
>>>>> Karam
>>>>>
>>>>> Karam Singh Badesha wrote:
>>>>>> Hi,
>>>>>> Here is the what I had when the code was working fine:
>>>>>>
>>>>>> Table data was hardcoded in the handler was passing a list of
>>>>>> HashTable/Map entries. The values is passed back and set as a
>>>>>> pageSession variable. Here is corresponding jsf code:
>>>>>>
>>>>>> <sun:tableRowGroup
>>>>>> id="rowGroup1"
>>>>>> data={"$pageSession{table1DataList}"}
>>>>>> sourceVar="tRow"
>>>>>> >
>>>>>>
>>>>>> Now, I am getting the data from the database in the handler and
>>>>>> can print the data fine in the handler, so I am assuming the data
>>>>>> is getting fed into the same list of HashTable/Map entries fine.
>>>>>> But nothing is showing up on the Table. Any idea why this might
>>>>>> be happening?
>>>>>>
>>>>>> Here is the corresponding handler code:
>>>>>>
>>>>>> @Handler(id="getTable1Data",
>>>>>> input={
>>>>>> @HandlerInput(name="lavaVersion", type=String.class),
>>>>>> @HandlerInput(name="buildVersion", type=String.class),
>>>>>> @HandlerInput(name="lavaProject", type=String.class)},
>>>>>> output={
>>>>>> @HandlerOutput(name="table1Data", type=java.util.List.class)
>>>>>> })
>>>>>> public static void fetchTable1Data(HandlerContext context) {
>>>>>> System.out.println("In fetchTable1Data...");
>>>>>> String lava = (String) context.getInputValue("lavaVersion");
>>>>>> String build = (String)
>>>>>> context.getInputValue("buildVersion");
>>>>>> String project = (String)
>>>>>> context.getInputValue("lavaProject");
>>>>>> List t1Data = new ArrayList();
>>>>>> try {
>>>>>> System.out.println("In fetchTable1Data try block...");
>>>>>> DataAccessLayer dal = new DataAccessLayer();
>>>>>> CachedRowSetImpl crs =
>>>>>> dal.getFirstLevelUsageStats(lava, build, project);
>>>>>> RowSetMetaDataImpl rsmd = (RowSetMetaDataImpl)
>>>>>> crs.getMetaData();
>>>>>> int count = rsmd.getColumnCount();
>>>>>> System.out.println("Column count is: " +
>>>>>> rsmd.getColumnCount());
>>>>>> int rows = 0;
>>>>>> while(crs.next()) {
>>>>>> System.out.println("In while loop: " + rows);
>>>>>> Map rEntries = new Hashtable();
>>>>>> for(int i=1;i<=count;i++)
>>>>>> {
>>>>>> System.out.println(crs.getObject(i));
>>>>>> rEntries.put("col" +i,
>>>>>> crs.getObject(i).toString());
>>>>>> }
>>>>>> t1Data.add(rows,rEntries);
>>>>>> rows++;
>>>>>> }
>>>>>> System.out.println("Table rows: " + rows);
>>>>>> } catch(SQLException e) {
>>>>>> e.printStackTrace();
>>>>>> }
>>>>>> // Set the output.
>>>>>> context.setOutputValue("table1Data", t1Data);
>>>>>> }
>>>>>>
>>>>>> thanks
>>>>>> Karam