rich:使用复杂对象时出现listShuttle错误

时间:2012-06-29 18:35:20

标签: java jsf seam

工作:这是我的工作富:listShuttle,当sourceValue和目标值是字符串列表时。

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

} 

NOT-WORKING:我更改了列表穿梭,因此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>

2 个答案:

答案 0 :(得分:1)

你可以使用seam标签“&lt;”s:convertEntity /&gt;

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

答案 1 :(得分:0)

我正在使用其getter getStatesList 加载sourceValue =“#{companyAdminAction.statesList}”。应该单独加载,在页面渲染时多次调用coz getter和setter。我不得不将加载statesList移动​​到bean初始化期间调用的另一个私有方法。

相关问题