jsf 2 - update entity attribute through primefaces modal -


try load , update attributes datatable form embedded in primefaces modal box:

1) datatable command send user's data modal

<p:commandbutton value="alterar"                         action="#{usuariomb.carregaralteracao(u)}" update=":usuariodesc"                         process="@this" onclick="dlg.show();" /> 

2) loads user's attributes in modal box

<p:dialog id="modaldialog" header="alterar usuário" widgetvar="dlg"             modal="true" height="260" appendtobody="true" dynamic="true" >             <h:form id="usuariodesc" styleclass="formtamanho">                 <h:panelgrid id="#{msg.pnlidprofile}" columns="2"                     columnclasses="labelpanelgrid, contentpanelgrid">                     <p:outputlabel value="perfil:" />                     <p:outputlabel value="#{usuariomb.usuario.perfil.nome}" />                 </h:panelgrid>                  <h:panelgrid id="#{msg.pnlidlogin}" columns="2"                     columnclasses="labelpanelgrid, contentpanelgrid">                     <p:outputlabel value="#{msg.lbllogin}" for="usuario_login" />                     <p:inputtext value="#{usuariomb.usuario.login}" id="usuario_login"                         required="true" requiredmessage="#{msg.msgreqlogin}" />                 </h:panelgrid>                  <h:panelgrid id="nomeusuario" columns="2"                     columnclasses="labelpanelgrid, contentpanelgrid">                     <p:outputlabel value="nome:" for="usuario_nome" />                     <p:inputtext value="#{usuariomb.usuario.nome}" id="usuario_nome"                         required="true" />                 </h:panelgrid>                  <h:panelgrid id="emailusuario" columns="2"                     columnclasses="labelpanelgrid, contentpanelgrid">                     <p:outputlabel value="email:" for="usuario_email" />                     <p:inputtext value="#{usuariomb.usuario.email}" id="usuario_email"                         required="false" />                 </h:panelgrid>                   <h:panelgrid id="#{msg.pnlidcal}" columns="3"                     columnclasses="labelpanelgrid, contentpanelgrid">                     <p:outputlabel value="#{msg.lblbirth}" for="#{msg.calid}" />                     <p:calendar value="#{usuariomb.usuario.nascimento}"                         id="#{msg.calid}" locale="#{msg.callocale}" showbuttonpanel="true"                         navigator="true" />                     <p:outputlabel value="(ex: 16-04-1980)" />                 </h:panelgrid>                 <br />                 <div id="btnforms" style="margin-left: 120px;">                     <p:commandbutton value="alterar usuário" id="alt_usuario"                         action="#{usuariomb.alterar()}" update=":usuariodatatable:tableusuarios"                         process="@this" style="margin-left:5px;" oncomplete="dlg.hide();"/>                      <p:commandbutton value="criar nova senha e mandar por email"                         id="alt_senha"                         action="#{usuariomb.sendemail(usuario.email)}"                         process="@this"                         style="margin-left:5px;" />                     <p:commandbutton value="cancelar" onclick="dlg.hide();"                         style="margin-left:5px;" />                 </div>             </h:form>         </p:dialog> 

3) when modify attribute through fields in modal, use command action "alterar" , managed bean still keeps reference user's original datas, , no update happens.

public string alterar() {          try {             gerenciarusuariobean.alterar(usuario);             jsfmessageutil.sendinfomessagetouser("usuário salvado com sucesso!");          } catch (daoexcecao e) {             log.error(e);             jsfmessageutil.senderrormessagetouser("erro cadastrando usuário !");         }         usuario = new usuario();         return "/views/gerencia/gerenciarusuarios.xhtml";     } 

in nutshell, user's attributes auto merged in database. welcome..

ok, there bit of confusion in command buttons (process / update)

1) datatable cmd:

<p:commandbutton value="alterar"                             action="#{usuariomb.carregaralteracao(u)}" update=":usuariodesc:usr"                             process="@this" onclick="dlg.show();" /> 

2) update button

<p:commandbutton value="alterar usuário" id="alt_usuario"                             action="#{usuariomb.alterar()}"                             update=":usuariodatatable:tableusuarios" process="@form"                             style="margin-left:5px;" oncomplete="dlg.hide();" /> 

hope helps someone.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -