Submit datatable values with JSF and access it thr

2019-08-29 10:52发布

Is is possible to submit the JSF/PrimeFaces values of a datatable? Normally the datatable would be bind to a managed bean property and access it that way.

I need to have each entry of the datatable accesible through javax.servlet.http.HttpServletRequest object when the submit is made.

1条回答
叼着烟拽天下
2楼-- · 2019-08-29 11:24

Bind the value attribute of datatable to a list of POJOs. The table column corresponds to the POJO member.

public class MyPOJO{
   String column1;
   String column2;
   String column3;
   String column4;
    //setters and getters here ....
}

@ManagedBean(name="beanDetails")
@ViewScoped
public class MyBean {
public List<MyPOJO> list_POJO;
    //setters and getters here ....
}

<p:dataTable id="myTable" value="#{beanDetails.list_POJO}" var="dataItem"> 
<p:column>
    <f:facet name="header">
       <h:outputLabel value="Column 1" />
    </f:facet>

   <p:cellEditor>
        <f:facet name="output">
            <h:outputLabel value="#{dataItem.column1}" />
        </f:facet>
        ...
        ...
   </p:cellEditor>
</p:column>
   .... 
   ....
</p:dataTable>  

<p:commandButton value="Submit" actionListener="#{beanDetails.submitDetails}"/>

And in submitDetails, you can traverse through the datatable records using list_POJO.

查看更多
登录 后发表回答