0 Replies Latest reply on Oct 15, 2008 5:28 PM by Val Sw

    Displaying relational entity data in single page

    Val Sw Expert
      I need to display relational entity data in single page but not sure what will be the right approach, please suggest how I can achieve this in single page, which method I should override, what shoud be the process, etc..

      Details:
      I have 2 entities Study and Quant Experiment (there will be always 1 quant experiment for a study).
      a) I am able to persist Study & QuantExperiment from single xhtml page - OK
      ----------code used---------
      <h:form id="study" styleClass="edit">
      <s:decorate id="studyNameDecoration" template="layout/edit.xhtml">
      <ui:define name="label">Study Name</ui:define>
      <h:inputText id="studyName" required="true" value="#{studyHome.instance.studyName}"/>
      </s:decorate>
      <s:decorate id="entryPointDecoration" template="layout/edit.xhtml">
      <ui:define name="label">Entry Point</ui:define>
      <h:inputText id="entryPoint" required="true" value="#{quantExperimentHome.instance.entryPoint}"/>
      </s:decorate>
      </h:form>
      <h:commandButton id="save" value="Save" action="#{studyHome.persist}".../> 
      -----------------------------

      b) When I go to StudyList.xhtml, it displays all created Studies - OK

      Issue :
      c) I have created a link say "View" in StudyList.xhtml which on clicking takes user to "StudyListAll.xhtml" on which I am able to get study details but quant experiment details are null.
      ----------code used---------
      <s:decorate id="studyNameDecoration" template="layout/edit.xhtml">
      <ui:define name="label">Study Name</ui:define>
      <s:label value="#{studyHome.instance.studyName}"></s:label>    //THIS IS OK
      </s:decorate>
      <s:decorate id="entryPointDecoration" template="layout/edit.xhtml">
      <ui:define name="label">Entry Point</ui:define>
      <s:label value="#{quantExperimentHome.instance.entryPoint}"></s:label> //DISPLAYS NULL
      </s:decorate>
      ----------------------------

      d) studyHome.java... I need to somehow get created Quant Experiment for particular study then handle label #{quantExperimentHome.instance.entryPoint} somehow...

      But I am not sure how I can achieve this in single page.

      Note : If I click QuantExperiment list from header menu, it displays all created quantexperiments.

      studyHome.java
      --------------
      @Name("studyHome")

      public class StudyHome extends EntityHome<Study> {
           
          @In(required=false)     
          QuantExperimentHome quantExperimentHome;
           
           public StudyHome(){     super();}     
           public void setStudyHjid(Long id) {setId(id);}
           public Long getStudyHjid() {return (Long) getId();}

           @Override
           protected Study createInstance() {
                Study study = new Study();
                return study;
           }

           public void wire() {getInstance();}
           public boolean isWired() {return true;}
           public Study getDefinedInstance() {
                return isIdDefined() ? getInstance() : null;
           }
           
           public String persist(){
           java.util.ArrayList<QuantExperiment> arrListQuantExp=new              
                                                    java.util.ArrayList<QuantExperiment>();
                QuantExperiment qe=quantExperimentHome.getInstance();          
                arrListQuantExp.add(qe);
                this.instance.setQuantExperiment(arrListQuantExp);
                return super.persist();
           }
      }
      ----------------------------

      Study.java entity
      ----------
      public class Study....{
        protected Long hjid;
        ........

        public Study() {
           super();
           setQuantExperiment(new ArrayList<QuantExperiment>());
           getQuantExperiment().add(new QuantExperiment());
        }

      @OneToMany(fetch=FetchType.EAGER, cascade = {CascadeType.ALL})
      @JoinTable(name = "MET_STUDY_QUANT_EXPERIMENT_J", joinColumns = {
      @JoinColumn(name = "PARENT_STUDY_ID")
      }, inverseJoinColumns = {@JoinColumn(name = "CHILD_QUANTEXPERIMENT_ID")})
      @OrderBy

      public List<QuantExperiment> getQuantExperiment() {
      if (quantExperiment == null) {
          quantExperiment = new ArrayList<QuantExperiment>();
      }
      return this.quantExperiment;
      }
      public void setQuantExperiment(List<QuantExperiment> quantExperiment) {
          this.quantExperiment = quantExperiment;
      }