我正在使用primefaces选择列表,并获得问题所述的错误。只张贴问题相关代码。XHTML页面
<p:row>
<p:column>
<p:outputLabel style="font-size:12px;" styleClass="labelCaption"
for="bank" value="Bank(s) Name :" />
</p:column>
<p:column colspan="3">
<p:pickList id="bank" style="font-size:12px;" required="true" value="#{eipoIRBean.dualbanks}" var="dbanks" itemLabel="#{dbanks.name}" itemValue="#dbanks}">
<f:facet name="sourceCaption">Available Banks</f:facet>
<f:facet name="targetCaption">Selected Banks</f:facet>
</p:pickList>
</p:column>
</p:row>
<p:row>
<p:column colspan="4" align="left"
styleClass="panelGridFooter ui-widget-header">
<p:commandButton id="submit" ajax="false"
style="font-size:12px;" value="Save"
action="#{eipoIRBean.submit}"
icon="ui-icon-check">
</p:commandButton>
<p:commandButton icon="ui-icon-arrowreturnthick-1-w"
style="font-size:12px;" value="Cancel"
action="listMyGroupLifeClaim?faces-redirect=true"
immediate="true" global="true">
</p:commandButton>
</p:column>
</p:row>
憨豆是
@ViewScoped
@ManagedBean(name = "eipoIRBean")
public class InvestorRegistrationBean implements Serializable{
private InvestorSetupBusinessObj businessObj = new InvestorSetupBusinessObj();
private DualListModel<Bank> dualbanks;
public DualListModel<Bank> getDualbanks() {
return dualbanks;
}
public void setDualbanks(DualListModel<Bank> dualbanks) {
this.dualbanks = dualbanks;
}
public InvestorSetupBusinessObj getBusinessObj() {
return businessObj;
}
public void setBusinessObj(InvestorSetupBusinessObj businessObj) {
this.businessObj = businessObj;
}
public InvestorRegistrationBean(){
dualList_of_banks();
}
public void dualList_of_banks(){
dualbanks = new DualListModel<Bank>(businessObj.getInvestor().getBanks(), new ArrayList<Bank>());
}
public void submit() {
businessObj.getInvestor().setBanks(dualbanks.getTarget());
businessObj.save();
}
}
业务对象
public class InvestorSetupBusinessObj extends BaseBusinessObject {
private Investor investor= new Investor();
private InvestorRequestInvoker invoker = new InvestorRequestInvoker(this);
private List<Map<String,Object>> dataGrid;
public Investor getInvestor() {
return investor;
}
public void setInvestor(Investor investor) {
this.investor = investor;
}
public InvestorRequestInvoker getInvoker() {
return invoker;
}
public void setInvoker(InvestorRequestInvoker invoker) {
this.invoker = invoker;
}
public InvestorSetupBusinessObj(){
getInvestor().setBanks(invoker.selectAllBank());
}
}
<<p> Bank.java类/strong> public class Bank implements Serializable {
private static final long serialVersionUID = 1L;
private long id;
private String name;
private List<BankBranch> bankBranches;
private List<Investor> investors;
private List<InvestorJointHolder> investorJointHolders;
private List<PoBank> poBanks;
private List<PoSubscription> poSubscriptions;
public Bank() {
}
@Id
public long getId() {
return this.id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
//bi-directional many-to-one association to BankBranch
@OneToMany(mappedBy="bank")
public List<BankBranch> getBankBranches() {
return this.bankBranches;
}
public void setBankBranches(List<BankBranch> bankBranches) {
this.bankBranches = bankBranches;
}
public BankBranch addBankBranches(BankBranch bankBranches) {
getBankBranches().add(bankBranches);
bankBranches.setBank(this);
return bankBranches;
}
public BankBranch removeBankBranches(BankBranch bankBranches) {
getBankBranches().remove(bankBranches);
bankBranches.setBank(null);
return bankBranches;
}
//bi-directional many-to-many association to Investor
@ManyToMany(mappedBy="banks")
public List<Investor> getInvestors() {
return this.investors;
}
public void setInvestors(List<Investor> investors) {
this.investors = investors;
}
//bi-directional many-to-one association to InvestorJointHolder
@OneToMany(mappedBy="bank")
public List<InvestorJointHolder> getInvestorJointHolders() {
return this.investorJointHolders;
}
public void setInvestorJointHolders(List<InvestorJointHolder> investorJointHolders) {
this.investorJointHolders = investorJointHolders;
}
public InvestorJointHolder addInvestorJointHolders(InvestorJointHolder investorJointHolders) {
getInvestorJointHolders().add(investorJointHolders);
investorJointHolders.setBank(this);
return investorJointHolders;
}
public InvestorJointHolder removeInvestorJointHolders(InvestorJointHolder investorJointHolders) {
getInvestorJointHolders().remove(investorJointHolders);
investorJointHolders.setBank(null);
return investorJointHolders;
}
//bi-directional many-to-one association to PoBank
@OneToMany(mappedBy="bank")
public List<PoBank> getPoBanks() {
return this.poBanks;
}
public void setPoBanks(List<PoBank> poBanks) {
this.poBanks = poBanks;
}
public PoBank addPoBanks(PoBank poBanks) {
getPoBanks().add(poBanks);
poBanks.setBank(this);
return poBanks;
}
public PoBank removePoBanks(PoBank poBanks) {
getPoBanks().remove(poBanks);
poBanks.setBank(null);
return poBanks;
}
//bi-directional many-to-many association to PoSubscription
@ManyToMany(mappedBy="banks")
public List<PoSubscription> getPoSubscriptions() {
return this.poSubscriptions;
}
public void setPoSubscriptions(List<PoSubscription> poSubscriptions) {
this.poSubscriptions = poSubscriptions;
}
}
我的选择列表使用上述方法public InvestorSetupBusinessObj()
正确填充,但是当我选择一个银行并保存它时,它会给出以下异常。如有任何帮助,不胜感激。
Stack Trace is
javax.el.PropertyNotFoundException: /eipo/investorRegistration.xhtml @367,59 itemLabel="#{dbanks.name}": Property 'name' not found on type java.lang.String
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:111)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at org.primefaces.component.picklist.PickList.getItemLabel(PickList.java:130)
at org.primefaces.component.picklist.PickListRenderer.encodeOptions(PickListRenderer.java:226)
at org.primefaces.component.picklist.PickListRenderer.encodeList(PickListRenderer.java:192)
at org.primefaces.component.picklist.PickListRenderer.encodeMarkup(PickListRenderer.java:86)
at org.primefaces.component.picklist.PickListRenderer.encodeEnd(PickListRenderer.java:59)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:877)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1826)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1822)
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeRow(PanelGridRenderer.java:148)
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeStaticBody(PanelGridRenderer.java:110)
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeBody(PanelGridRenderer.java:63)
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:49)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:877)
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:74)
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:57)
at org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:204)
at org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:121)
at org.primefaces.component.panel.PanelRenderer.encodeEnd(PanelRenderer.java:58)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:877)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1826)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:847)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1819)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1822)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1822)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:447)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
您必须定义一个转换器才能使其工作,当使用picklist:
时,必须按照primefaces手册中的指导进行转换。<p:pickList ... var="dbanks" itemValue="#{dbanks}" converter="BankConverter" >
请看这里:JSF 2.0中的自定义转换器