users@woodstock.java.net

Re: weird refresh() behaviour in table

From: Dan Labrecque <Dan.Labrecque_at_Sun.COM>
Date: Fri, 08 Feb 2008 15:50:25 -0500

I modified the Woodtsock dynamic table example to include buttons
(created using Java). I used a value expression to set each button label
using a date. Then, I wrote some JavaScript to refresh a particular
button in the table. Unlike you, I only saw one button being refreshed
with a new date value. Below are a couple snippets of code used in my test.

In the example's Dynamic.java class, I added the following code.
Basically, all this does is add a button child to the TableColumn object
(i.e., col2).

| public Button getButton(String id, String text) {
        // Get checkbox.
        Button btn = new Button();
        btn.setId(id);
        JSFUtilities.setValueExpression(btn, "text", text); // Set text
using value expression.
        return btn;
    }

    public void setTableRowGroupChildren(TableRowGroup rowGroup, String
cbSort,...
        ...
        Button btn = getButton("_button", "#{DynamicTableBean.time}");
        col2.getChildren().add(btn);|

Then, in my DynamicTableBean.java class, I added the following function
to retrieve a date for the button label.

| public String getTime() {
        Calendar calendar = Calendar.getInstance();
        return calendar.getTime().toString();
    }|

Finally, I included a simple control used to refresh a button of a
particular table row. If all buttons were being refreshed, as you
suggest, I should see all button labels updated with a new date.
However, I only saw one button label updated as expected.

    |<input type="button" onClick="refreshButton();" value="Test Refresh"/>
    <script>
        function refreshButton() {
            var domNode =
    document.getElementById("form1:table1:rowGroup1:3:col1:_button");
            domNode.refresh();
        }
    </script>
    |

If you're still seeing all buttons being refreshed, take a look at the
Ajax response in Firebug. You should see text containing button
properties and not raw HTML. If you see HTML, JSF may have re-rendered
the entire page. There could be many reasons for this, but JSF most
likely could not locate the button in the JSF component tree. For
example, the wrong button id was used. Or, the same DataProvider was not
available to JSF during the decode phase. You can test that by setting
the backing bean to be session scoped.

Sorry, I cannot be more helpful.

Dan

autozoom wrote:
> I am again trying to make Woodstock 4.2 M1 components work with Ajax.
> I drop a table on an empty page, then delete 2 columns so that only 1
> remains, then edit the table layout so that the column only contains a
> button.
> I bind the button text to a page's property, here's the resulting JSP:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!--
> Document : Page1
> Created on : 5-feb-2008, 15.54.33
> Author : mauro
> -->
> <jsp:root version="2.1" xmlns:f="http://java.sun.com/jsf/core"
> xmlns:h="http://java.sun.com/jsf/html"
> xmlns:jsp="http://java.sun.com/JSP/Page"
> xmlns:webuijsf="http://www.sun.com/webui/webuijsf">
> <jsp:directive.page contentType="text/html;charset=UTF-8"
> pageEncoding="UTF-8"/>
> <f:view>
> <webuijsf:page binding="#{Page1.page1}" id="page1">
> <webuijsf:html binding="#{Page1.html1}" id="html1">
> <webuijsf:head binding="#{Page1.head1}" id="head1">
> <webuijsf:link binding="#{Page1.link1}" id="link1"
> url="/resources/stylesheet.css"/>
> </webuijsf:head>
> <webuijsf:body binding="#{Page1.body1}" id="body1"
> style="-rave-layout: grid">
> <webuijsf:form binding="#{Page1.form1}" id="form1">
> <webuijsf:table augmentTitle="false"
> binding="#{Page1.myTable}" id="myTable" style="position: absolute; left:
> 120px; top: 192px"
> title="Table" width="0">
> <webuijsf:tableRowGroup
> binding="#{Page1.tableRowGroup1}" id="tableRowGroup1" rows="10"
>
> sourceData="#{Page1.defaultTableDataProvider}" sourceVar="currentRow">
> <webuijsf:tableColumn
> binding="#{Page1.tableColumn2}" headerText="tableColumn1" id="tableColumn2">
> <webuijsf:button
> binding="#{Page1.button1}" id="button1" text="#{Page1.txt}"/>
> </webuijsf:tableColumn>
> </webuijsf:tableRowGroup>
> </webuijsf:table>
> </webuijsf:form>
> </webuijsf:body>
> </webuijsf:html>
> </webuijsf:page>
> </f:view>
> </jsp:root>
>
> Rendering is ok and I see a table with 5 rows, each of which contains a
> button.
>
> But when I call a javascript refresh() on the first button
>
> $("form1:myTable:tableRowGroup1:0:tableColumn2:button1").refresh()
> 4 out of 5 buttons are refreshed at the same time!
>
> No errors, neither javascript nor on the server, but many buttons are
> refreshed and not only 1
>
> any hints?
>