JSF:selectOneMenu 的绑定值永远不会被设置
我有一个如下所示的 selectOneMenu 这
<h:form>
<h:selectOneMenu value="#{CreateAds.selectedOwnerId}">
<f:selectItem itemLabel="Select a Owner" itemValue=""/>
<f:selectItems value="#{CreateAds.availableOwner}" />
</h:selectOneMenu>
</h:form>
是我的 CreateAds
ViewScoped
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
}
列表显示正确,但当值 selectedOwnerId
属性从未设置时。它的值为null。这是我的代码生成的html
<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>
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
ViewScoped
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要一个与下拉列表相同形式的命令按钮/链接。
You need a command button/link in the same form as the dropdown.