9 Replies Latest reply on Apr 13, 2007 9:05 PM by tony.herstell1

    How to double indirect a label (seam question)

    tony.herstell1

      I have an enumesation and I want to use the string value to inl8 it from the messages.properties...

      from Advert:

       public enum AdvertType {Lineage, BannerAd};
       public static final String LINEAGE = AdvertType.Lineage.toString();
       public static final String BANNERAD = AdvertType.BannerAd.toString();
      
       ...
      
       @Transient
       public List<String> getAdvertTypes() {
       List<String> advertTypesToReturn = new ArrayList<String>();
       advertTypesToReturn.add(Advert.LINEAGE);
       advertTypesToReturn.add(Advert.BANNERAD);
       return advertTypesToReturn;
       }
      



      How do I do this?


      <h:selectOneRadio id="advertType" value="#{advertisingCampaignController.campaign.advert.type}">
       <s:selectItems value="#{advertisingCampaignController.campaign.advert.advertTypes}" var="advertType" label="#{messages.label_ad_type_#{advertType}}"/>
      </h:selectOneRadio>
      


      also tried:
      label="#{messages.label_ad_type_}#{advertType}"
      




        • 1. Re: How to double indirect a label (seam question)
          pmuir

           

          @Factory("advertType")
          public AdvertType[] getAdvertTypes() {
           return AdvertType.values();
          }


          <h:selectOneRadio id="advertType" value="#{advertisingCampaignController.campaign.advert.type}">
           <s:selectItems value="#{advertTypes}" var="advertType" label="#{messages['label_ad_type_'advertType]}"/>
           <s:convertEnum />
          </h:selectOneRadio>


          Though I'm not sure concating the string for the message key like that is valid .

          • 2. Re: How to double indirect a label (seam question)
            tony.herstell1

             

            <s:decorate>
             <h:selectOneRadio id="advertType" required="true" value="#{advertisingCampaignController.campaign.advert.type}">
             <s:selectItems value="#{advertisingCampaignController.campaign.advert.advertTypes}" var="advertType" label="advertType">
             <s:convertEnum />
             </s:selectItems>
             </h:selectOneRadio>
             </s:decorate>
            


            gives

            SEVERE: Error Rendering View[/pages/advertisingCampaign/wizard.xhtml]
            com.sun.facelets.tag.TagException: /WEB-INF/pages/advertisingCampaignWizard/adType.xhtml @25,28 <s:convertEnum> Parent not an instance of ValueHolder: org.jboss.seam.ui.UISelectItems@6ba6895c
            


            ????

            and you were right:
            label="#{messages['label_ad_type_'advertType]}"
            



            didnt work

            :(


            • 3. Re: How to double indirect a label (seam question)
              pmuir

              Put the s:convertEnum as direct child of the h:selectOneRadio as I did.

              #{messages[advertType]} will work, alternatively, put a property on the Enum which contains the key e.g. #{messages[advertType.key]}

              • 4. Re: How to double indirect a label (seam question)
                tony.herstell1

                This seemed to get rid of the error (using a list (no I dont know why))...
                still cant get the label to work.
                Any ideas?

                 @Transient
                 public List<String> getAdvertTypes() {
                 List<String> advertTypesAsStringList = new ArrayList<String>();
                 AdvertType[] advertTypesAsStringArray = AdvertType.values();
                 for (AdvertType type : advertTypesAsStringArray) {
                 advertTypesAsStringList.add(type.toString());
                 }
                 return advertTypesAsStringList;
                 }
                


                • 5. Re: How to double indirect a label (seam question)
                  tony.herstell1

                   

                  "petemuir" wrote:
                  Put the s:convertEnum as direct child of the h:selectOneRadio as I did.

                  #{messages[advertType]} will work, alternatively, put a property on the Enum which contains the key e.g. #{messages[advertType.key]}


                  trying that now

                  • 6. Re: How to double indirect a label (seam question)
                    tony.herstell1

                    >> java.lang.String cannot be cast to java.lang.Enum

                    I think I did what you said...

                    From Advert entity:

                     @Transient
                     public AdvertType[] getAdvertTypes() {
                     return AdvertType.values();
                     }
                    



                    <h:selectOneRadio id="advertType" required="true" value="#{advertisingCampaignController.campaign.advert.type}">
                     <s:selectItems value="#{advertisingCampaignController.campaign.advert.advertTypes}" var="advertType" label="#{messages[advertType]}"/>
                     <s:convertEnum />
                    </h:selectOneRadio>
                    


                    • 7. Re: How to double indirect a label (seam question)
                      tony.herstell1

                      Pete, your kung foo is strong:

                       public enum AdvertType {
                       Lineage ("label_ad_type_lineage"),
                       BannerAd ("label_ad_type_banner_ad");
                       private final String label;
                       AdvertType(String label) {
                       this.label = label;
                       }
                       public String getLabel() { return label; }
                       }
                      


                       @NotNull(message="required")
                       @Length(max = 30)
                       public AdvertType getType() {
                       return type;
                       }
                      
                       public void setType(AdvertType type) {
                       this.type = type;
                       }
                      


                      <h:selectOneRadio id="advertType" required="true" value="#{advertisingCampaignController.campaign.advert.type}">
                       <s:selectItems value="#{advertisingCampaignController.campaign.advert.advertTypes}" var="advertType" label="#{messages[advertType.label]}"/>
                       <s:convertEnum />
                      </h:selectOneRadio>
                      



                      Thanyou for your suppoort and pointing me in the right direction (I didnt even know Emuns could have "parameters"!




                      • 8. Re: How to double indirect a label (seam question)
                        tony.herstell1

                        Oh yes and this bit.

                         @Transient
                         public AdvertType[] getAdvertTypes() {
                         return AdvertType.values();
                         }
                        


                        • 9. Re: How to double indirect a label (seam question)
                          tony.herstell1

                          Darn..

                          If I use a validateAll for the whole form I get:

                          >>> java.lang.String cannot be cast to java.lang.Enum

                          
                          <h:selectOneRadio id="advertType" required="true" value="#{advertisingCampaignController.campaign.advert.type}">
                           <s:selectItems value="#{advertisingCampaignController.campaign.advert.advertTypes}" var="advertType" label="#{messages[advertType.label]}"/>
                           <s:convertEnum />
                           <s:validate/>
                          </h:selectOneRadio>
                          


                          For now, (after finding the problem!), I have just added <s:validate/> to all the other fields.

                          Is this a JIRA issue?