2 Replies Latest reply on Nov 25, 2008 2:30 AM by Val Sw

    Pls suggest on how to store field values temporarily so that it can be used on different page

    Val Sw Expert
      How to store field values temporarily so that it can be used on different page.

      I have entity Reagent(parent) and Treatment(child), one reagent can have multiple treatments.

      As per requirement both entity fields should be on single page... where I need to allow user to add multiple treatments.

      I am facing issues while Creating, I was trying to provide Add button where user can fill the fields and those fields should be reflected on output-text fields on main.xhtml after closing the TreatmentEdit.xhtml...

      Please suggest what should be the best approach I should go for.

      Main.xhtml
      <ui:repeat value="#{projectHome.reagent}" var="info" >
           <h:inputText id="pname1" required="true" value="#{info.pname}"/>
           ....
                <ui:repeat value="#{info.treatment}" var="itreat">
                     <h:outputText value="itreat.treatmentCompoundName"/>
                     <h:outputText value="itreat.treatmentCompoundNameDesc"/>

                          <s:button title="Add more treatments to this reagent"
                               value="Add treatment"
                               view="/TreatmentEdit.xhtml">
                          </s:button>
                </ui:repeat>
      </ui:repeat>
        • 1. Re: Pls suggest on how to store field values temporarily so that it can be used on different page
          Mikael Andersson Master

          You'll need to give us some more information


          For example which scope is your backing bean projectHome in? It it is in session scope then you are fine, you just need to do some work in setting the object you want to add more treatments to in your backing bean.
          Otherwise you might want to consider using a long running conversation, or add the some value to the request (via request parameters).


          Cheers,
          micke

          • 2. Re: Pls suggest on how to store field values temporarily so that it can be used on different page
            Val Sw Expert
            Thanks for replying Micke...

            Hierarchy of entities are Project > QuantExperiment > Reagent > Treatment.

            I need to add multiple treatments to reagent row, as per ui:reapeat tag above.

            My ui:repat works fine, like if I add "addTreatmentLink" method in project home and from above ui use "h:commandLink action="#{projectHome.addTreatmentLink}" it adds a treatment row for reagent. But as per requirement, we should take user to other page where user can fill treatment fields and on closing the other page treatment fields should be reflected in main page.

            Please suggest, if we can make use of this code or any other way around....

            <h:commandLink action="#{projectHome.addTreatmentLink}" 
            value="Add treatments" immediate="true">
            <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 "";     
            }
            ------------

            ProjectHome:
            ------------
            package com.session;

            @Name("projectHome")
            public class ProjectHome extends EntityHome<Project> {

                 public void setProjectHjid(Long id) {
                      setId(id);
                 }

                 public Long getProjectHjid() {
                      return (Long) getId();
                 }

                 @Override
                 protected Project createInstance() {
                      Project project = new Project();
                      return project;
                 }

                 public void wire() {
                      getInstance();
                 }

                 public boolean isWired() {
                      return true;
                 }

                 public Project getDefinedInstance() {
                      return isIdDefined() ? getInstance() : null;
                 }

                 public List<QuantExperiment> getQuantExperiment() {
                      return getInstance() == null ? null : new ArrayList<QuantExperiment>(
                                getInstance().getQuantExperiment());
                 }
                 
                 //CUSTOM FUNCTIONALITY METHODS STARTS FROM HERE          
                 @Out(required=false)
                 @In(required=false)     
                ReagentHome reagentHome=new ReagentHome();
                 
                 @Out(required=false)
                 @In(required=false)     
                TreatmentHome treatmentHome=new TreatmentHome();          
                 
                 private Reagent[] reagent=new Reagent[]{new Reagent()};
                      
                 private Reagent initializeReagent(Reagent re){
                      List<Treatment> t=re.getTreatment();                    
                      if(t.size()<1){
                           t.add(new Treatment());               
                      }
                      re.setTreatment(t);
                      return re;
                 }
                 
                 public ProjectHome(){
                      super();
                      Identity.setSecurityEnabled(true);
                      for(int i=0;i<reagent.length;i++){
                           reagent[i]=initializeReagent(reagent[i]);                         
                      }
                 }     
                 
                 public Reagent[] getReagent() {
                      return reagent;
                 }
                 
                 public void setReagent(Reagent[] reagent) {
                      this.reagent = reagent;
                 }     
            }