3 Replies Latest reply on Dec 1, 2008 12:29 AM by valatharv

    Urgent, please help, h:commandLink not working on first click, is it a bug?

    valatharv
      version used: jboss-seam-2.0.2.SP1, jboss-4.2.3

      I am in ddep trouble... please suggest

      h:commandLink not working on first click. If I click h:commandLink second time it works fine.

      Is it a bug, I explored a lot and found this https://jira.jboss.org/jira/browse/RF-3357
      I also tried using richfaces 3.2.2.GA but no luck.

      I am matching the hashcode from ui with the one of an entity and adding a row to UI..
      I don't want to use immediate=true as other text fields in the panel becomes null...

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

      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 "";     
      }
        • 1. Re: Urgent, please help, h:commandLink not working on first click, is it a bug?
          meetoblivion

          have you considered putting the param via config in your pages.xml? 

          • 2. Re: Urgent, please help, h:commandLink not working on first click, is it a bug?
            valatharv
            Thanks for replying John, I removed immediate=true and removed "int hashCode()" which was generated by JAXB, I am now able to add treatment row on single click.

            However, I am not able to understand the following issue, please guide...

            On clicking "Add treatment" link it adds a new row but values of previous rows are populated by default.

            Example:
            If h:inputText id="treatmentCompoundName" contains say "aaa" and when I click "Add treatments" link, it adds new h:inputText for treatment compound as per ui:repeat
            but new h:inputText for treatment compound displays the same value as "aaa" it should be null.

            ------xhtml code------------
            <ui:repeat value="#{quantExperimentHome.reagent1}" 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="#{quantExperimentHome.addTreatmentLink}" 
               value="Add treatments" immediate="true" >
              <f:param name="re_hashcode" value="#{info.hashCode()}"/>
            </h:commandLink>
            </ui:repeat>

            Reagent Entity
            ----------------
            protected List<Treatment> treatment;
            @OneToMany(cascade = {CascadeType.ALL}, mappedBy="reagent")
            public List<Treatment> getTreatment() {
                    if (treatment == null) {
                        treatment = new ArrayList<Treatment>();
                    }
                    return this.treatment;
                }
            public void setTreatment(List<Treatment> treatment) {
                      for(Treatment t : treatment){
                         t.setReagent(this);
                      }
                       this.treatment = treatment}

            Treatment entity
            -------------------
            public class Treatment impl...{
            protected Reagent reagent;
            @ManyToOne(optional=false)
               public Reagent getReagent() {
                  return reagent;
               }
            public void setReagent(Reagent reagent) {
                  this.reagent = reagent;
               }
            • 3. Re: Urgent, please help, h:commandLink not working on first click, is it a bug?
              valatharv
              Sorry for the typo... h:commandLink is now

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

              and QuantExperimentHome.addTreatmentLink() is:
              -----------------------------------------
              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<reagent1.length;i++){
                   if(reagent1[i].hashCode()==Integer.parseInt(reagentHashcode)){
                   Treatment treatment = new Treatment();
                   treatment.setReagent(reagent1[i]);
                   reagent1[i].getTreatment().add(treatment);
                   break;
              }
              }
              return "";     
              }