Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
989 views
in Technique[技术] by (71.8m points)

jsf - Default selection for <f:selectItem> within <h:selectOneMenu>

How to make default selection for <f:selectItem> within <h:selectOneMenu>?

It's needed,that particular "20" item of dropdown to be already selected when page is loaded.

  <h:selectOneMenu value="#{fileSearchCriteriaOut.recordsPerPage}"  >            
               <f:selectItem itemLabel="5" itemValue="5" />
               <f:selectItem itemLabel="10" itemValue="10" />
               <f:selectItem itemLabel="20" itemValue="20" selected="true"/>
  </h:selectOneMenu>

these four don't work:

<f:selectItem itemLabel="20" selected="true"/>
<f:selectItem itemLabel="20" selected="selected"/>
<f:selectItem itemLabel="20" checked="checked"/>
<f:selectItem itemLabel="20" checked="true"/>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
<h:selectOneMenu id="items" value="#{bean.selectedItem}">
  <f:selectItem itemLabel="10" itemValue="10"/>
  <f:selectItem itemLabel="20" itemValue="20"/>
  <f:selectItem itemLabel="30" itemValue="30"/>
</h:selectOneMenu>

The default selection would be the one which has value same as selectedItem which you set in bean.

selectedItem = 20;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...