JSF - Selecting Item from a Set

Asked

Viewed 303 times

1

I want to make a xhtml that returns a list of users and next appears a button to select a particular user. Something like this:

+----------------------------+
| ID | User | (Button) |
+----------------------------+

My question is: How do I do a repeat loop in xhtml to build the page with all the objs q are within the set and what is the best way to make the button reference the respective object of your line.

If anyone can help me. I thank you in advance.

3 answers

1

1

Try

<p:panelGrid columns="3"> .... </p:panelGrid>

p: is from the first faces but also works with pure JFS.

  • Activate the drawing. Rereading the question I believe the most appropriate need to be even a datatable as mentioned by other colleagues.

1


Jhow,

As Tiago said above, you can use the Primefaces datatable or you can also use the JSF datatable. Follow an example below.

We will have in your class "@Managedbean("user")" a list of the object you want to insert in the table.

    private List<Usuario> usuario = new ArrayList<Usuario>();

   <h:dataTable value="#{usuario.usuario}" var="u">

                <h:column>
                    <f:facet name="header">Order No</f:facet>
                    #{u.id}
                </h:column>

                <h:column>
                    <f:facet name="header">Product Name</f:facet>
                    #{u.nome}
                </h:column>

                <h:column>
                    <f:facet name="header">Price</f:facet>
                    #{u.sexo}
                </h:column>

                <h:column>
                    <f:facet name="header">Quantity</f:facet>
                    <h:commandButton value="submit" type="submit" action="#{usuario.fazAlgumaCoisa(u)}" />
                </h:column>

    </h:dataTable>

Follow a reference link. http://www.mkyong.com/jsf2/jsf-2-datatable-example/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.