0

I have a simple OneMenu in JSF:

@ManagedBean
@ViewScoped
public class ProductBean {
  ...
  protected static Map<String, String> priceTypes;
  ...
  getter & setter
}

<p:selectOneMenu id="sizeType" >
  <f:selectItems value="#{productBean.priceTypes}" />
</p:selectOneMenu>

In my usecase, i want to preselect[1] an option out of "priceTypes" - how can i do that?

I am using Glassfish 3.1.2.2 with Primefaces 3.4.1

[1] See "selected" at http://www.w3schools.com/tags/tag_option.asp

Markus Schulte
  • 4,171
  • 3
  • 47
  • 58

1 Answers1

1

I am not sure about pfaces, but in plain JSF you just have to set the value attribute in the selectOneMenu tag, and make sure that the value returned by the bean is in the select list.

<p:selectOneMenu id="sizeType" value="#{myBean.sizeType}>
  <f:selectItems value="#{productBean.priceTypes}" />
 </p:selectOneMenu> 

Of course, sizeType must mutch the key of your map.

SJuan76
  • 24,532
  • 6
  • 47
  • 87