您好我是richfaces选项列表的新手,我的方案是加载hashmap并选择我需要在选项列表中加载它的键值。获得密钥后,我需要生成动态jasper报告。我的问题是在尝试加载地图值时,我最终得到了Typecast异常以及我遇到的例子。
<rich:pickList id="pickList1" value="#{xxx.selectionBean.fieldNameList}" sourceCaption="Fields to be Selected for Report"
targetCaption="Selected Fields for Report" listWidth="165px" listHeight="100px" orderable="true" converter="pickListConvertor">
<f:selectItems value="#{xxx.commencementworkBean.commencementList}" var="s"
itemLabel="#{s.key}" itemValue="#{s.value}" />
<f:converter converterId="pickListConvertor" />
</rich:pickList>
SelectionBean
package xxx.xxx.xxx.bean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class SelectionBean implements Serializable{
/**
vs00324258
*/
private static final long serialVersionUID = -1597587007448113972L;
private String key;
private String value;
List<SelectionBean> fieldNameList = new ArrayList<SelectionBean>();
List<SelectionBean> dynamicList = new ArrayList<SelectionBean>();
List<Object> fieldList = new ArrayList<Object>();
public List<SelectionBean> getFieldNameList() {
return fieldNameList;
}
public void setFieldNameList(List<SelectionBean> fieldNameList) {
this.fieldNameList = fieldNameList;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public List<SelectionBean> getDynamicList() {
return dynamicList;
}
public void setDynamicList(List<SelectionBean> dynamicList) {
this.dynamicList = dynamicList;
}
public List<Object> getFieldList() {
return fieldList;
}
public void setFieldList(List<Object> fieldList) {
this.fieldList = fieldList;
}
}
PicklistConvertor
@FacesConverter(value = "pickListConvertor")
public class PickListConvertor implements Converter{
@Override
public Object getAsObject(FacesContext context, UIComponent component, String submittedValue) {
if(submittedValue.trim().equals("")){
return null;
}else{
return submittedValue.toString();
}
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
if (value == null || value.equals("")) {
return "";
} else {
return String.valueOf(((SelectionBean) value));
}
}
}
CommencementWorkBean
public class CommencementworkBean implements Serializable{
/**
vs00324258
*/
private static final long serialVersionUID = -5020735931910106047L;
private String agreementnum;
private String agreementtype;
private String authorityentering;
private String contractorname;
private String tendercalledbyoffice;
private Date dateofagreemtn;
private Date dateofcommofwork;
private Date dateofintendedcompl;
private Date tenderdate;
private Date duedateofmeterialworks;
private Date regdateofcontract;
private String detailsofsecurdeposit;
private String estamtsanctionno;
private String estimateamt;
private String isitlowest;
private String nameofwork;
private String orignalorsupplemental;
private String pricevariationapplicable;
private String reasonforlowest;
private String regnumberofvendor;
private String remarks;
private String taxes;
private String statusCode;
private String tenderauthority;
private String tenderpremium;
private String validityofsecurdeposit;
private String valueofcontract;
private String worldbankapproval;
private boolean searchCommTableEnabled = false;
private String fieldName;
private Map<String,Object> commencementList = new TreeMap<String, Object>();
private String headerName;
private String valueName;
private List<CommencementworkBean>searchCommencementBeanList = new ArrayList<CommencementworkBean>();
public String getAgreementnum() {
return agreementnum;
}
public void setAgreementnum(String agreementnum) {
this.agreementnum = agreementnum;
}
public String getAgreementtype() {
return agreementtype;
}
public void setAgreementtype(String agreementtype) {
this.agreementtype = agreementtype;
}
public String getAuthorityentering() {
return authorityentering;
}
public void setAuthorityentering(String authorityentering) {
this.authorityentering = authorityentering;
}
public String getContractorname() {
return contractorname;
}
public void setContractorname(String contractorname) {
this.contractorname = contractorname;
}
public String getTendercalledbyoffice() {
return tendercalledbyoffice;
}
public void setTendercalledbyoffice(String tendercalledbyoffice) {
this.tendercalledbyoffice = tendercalledbyoffice;
}
public Date getDateofagreemtn() {
return dateofagreemtn;
}
public void setDateofagreemtn(Date dateofagreemtn) {
this.dateofagreemtn = dateofagreemtn;
}
public Date getDateofcommofwork() {
return dateofcommofwork;
}
public void setDateofcommofwork(Date dateofcommofwork) {
this.dateofcommofwork = dateofcommofwork;
}
public Date getDateofintendedcompl() {
return dateofintendedcompl;
}
public void setDateofintendedcompl(Date dateofintendedcompl) {
this.dateofintendedcompl = dateofintendedcompl;
}
public Date getTenderdate() {
return tenderdate;
}
public void setTenderdate(Date tenderdate) {
this.tenderdate = tenderdate;
}
public Date getRegdateofcontract() {
return regdateofcontract;
}
public void setRegdateofcontract(Date regdateofcontract) {
this.regdateofcontract = regdateofcontract;
}
public String getDetailsofsecurdeposit() {
return detailsofsecurdeposit;
}
public void setDetailsofsecurdeposit(String detailsofsecurdeposit) {
this.detailsofsecurdeposit = detailsofsecurdeposit;
}
public String getEstamtsanctionno() {
return estamtsanctionno;
}
public void setEstamtsanctionno(String estamtsanctionno) {
this.estamtsanctionno = estamtsanctionno;
}
public String getEstimateamt() {
return estimateamt;
}
public void setEstimateamt(String estimateamt) {
this.estimateamt = estimateamt;
}
public String getIsitlowest() {
return isitlowest;
}
public void setIsitlowest(String isitlowest) {
this.isitlowest = isitlowest;
}
public String getNameofwork() {
return nameofwork;
}
public void setNameofwork(String nameofwork) {
this.nameofwork = nameofwork;
}
public String getOrignalorsupplemental() {
return orignalorsupplemental;
}
public void setOrignalorsupplemental(String orignalorsupplemental) {
this.orignalorsupplemental = orignalorsupplemental;
}
public String getPricevariationapplicable() {
return pricevariationapplicable;
}
public void setPricevariationapplicable(String pricevariationapplicable) {
this.pricevariationapplicable = pricevariationapplicable;
}
public String getReasonforlowest() {
return reasonforlowest;
}
public void setReasonforlowest(String reasonforlowest) {
this.reasonforlowest = reasonforlowest;
}
public String getRegnumberofvendor() {
return regnumberofvendor;
}
public void setRegnumberofvendor(String regnumberofvendor) {
this.regnumberofvendor = regnumberofvendor;
}
public String getRemarks() {
return remarks;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public String getTaxes() {
return taxes;
}
public void setTaxes(String taxes) {
this.taxes = taxes;
}
public String getTenderauthority() {
return tenderauthority;
}
public void setTenderauthority(String tenderauthority) {
this.tenderauthority = tenderauthority;
}
public String getTenderpremium() {
return tenderpremium;
}
public void setTenderpremium(String tenderpremium) {
this.tenderpremium = tenderpremium;
}
public String getValidityofsecurdeposit() {
return validityofsecurdeposit;
}
public void setValidityofsecurdeposit(String validityofsecurdeposit) {
this.validityofsecurdeposit = validityofsecurdeposit;
}
public String getValueofcontract() {
return valueofcontract;
}
public void setValueofcontract(String valueofcontract) {
this.valueofcontract = valueofcontract;
}
public String getWorldbankapproval() {
return worldbankapproval;
}
public void setWorldbankapproval(String worldbankapproval) {
this.worldbankapproval = worldbankapproval;
}
public Date getDuedateofmeterialworks() {
return duedateofmeterialworks;
}
public void setDuedateofmeterialworks(Date duedateofmeterialworks) {
this.duedateofmeterialworks = duedateofmeterialworks;
}
public boolean isSearchCommTableEnabled() {
return searchCommTableEnabled;
}
public void setSearchCommTableEnabled(boolean searchCommTableEnabled) {
this.searchCommTableEnabled = searchCommTableEnabled;
}
public List<CommencementworkBean> getSearchCommencementBeanList() {
return searchCommencementBeanList;
}
public void setSearchCommencementBeanList(
List<CommencementworkBean> searchCommencementBeanList) {
this.searchCommencementBeanList = searchCommencementBeanList;
}
public String getFieldName() {
return fieldName;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
public String getHeaderName() {
return headerName;
}
public void setHeaderName(String headerName) {
this.headerName = headerName;
}
public String getValueName() {
return valueName;
}
public void setValueName(String valueName) {
this.valueName = valueName;
}
public String getStatusCode() {
return statusCode;
}
public void setStatusCode(String statusCode) {
this.statusCode = statusCode;
}
public Map<String, Object> getCommencementList() {
return commencementList;
}
public void setCommencementList(Map<String, Object> commencementList) {
this.commencementList = commencementList;
}
}
如何从选择列表中获取密钥和值。
异常
java.lang.String cannot be cast to xxx.xxx.xxx.bean.SelectionBean
java.lang.ClassCastException: java.lang.String cannot be cast to xxx.xxx.xxx.bean.SelectionBean
at org.gov.tnwrd.utils.PickListConvertor.getAsString(PickListConvertor.java:26)
at org.richfaces.component.util.InputUtils.getConvertedStringValue(InputUtils.java:96)
at org.richfaces.component.util.InputUtils.getConvertedStringValue(InputUtils.java:88)
at org.richfaces.renderkit.SelectHelper.generateClientSelectItem(SelectHelper.java:80)
at org.richfaces.renderkit.SelectManyHelper.getClientSelectItems(SelectManyHelper.java:254)
at org.richfaces.renderkit.SelectManyRendererBase.getClientSelectItems(SelectManyRendererBase.java:60)
at org.richfaces.renderkit.html.PickListRenderer.encodeEnd(PickListRenderer.java:202)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
at org.richfaces.renderkit.RendererBase.renderChildren(RendererBase.java:276)
at org.richfaces.renderkit.html.PanelRenderer.encodeEnd(PanelRenderer.java:181)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
at org.richfaces.renderkit.RendererBase.renderChildren(RendererBase.java:276)
at org.richfaces.renderkit.html.AjaxOutputPanelRenderer.encodeChildren(AjaxOutputPanelRenderer.java:57)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at org.richfaces.context.ExtendedPartialViewContextImpl$RenderVisitCallback.visit(ExtendedPartialViewContextImpl.java:504)
at org.richfaces.context.BaseExtendedVisitContext.invokeVisitCallback(BaseExtendedVisitContext.java:321)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1612)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at org.richfaces.component.AbstractTogglePanel.visitTree(AbstractTogglePanel.java:743)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIForm.visitTree(UIForm.java:371)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
at org.richfaces.context.ExtendedPartialViewContextImpl.processPartialRenderPhase(ExtendedPartialViewContextImpl.java:272)
at org.richfaces.context.ExtendedPartialViewContextImpl.processPartial(ExtendedPartialViewContextImpl.java:194)
at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:981)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:409)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
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:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)