[jsr-314-open] <h:dataTable> binding vs. ui:repeat

Dan Allen dan.j.allen at gmail.com
Tue Aug 4 14:38:16 EDT 2009


Lincoln,

There is an approach which will work in this case, but it doesn't rule out
the possibility that refinement is needed. Let me open with the example.

On the home page, there is a link that will load a feature list and navigate
to the list page.

/home.xhtml

<h:form>
    <h:commandButton action="#{featureList.load}" value="View feature
list"/>
</h:form>

/list.xhtml

<h:form>
    <ul>
        <ui:repeat var="f" value="#{featureList.features}">
            <h:inputText value="#{f.name}"/> <h:commandButton
action="#{featureList.action}" value="Action"/>
        </ui:repeat>
    </ul>
</h:form>

And finally, the controller:

@ManagedBean
@SessionScoped // chosen for convenience, really it should be view-scoped or
conversation-scoped (299)
public class FeatureList
{
    private DataModel features;

    public DataModel getFeatures() { return features; }

    public String load() {
        List<Feature> l = new ArrayList<Feature>();
        l.add(new Feature("One"));
        l.add(new Feature("Two"));
        features = new ListDataModel(l);
    }

    public void action()
    {
        System.out.println("You clicked on the button in the row with
feature " + ((Feature) features.getRowData()).getName());
    }
}

Note that the getRowData() method is positioned at the row which received
the action during the invocation of any listener. Be careful, though,
because it points to the first row if no row is selected. First check if
getRowIndex() >= 0 to see if a row received an action.

Regardless, this is still a horrible way (IMO) of having to select the row.
It is very opaque. This is one area where you really take Seam for granted
because you would instead use injection of the selected row:

@DataModelSelection Feature selectedFeature;

There may be some edge cases where this doesn't work. Please apply to your
use case and report back any gaps.

-Dan

-- 
Dan Allen
Senior Software Engineer, Red Hat | Author of Seam in Action
Registered Linux User #231597

http://mojavelinux.com
http://mojavelinux.com/seaminaction
http://in.relation.to/Bloggers/Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jsr-314-open-mirror/attachments/20090804/9fafd25f/attachment.html 


More information about the jsr-314-open-mirror mailing list