5 Replies Latest reply on Mar 20, 2007 9:28 AM by pmuir

    How to Inject app properties to bean transient method

    statelessbean

      Hi,
      I have collection of Entity Beans in my Statefull Bean loaded from DB, and iterated in page in <h:dataTable, like:

      List listOfMyBeans;

      And here is my problem: i need to load some text from app properties, if some field in bean is true/false, nevermind.
      I have two ideas:
      1. get this text from app properties when iterating my collection on page.
      2. When load my collection in Statefull Bean, here text is injected into my entity bean.

      What way is better?
      if first, here i got problem, how to get into my messages map from Entity Bean when iterating directly on page?

      @In
      protected Map<String, String> messages;
      

      Regards!



        • 1. Re: How to Inject app properties to bean transient method
          fernando_jmt

          I think the 1 approach it is ok.

          I have working something similar:

           <ice:selectManyCheckbox value="#{userManager.userRoles}" id="userRoles">
           <s:selectItems value="#{roleList.resultList}" var="role" label="#{messages[role.description]}"/>
           </ice:selectManyCheckbox>
          


          As you can see I get the property value for role.description on the fly using the messages.

          • 2. Re: How to Inject app properties to bean transient method
            statelessbean

            That's not exacly i want to...
            look:
            My Entity Bean looks like this:

            private int howOld;
            private boolean sex;

            @Transient
            public String getPersonName() {
            
             if(sex) {
             switch(howOld) {
             case(20) :
             //And here i want to get some text from app properties like example:
             messages.get('sex.youngMane'); <-----here i want to Inject some string
             break:
             .....
             }
             }
            }
            


            • 3. Re: How to Inject app properties to bean transient method
              pmuir

               

              <h:column>
               <h:outputText value="#{messages['sex.youngMane']}" rendered="#{entity.sex and entity.howOld eq 20}" />
              </h:column>


              • 4. Re: How to Inject app properties to bean transient method
                sherkan777

                 

                "petemuir" wrote:
                <h:column>
                 <h:outputText value="#{messages['sex.youngMane']}" rendered="#{entity.sex and entity.howOld eq 20}" />
                </h:column>


                Isn't better to get string directly from method?
                Maybe u not understod my think.
                I have field like int in each entity bean and collection of those beans.
                and iterating my collection on page i want to get from application resources some string, dependent of my int flag.
                like

                public int getAge() {
                 ....
                }
                
                @Transient
                public String getName() {
                 int age = getAge();
                 String tempString = "";
                 switch(age) {
                 case(1) :
                 tempString = messages.("age.veryYoung");
                 break;
                 case(2) :
                 tempString = messages.("age.twoYearsOld");
                 break;
                 }
                 return tempString;
                }
                
                
                
                and in <h:dataTable
                
                <h:column>
                 <h:outputText value="currentBean.name" />
                </h:column>
                
                
                


                • 5. Re: How to Inject app properties to bean transient method
                  pmuir

                  I understand :) I wouldn't want to mix my business and presentation logic like you suggest, so I would keep the presentation logic in the page. You could of course do what you suggest as well.