JSF 多个组合框问题
我对多个组合框有疑问,而且我也在使用 primefaces。我的代码如下;
xhtml页面:
<f:view xmlns="http://www.w3.org/19399/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:pm="http://primefaces.prime.com.tr/mobile"
contentType="text/html">
<pm:page title="Title">
<pm:view id="organizationView" swatch="b">
<pm:header title="Title">
<f:facet name="right">
<pm:button value="Logout" icon="minus" />
</f:facet>
</pm:header>
<pm:content>
<h:form id="organizationForm" prependId="false">
<p:separator />
<h:selectOneMenu id="company" value="#{myView.selected}" >
<f:selectItem value="#{null}" itemLabel="Select company..." noSelectionOption="true" />
<f:selectItems value="#{myView.companyList}"
var="company" itemLabel="#{company.name}" itemValue="#{company.companyId}"/>
<p:ajax immediate="true" update="organization" listener="#{myView.loadOrganization}" />
</h:selectOneMenu>
<h:selectOneMenu id="organization" value="#{myView.organization.orgId}">
<f:selectItem itemLabel="Select Organization..." itemValue="" />
<f:selectItems value="#{myView.orgList}"
var="organization" itemLabel="#{organization.name}" itemValue="#{organization.orgId}"/>
</h:selectOneMenu>
<p:separator />
</h:form>
</pm:content>
</pm:view>
</pm:page>
和 backing-bean 是这样的:
@Component("myView")
@Scope("view")
public class MyView implements Serializable {
private Long selected;
private List<Company> companyList;
private Company company;
private Organization organization;
private List<Organization> orgList;
@Autowired
private MyViewService myViewService;
public MyView() {
}
@PostConstruct
public void init(){
companyList = myViewService.findAllCompany();
}
public void loadOrganization() {
if(selected != null && selected >0L)
orgList = myViewService.findGroupsByCompanyId(selected);
}
public void setCompany(Company company) {
this.company = company;
}
public Company getCompany() {
return company;
}
public List<Company> getCompanyList() {
return companyList;
}
public void setCompanyList(List<Company> companyList) {
this.companyList = companyList;
}
public List<Organization> getOrgList() {
return orgList;
}
public void setOrgList(List<Organization> orgList) {
this.orgList = orgList;
}
public Organization getOrganization() {
return organization;
}
public void setOrganization(Organization organization) {
this.organization = organization;
}
public myViewService getMyViewService() {
return myViewService;
}
public void setMyViewService(MyViewService myViewService) {
this.myViewService = myViewService;
}
public Long getSelected() {
return selected;
}
public void setSelected(Long selected) {
this.selected = selected;
}
}
当我更改公司组合框时,它调用 loadOrganization() 方法,但 selected 值设置为 null。我如何从公司组合框中获取选定值? 谢谢大家的帮助。
I have a problem about multiple combobox, also i am using primefaces. My code is like below;
xhtml page:
<f:view xmlns="http://www.w3.org/19399/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:pm="http://primefaces.prime.com.tr/mobile"
contentType="text/html">
<pm:page title="Title">
<pm:view id="organizationView" swatch="b">
<pm:header title="Title">
<f:facet name="right">
<pm:button value="Logout" icon="minus" />
</f:facet>
</pm:header>
<pm:content>
<h:form id="organizationForm" prependId="false">
<p:separator />
<h:selectOneMenu id="company" value="#{myView.selected}" >
<f:selectItem value="#{null}" itemLabel="Select company..." noSelectionOption="true" />
<f:selectItems value="#{myView.companyList}"
var="company" itemLabel="#{company.name}" itemValue="#{company.companyId}"/>
<p:ajax immediate="true" update="organization" listener="#{myView.loadOrganization}" />
</h:selectOneMenu>
<h:selectOneMenu id="organization" value="#{myView.organization.orgId}">
<f:selectItem itemLabel="Select Organization..." itemValue="" />
<f:selectItems value="#{myView.orgList}"
var="organization" itemLabel="#{organization.name}" itemValue="#{organization.orgId}"/>
</h:selectOneMenu>
<p:separator />
</h:form>
</pm:content>
</pm:view>
</pm:page>
and backing-bean is like this:
@Component("myView")
@Scope("view")
public class MyView implements Serializable {
private Long selected;
private List<Company> companyList;
private Company company;
private Organization organization;
private List<Organization> orgList;
@Autowired
private MyViewService myViewService;
public MyView() {
}
@PostConstruct
public void init(){
companyList = myViewService.findAllCompany();
}
public void loadOrganization() {
if(selected != null && selected >0L)
orgList = myViewService.findGroupsByCompanyId(selected);
}
public void setCompany(Company company) {
this.company = company;
}
public Company getCompany() {
return company;
}
public List<Company> getCompanyList() {
return companyList;
}
public void setCompanyList(List<Company> companyList) {
this.companyList = companyList;
}
public List<Organization> getOrgList() {
return orgList;
}
public void setOrgList(List<Organization> orgList) {
this.orgList = orgList;
}
public Organization getOrganization() {
return organization;
}
public void setOrganization(Organization organization) {
this.organization = organization;
}
public myViewService getMyViewService() {
return myViewService;
}
public void setMyViewService(MyViewService myViewService) {
this.myViewService = myViewService;
}
public Long getSelected() {
return selected;
}
public void setSelected(Long selected) {
this.selected = selected;
}
}
when i change company combobox it calls loadOrganization() method, but selected value is set to null. How can i get selected value from company combobox?
Thx all for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望在使用提交的值更新模型值后调用侦听器,请从
中删除immediate="true"
属性。Remove the
immediate="true"
attribute from<p:ajax>
if you want the listener to be invoked after that the model value is been updated with the submitted value.