0

I created a generic xhtml page in my java web app that gets all the users from a database table and shows them in a datatable, but I want to add buttons next to every row (view, edit, delete) that have unique ids and which invoke methods in the java bean passing their ids as arguments.

I'm new at this it seems incredibly simple, but nothing I tried works.

<h:form>
        <h:dataTable value="#{functions.employees}" var="employee"
                        rowClasses="oddTableRow, evenTableRow"
                        headerClass="tableHeader"
                        styleClass="table">
            <h:column>
                <f:facet name="header">id</f:facet>
                #{employee.id}
            </h:column>

            <h:column>
                <f:facet name="header">First Name</f:facet>
                #{employee.firstName}
            </h:column>

            <h:column>
                <f:facet name="header">Last Name</f:facet>
                #{employee.lastName}
            </h:column>

            <h:column>
                <f:facet name="header">Adress</f:facet>
                #{employee.adress}
            </h:column>

            <h:column>
                <f:facet name="header">Phone</f:facet>
                #{employee.phone}
            </h:column>

            <h:column>
                <f:facet name="header">Email</f:facet>
                #{employee.email}
            </h:column>

            <h:column>
                <h:commandButton value="View" action="viewPage.xhtml">
                    <f: actionListener binding ="#{Functions.setId(id)}"
                </h:commandButton>
            </h:column>

            <h:column>
                      <h:button value="Edit" outcome = "editPage.xhtml"/>
            </h:column>

            <h:column>
                      <h:button value="Delete" outcome = "#{Functions.delete(id)}"/>
            </h:column>

        </h:dataTable>
    </h:form>

1 Answers1

0

How about you use PrimeFaces ? its components make a lot of work easier, for example in your case you can use the <p:dataTable> refer to their showcase for a concrete example.
If you want to do it with just JSF then refer to this, that question and its answer should solve your problem.

Community
  • 1
  • 1
RedaN
  • 93
  • 1
  • 10
  • Thanks, I already solved that question by passing the row or it's elements as arguments. Though I didn't consider alternatives or efficiency. I'll probably get to your answer one day to consider how to best work with the data. – John Smith Apr 21 '17 at 09:39
  • @JohnSmith Ah ok then, how about you write your solution as an answer so you can mark this question as solved – RedaN Apr 21 '17 at 10:11