4 Replies Latest reply on Nov 29, 2008 9:21 PM by valatharv

    How to retain the values of text field on link click, tried using s:link ..

    valatharv
      I tried using s:link but it dosen't work... please help on how I can retain value in h:inputText pname1 on link click... I tried soem options but it dosen't work...

      Details :
      User fills h:inputText pname1 and on clicking h:commandLink (Add treatments), h:inputText pname1 becomes null.


      <rich:panel id="reagentPanel">
      <table border="1" class="dr-table rich-table" id="color">
      <ui:repeat value="#{projectHome.reagent}" var="info" >
           <tr class="dr-table-header rich-table-header">
                <td class="dr-subtable-cell rich-subtable-cell" style="width:80px">
                <s:decorate template="layout/edit.xhtml">
                     <h:inputText id="pname1" required="true" value="#{info.pname}"/>
                </s:decorate>
                </td>
                .....
           </tr>
      <td class="dr-subtable-cell rich-subtable-cell" style="width:80px" align="center"> 
      <rich:panel id="trtPanel">
           <table id="trtTable" style="width:557px" border="0" class="message">
           <tr style="width:557px" bgcolor="#F0F8FF" align="justify" valign="top">
                <th>Agent Name</th>
           </tr>
           <ui:repeat value="#{info.treatment}" var="itreat">                                 
                <tr>
                     <td><h:inputText id="treatmentCompoundName" value="#{itreat.treatmentCompoundName}"/> </td>
                </tr>
                .....
           </ui:repeat>  
           </table>
                
           <h:commandLink action="#{projectHome.addTreatmentLink}" 
                value="Add treatments" immediate="true" >
           <f:param name="re_hashcode" value="#{info.hashCode()}"/>
           </h:commandLink>  
      </rich:panel>
      </td>
      ....
      </ui:repeat>
      <rich:panel>
        • 1. Re: How to retain the values of text field on link click, tried using s:link ..
          cosmo

          Hello,
          is the value submited to the form bean null or the value that it is shown after page reload is null?


          If it is the first one I think you need to remove the immediate="true"?
          If it is the second one, I believe you need to define a explicit conversation in the form backing bean.

          • 2. Re: How to retain the values of text field on link click, tried using s:link ..
            diegocoronel

            try c:forEach instad ui:repeat

            • 3. Re: How to retain the values of text field on link click, tried using s:link ..
              valatharv
              Reagent entity contains treatment and 1 reagent can have multiple treatments.

              Please suggest.....

              a) I need to use immediate as link was not working on first click and hashcode from UI was not matching the entity.
              Here, I am matching the hashcode from ui with the one of an entity and adding a row to UI..

              b) UI:repeat works fine, all logic is implemented accordingly, I am not sure how I can replace c:for each, any suggestions

              <ui:repeat value="#{projectHome.reagent}" var="info" >
                   <h:inputText id="pname1" required="true" value="#{info.pname}"/>
                   ....
                        <ui:repeat value="#{info.treatment}" var="itreat">     
                             <h:inputText id="treatmentCompoundName" value="#{itreat.treatmentCompoundName}"/>
                             ......
                        </ui:repeat>  
                        <h:commandLink action="#{projectHome.addTreatmentLink}" 
                                  value="Add treatments" immediate="true" >
                             <f:param name="re_hashcode" value="#{info.hashCode()}"/>                                                                                       
                         </h:commandLink>
              </ui:repeat>
                                              
              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");
                   for(int i=0;i<reagent.length;i++){
                           if(reagent[i].hashCode()==Integer.parseInt(reagentHashcode)){
                             reagent[i].getTreatment().add(new Treatment());
                            break;
                           }
                   }
                   return "";     
              }
              • 4. Re: How to retain the values of text field on link click, tried using s:link ..
                valatharv
                Please suggest..... it is very important...

                I used immediate=true as link was not working on first click and hashcode from UI was not matching the hashcode of entity.
                Here, I am matching the hashcode from ui with the one of an entity and adding a row to UI..

                I just need that on clicking "Add Treatment" link "pname1" text field should not become null... please check the code above and help...