Mohemmed Bilal Ilyas
Mohemmed Bilal Ilyas

Reputation: 31

how do i get itemvalue of <f:selectItem> in my Bean?

How to get value from "itemvalue" attribute of 'f:selectItem itemLabel="Request Posting" itemValue="1" ' in a managed Bean in jsf ?

Upvotes: 0

Views: 877

Answers (1)

BalusC
BalusC

Reputation: 1108632

JSF will just set it in the property behind value attribute of the UISelectOne or UISelectMany component wherein you are using this <f:selectItem> as child.

E.g.

<h:selectOneMenu value="#{bean.someProperty}">
    <f:selectItem itemLabel="Request Posting" itemValue="1" />
    ...
</h:selectOneMenu>
<h:commandButton value="submit" action="#{bean.submit}" />

It'll during the invoke action phase (e.g. in command button action method) just be available as someProperty.

private String someProperty; // +getter+setter

public void submit() {
    System.out.println(someProperty); // Look, JSF has already set it!
}

See also:

Upvotes: 1

Related Questions