gpt4 book ai didi

java - 丰富 :listShuttle error when using complex object

转载 作者:太空宇宙 更新时间:2023-11-04 08:10:44 24 4
gpt4 key购买 nike

工作中:这是我的工作 rich:listShuttle 当源值和目标值是字符串列表时。

<强>1。 JSF 页面

<rich:listShuttle id="companyJurisdictionShutle"
sourceValue="#{companyAdminAction.statesList}"
targetValue="#{companyAdminAction.selectedStates}"
var="item" orderControlsVisible="false" fastOrderControlsVisible="false"
sourceCaptionLabel="Available"
targetCaptionLabel="Selected" styleClass="lishShuttle">
<rich:column>
#{item}
</rich:column>
</rich:listShuttle>

<强>2。支持 bean

//sourceValue                    
public List<String> getStatesList() {

for (DMPJurisdiction dmpJurisdiction: jurisdictionList) {
if(!statesList.contains(dmpJurisdiction.getJurisName())) {
statesList.add(dmpJurisdiction.getJurisName());
}
}
return statesList;
}

//targetValue
public List<String> getSelectedStates() {
return selectedStates;
}

<强>3。值对象

public class DMPJurisdiction implements Serializable {

/** serial version UID **/
private final static Long serialVersionUID = 109892748283726L;

/** jurisdiction id **/
private Long jurisId;

/** name **/
private String jurisName;

/** description **/
private String jurisDescription;

/** code **/
private String jurisCode;

//Getters and Setters

}

不工作:我更改了列表穿梭,以便 sourceValue 和 targetValue 是复杂对象 (DMPJurisdiction) 的列表,而不是像以前那样的字符串列表。我为此编写了一个转换器。

<强>1。 JSF 页面

<rich:listShuttle id="companyJurisdictionShutle"
sourceValue="#{companyAdminAction.jurisdictionList}"
targetValue="#{companyAdminAction.targetJurisdictionList}"
converter="#{dmpJurisdictionConverter}"
var="item" orderControlsVisible="false" fastOrderControlsVisible="false"
sourceCaptionLabel="Available"
targetCaptionLabel="Selected" styleClass="lishShuttle">
<rich:column>
#{item.jurisName}
</rich:column>
</rich:listShuttle>

<强>2。支持 Bean:现在返回上面列出的复杂对象 DMPJurisdiction 的列表。

//sourceValue
public List<DMPJurisdiction> getJurisdictionList() {
return jurisdictionList;
}

//targetValue
public List<DMPJurisdiction> getTargetJurisdictionList() {
return targetJurisdictionList;
}

<强>3。转换器

public class DmpJurisdictionConverter implements javax.faces.convert.Converter {

public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) {
List<DMPJurisdiction> dmpJurisdictionList = Cache.loadAllDmpJurisdictions();
for (DMPJurisdiction dmpJurisdiction : dmpJurisdictionList) {
if (dmpJurisdiction.getJurisName().equals(s)) {
return dmpJurisdiction;
}
}
return null;
}

public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object o) {
List<DMPJurisdiction> dmpJurisdictionList = Cache.loadAllDmpJurisdictions();
for (DMPJurisdiction dmpJurisdiction : dmpJurisdictionList) {
if (((DMPJurisdiction) o).getJurisName().equals(dmpJurisdiction.getJurisName())) {
return dmpJurisdiction.getJurisName();
}
}
return null;
}

}

<强>4。错误: sourceId=accountWorkcaseOpenTabForm:addDmpCompanySubview:companyJurisdictionShutle[severity=(ERROR 2),summary=(javax.el.PropertyNotFoundException:/html/workcase/type/dmp/admin/AddCompany.xhtml @55,98 sourceValue="#{companyAdminAction.jurisdictionList}":属性“jurisdictionList”不可写在类型 java.util.List 上),detail=(javax.el.PropertyNotFoundException:/html/workcase/type/dmp/admin/AddCompany.xhtml @55,98 sourceValue="#{companyAdminAction.jurisdictionList}": 属性“jurisdictionList”在类型 java.util.List 上不可写)] ||||

注意:只是附注,我成功地为 selectOneMenu 使用了相同的 dmpJurisdictionConverter,如下所示,在不同的不相关 JSF 页面中。

<h:selectOneMenu value="#{companyAdminAction.dmpJurisdiction}" converter="#{dmpJurisdictionConverter}">
<s:selectItems var="item" value="#{companyAdminAction.jurisdictionList}" label="#{item.jurisName}"
hideNoSelectionLabel="true" noSelectionLabel="-- Select Jurisdiction --"/>
<a4j:support event="onchange" action="#{companyAdminAction.loadCompanyList()}"
reRender="dmpCompanies"/>
</h:selectOneMenu>

最佳答案

您可以使用接缝标签“<”s:convertEntity/>

它会自动进行转换,但复杂对象必须是实体

关于java - 丰富 :listShuttle error when using complex object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11267180/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com