工作:这是我的工作丰富:当 sourceValue 和目标值是字符串列表时的 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. 支持豆
//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. Backing 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}": Property 'jurisdictionList' not writable on type java.util.List), detail=(javax.el.PropertyNotFoundException: /html/workcase/type/dmp/admin/AddCompany.xhtml @55,98 sourceValue="#{companyAdminAction.jurisdictionList}": Property 'jurisdictionList' not writable on type 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>