JSF: the binding value of selectOneMenu never get set
I have a selectOneMenu look like this
<h:form>
<h:selectOneMenu value="#{CreateAds.selectedOwnerId}">
<f:selectItem itemLabel="Select a Owner" itemValue=""/>
<f:selectItems value="#{CreateAds.availableOwner}" />
</h:selectOneMenu>
</h:form>
Here is my CreateAds
ViewSc开发者_Python百科oped
bean
@ViewScoped
public class CreateAds extends View {
private List<SelectItem> availableOwner = null;
private String selectedOwnerId = null;
public CreateAds() {
}
@PostConstruct
public void init(){
availableOwner = new ArrayList<SelectItem>();
List<User> users = scholarEJB.findSponsorAndAdmin();
for(User u : users){
availableOwner.add(new SelectItem(u.getId().toString(), u.getFname() + " " + u.getLname()));
}
}
//getters and setters
}
The list display correctly, but when value selectedOwnerId
attribute never got set. Its value is null. Here is the html my code generated
<select size="1" name="j_idt50:j_idt51">
<option value="">Select a Owner</option>
<option value="19102">Harry Pham</option>
<option value="27101">Thomas Chang</option>
<option value="27562">Hao Shen Lin</option>
</select>
You need a command button/link in the same form as the dropdown.
精彩评论