0

How to get print elements from an array in the JSF selectOneMenu, i am having an array in one bean class as

String[] leaveTypeArray;

Any suggestion for this ?

kark
  • 4,763
  • 6
  • 30
  • 44
  • You don't iterate, you use `` (note the **s** at the end of the tag component name). – Luiggi Mendoza Nov 08 '13 at 07:17
  • can you give me a sample code –  Nov 08 '13 at 07:21
  • 2
    You can find many starter examples of code at the wiki (info) page of the added tag. – skuntsel Nov 08 '13 at 07:22
  • Also, you can search for `` in the net... – Luiggi Mendoza Nov 08 '13 at 07:34
  • I cant understand what to put in the itemlabel and itemvalue –  Nov 08 '13 at 07:50
  • `itemLabel` evaluates to a String that will serve as the label to be shown for the item. `itemValue` is where you should stock the selected item (to be defined in the managed-bean). The essential is itemValue, it means you can omit itemLabel, and then, the itemValue will serve as itemLabel too. – Omar Nov 08 '13 at 08:44

1 Answers1

0

As luiggi-mendoza said that <f:selectItems> will be a good one.

You can do it with List , just add the items in List or String[] in bean class

Bean(via List) :

List listValue=new ArrayList[];

static
{
  listValue.add("First");
  listValue.add("Second");
  listValue.add("Third");
}
//Create getters and setters for listValue

Bean(via array) :

String[] listValue={"First", "Second", "Third"};

//Create getters and setters for listValue

JSF page

<p:selectOneMenu value="#{result value}">
  <f:selectItems value="#{bean.listValue}"/>
</p:selectOneMenu> 

Refer : Primefaces showcase

Community
  • 1
  • 1
kark
  • 4,763
  • 6
  • 30
  • 44
  • but cant we directly access the array itself in the selectonemenu.instead of again creating a new list and adding string objects..just to know.. –  Nov 08 '13 at 09:40