8 Replies Latest reply on Apr 16, 2010 10:45 PM by Daniel Kim

    Problem with EntityHome's update

    Max Meyers Newbie

      Hello!


      I have a problem with update and persist method of EntityHome object. I have a class, which is called Tuser. Now I want, that the user is able to change his data in a form. But if the user is going to save data, nothing happens and the old values are still displayed. I have no error messages in my log file and only select statements and no DML functions.


      Here is my code:


      <s:div id="editPersonal" rendered="#{edit.equals('personal')}"> 
                                    <div style="text-align:right">
                                         <s:link action="#{tuserHome.persist}" value="speichern" >
                                              <f:param name="edit" value="none"/>
                                         </s:link>
                                    </div>
                                    <s:decorate template="layout/edit.xhtml">
                                         <ui:define name="label"> Vorname </ui:define>
                                         <h:inputText id="tfirstname" value="#{tuserHome.instance.tfirstname}" >
                                              <a:support event="onblur" reRender="tskilllevelField"     bypassUpdates="true" ajaxSingle="true" />
                                         </h:inputText>
                                    </s:decorate>               
                                    <s:decorate template="layout/edit.xhtml">
                                         <ui:define name="label"> Nachname </ui:define>
                                         <h:inputText id="tlastname" value="#{tuserHome.instance.tlastname}" >
                                              <a:support event="onblur" reRender="tskilllevelField"     bypassUpdates="true" ajaxSingle="true" />
                                         </h:inputText>
                                    </s:decorate>
                                    <s:decorate template="layout/edit.xhtml">
                                         <ui:define name="label"> Geschlecht </ui:define>
                                         <rich:inplaceSelect id="tgender" defaultLabel="#{tuserHome.instance.tgender=='m' ? 'm&#228;nnlich' : 'weiblich'}" value="#{tuserHome.instance.tgender}">
                                              <f:selectItem itemValue="m" itemLabel="m&#228;nnlich"/>
                                              <f:selectItem itemValue="w" itemLabel="weiblich"/>
                                         </rich:inplaceSelect>
                                    </s:decorate>
                                    <s:decorate template="layout/edit.xhtml">
                                         <ui:define name="label"> Verein </ui:define>
                                         <h:inputText id="tclub"  value="#{tuserHome.instance.tclub.tname}" >
                                              <a:support event="onblur" reRender="tskilllevelField"     bypassUpdates="true" ajaxSingle="true" />
                                         </h:inputText>
                                    </s:decorate>
                                    <div style="clear:both">
                                    </div>
                               </s:div>
                     </rich:panel>



      This is the part of the richpanel where I want to make the update. I write the data in the tuserHome object and if somebody clicks on the link called speichern I want to update the data. But if I return to my page, the old data is still shown. I don't know what the problem is and why the update method of EntityHome object is not called or does nothing.


      What do you think?


      Thanks!


      regards,
      max.

        • 1. Re: Problem with EntityHome's update
          Max Meyers Newbie

          Now I found out, that the update method of EntityHome object is called. But in my TuserHome class I found out, that the values of my fields does not change, even if I change them in my form. I don't know why. Is this because a submit button is missing? The values in TuserHome class are still the same as before the change in the form. I don't know why.


          Would be nice if someone knows the answer!


          Thanks!


          regards,
          max.

          • 2. Re: Problem with EntityHome's update
            Val Sw Expert
            How you are calling update in tuserHome ? don't see any action ="#{tuserHome.update} ??
            • 3. Re: Problem with EntityHome's update
              Max Meyers Newbie

              Thank you for your reply! I am trying to achieve the update working several hours, but I had no success :(


              I tried many variants like to call persist too. You find this in line 3 of my code in post 1. There I am calling persist (but what I read in the ref doc is, that callinng persist on a managed object is the same like updating).


              Here is the code which I have written at the moment and still doesn't work (code replaces line 3-5, the rest is the same):



              <s:link type="submit" action="#{tuserHome.update}" value="speichern" >
                                                                <f:param name="edit" value="none"/>
                                                           </s:link> 



              You can see that I set the type to submit, which doesn't work too.


              Now I know what's my problem: When I log the data of my TuserHome object I get the same values in my update function as they were before calling update. I am editing these values, but they are not set. Does anybody know why? I have a register-function where it works, but there I have a button to submit. Doesn't a link set the attributes of TuserHome?


              I hope that somebody knows a solution. I don't know what I could try next.


              Thanks!


              regards,
              max.

              • 4. Re: Problem with EntityHome's update
                Val Sw Expert
                Can you try this... you should see the button if your tuserHome is managed

                <h:commandButton id="update"
                       value="Update"
                      action="#{tuserHome.update}"
                   rendered="#{tusrHome.managed}"/>
                • 5. Re: Problem with EntityHome's update
                  Max Meyers Newbie

                  Thank you so much for this tip. This is working:



                  <h:commandLink  id="update"
                     value="Update"
                    action="#{tuserHome.update}"
                     rendered="#{tuserHome.managed}" />



                  I use it conjunction with this:



                  <navigation from-action="#{tuserHome.update}">
                            <redirect view-id="/profile_own.xhtml">
                                 <param name="edit" value="none"/>
                            </redirect>
                       </navigation>



                  If I write my parameters directly to my xhtml file it doesn't work. There are still the old values in my TuserHome object. I don't know the difference between the two and why the last one ist working and the first one not. If someone can explain me this it would be great because I don't understand. But for this time I am very happy that it works!


                  Thanks!!!!!


                  regards,
                  Christian.


                  • 6. Re: Problem with EntityHome's update
                    Val Sw Expert
                    Ideally if you pass the paramer from link that should also work...

                    Here is the sample which works fine for me...

                    XHTML
                    -----
                    <h:commandLink action="#{projectHome.addTreatmentLink}" 
                         value="Add treatments"  >
                         <f:param name="re_hashcode" value="#{info.hashCode()}"/> 
                         <f:param name="re_pname" value="#{info.pname}"/>
                    </h:commandLink>

                    Corresponding Home function, which reads the param passed from UI
                    public String addTreatmentLink(){
                    javax.faces.context.FacesContext facesContext = (new org.jboss.seam.faces.FacesContext
                    ()).getContext();
                    javax.servlet.http.HttpServletRequest hsr=(javax.servlet.http.HttpServletRequest) 
                    facesContext.getCurrentInstance().getExternalContext().getRequest();
                    String reagentHashcode=hsr.getParameter("re_hashcode");          
                    String reagentPname=hsr.getParameter("re_pname");
                    return "added";
                    }
                    • 7. Re: Problem with EntityHome's update
                      Val Sw Expert

                      And of course s:link will also work fine on the same context as above.

                      • 8. Re: Problem with EntityHome's update
                        Daniel Kim Newbie

                        Hi,


                        I think I am having same problem, but adding h:commandLink didn't work at all for my case.
                        What version of jboss server and jboss seam did you use?


                        thx,
                        Daniel