简体   繁体   中英

How to dynamically generate Labels in jsf2.0 based on the data in the backing bean?

I am currently using jsf2.0 and rich faces.I have an object in the backing bean having a string field, holding large data ,each data being separated by ";" symbol. I want to extract each data and dynamically generate as many as 'h output labels' holding individual data.For instance if my string value contains 'apple;orange;mango;tea;coffee', I need to get five labels, each having value as apple,orange,mango,tea,coffee respectively displayed. Any help would be appreciated.

firstly,large string value is being split and taken to an array,then the array holding individual data being converted to an array list so that it can be used in the xhtml view

    @PostConstruct


    public void init(){
        ArryayList fruitList<string>=new ArryayList<String>
         String[] fruitArray = fruitobject.getFruitNames().split(";");
         for (String fruit : fruitArray){
            fruitList.add(fruit);
    }

   }

ui repeat tag is being used to create labels based on the value in the array list

<ui:repeat value="#{backingbeanName. fruitLis}" var="field" >
              <tr>
                      <td> <h:outputLabel value="Fruit Name"/></td>

                     <td>   <h:outputLabel  value=":"></h:outputLabel> </td>



               <td> <h:outputLabel value="#{field}"/></td>

               </tr>
            </ui:repeat>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM