jsf - Editable dataTable with inputText -
i want add inputtext datatable. inputtext used add new user (name, role, age) , save database. can olso update existing values in datatable. example let's have datatable.
what dynamically add inputtext fields first row of table on button click. fill in values insert , click on save button.
the idea come add editable="true"
datatable , use <p:celleditor>
, <p:roweditor/>
this:
<p:datatable var="item" value="#{usercontroler.users}" editable="true"> <p:column> <p:celleditor> <f:facet name="output"> <h:outputtext value="#{item.name}"/> </f:facet> <f:facet name="input"> <p:inputtext value="#{item.name}" style="width:100%"/> </f:facet> </p:celleditor> </p:column> <p:column> <p:roweditor /> </p:column> </p:datatable>
and add new epmty user list, refresh datatable, edit new user , save on event rowedit
. there way this?
because problem face due composite-id. when enter new value can't know if i'm going update or save given value. (suppose composite-id name , role. if want insert new value , make mistake , insert existing value i'm going have update instead of error message).
hope i'm clear enough. if not can provide more information.thank you.
i did balusc suggested.
<p:datatable var="item" value="#{usercontroler.users}" editable="true"> <p:column> <p:celleditor> <f:facet name="output"> <h:outputtext value="#{item.name}"/> </f:facet> <f:facet name="input"> <p:inputtext value="#{item.name}" style="width:100%"/> </f:facet> </p:celleditor> <f:facet name="footer"> <p:inputtext value="#{usercontroler.newuser.name}" /> </f:facet> </p:column> <p:column> <p:roweditor /> <f:facet name="footer"><p:commandbutton action="#{usercontroler.add}"/></f:facet> </p:column> </p:datatable>
works fine.
Comments
Post a Comment