2 Replies Latest reply on Dec 10, 2010 1:20 PM by Val Sw

    Displaying value against Id for single entity.

    Val Sw Expert
      Hi,

      Please advice if there is any trick on how I can display value/ name against Id from single table/ entity when xhtml page loads in point b(i), b(ii).

      Overview :
      a) I have single entity Computers with fields as compId, computerName,  applicationServerId

      @Entity
      @Name("Computers")
      @Table(name = "COMPUTERS")
      public class Computers implements java.io.Serializable {

              private Long compId;
              private String computerName;
              private Long applicationServerId;

              @Column(name = "COMP_ID")
              public Long getCompId() {
                      return this.compId;
              }

              public void setCompId(Long compId) {
                      this.compId = compId;
              }

              @Id
              @Column(name = "COMPUTER_NAME", unique = true, nullable = false, length = 50)
              @NotNull
              @Length(max = 50)
              public String getComputerName() {
                      return this.computerName;
              }

              public void setComputerName(String computerName) {
                      this.computerName = computerName;
              }
             

              @Column(name = "APPLICATION_SERVER_ID")
              public Long getApplicationServerId() {
                      return this.applicationServerId;
              }

              public void setApplicationServerId(Long applicationServerId) {
                      this.applicationServerId = applicationServerId;
              }
      }


      b) Seam-gen generated nice home and view objects.

      Here applicationServerId can be any compId. 

      i) In Computers.xhtml applicationServerId is mapped from
      <s:decorate id="applicationServerId" template="layout/display.xhtml">
                  <ui:define name="label">Application Server</ui:define>
                 #{computersHome.instance.applicationServerId} // CAN THIS BE SOMEHOW MAPPED TO CORRESPONDING computerName
      </s:decorate>

      ii) In ComputersList.xhtml applicationServerId is displayed from wrkComputersList.resultList
      <rich:dataTable id="computersList"
                      var="computers"
                    value="#{computersList.resultList}"
                 rendered="#{not empty computersList.resultList}">

      <h:column>
              <f:facet name="header">
      <s:link styleClass="columnHeader"
                              value="Processing ServerId #{computersList.order=='applicationServerId asc' ? messages.down : ( computersList.order=='applicationServerId desc' ? messages.up : '' )}">
                           <f:param name="order" value="#{computersList.order=='applicationServerId asc' ? 'applicationServerId desc' : 'applicationServerId asc'}"/>
                      </s:link>
              </f:facet>
                      #{computers.applicationServerId} // CAN THIS BE SOMEHOW MAPPED TO CORRESPONDING computerName
      </h:column>
        • 1. Re: Displaying value against Id for single entity.
          Tauseef Ahmed Newbie

          Hi,


          There are several ways to implement, one example is call a method from xhtml passing computers.applicationServerId as a parameter and return string as a computerName.
          ex: #{method(computers.applicationServerId)}.



          Thanks,
          Tauseef

          • 2. Re: Displaying value against Id for single entity.
            Val Sw Expert
            Thanks for the reply...

            I am able to get applicationServerId in home object but how to get it in bean class (looks like some small thing I am missing)

            a) I created simple bean to pass applicationServerId, but it always says method not found/ error parsing as below, any idea what small thing I am missing.
            XHTML: #{computersHome.instance.processingServerId}// THIS IS THE ID I NEED TO PASS

            <h:outputText value="#{compUtilsBean.applicationServerName(#{computersHome.instance.processingServerId})}" >
            "//Gives Error Parsing: #{compUtilsBean.applicationServerName(#{computersHome.instance.processingServerId})}"

            <h:outputText value="#{compUtilsBean.applicationServerName(23)}"/> //If I try to hard code for testing it says
            //Error Method #{compUtilsBean.applicationServerName('23')}": Method not found: com.session.CompUtilsBean

            <h:outputText value="#{compUtilsBean.applicationServerName}"/ >// THIS works fine for 1st. method in bean method but no id passed.

            @Name("compUtilsBean")
            @Scope(ScopeType.SESSION)
            public class CompUtilsBean {
                 ...
                 public String getApplicationServerName() {
                      return "test1";
                 }     
                 public String getApplicationServerName(Long compId) {
                      return "test2";
                 }
                 public String getApplicationServerName(String compId) {
                      return "test3";
                 }
            }

            b) This works fine I am able to get ApplicationServerId by creating method in corresponding computerHome and using getInstance
            ComputerHome.java
            public String getApplicationServerName() {          
                 Computers comp = getInstance();
                 log.info("ComputerHome.getApplicationServerName application_server_id : "+this.getInstance().getApplicationServerId());
                 //Get computerName on the basis of this this.getInstance().getApplicationServerId() and return
                 return "applicationServerName";
            }