javax.faces.FacesException:目标模型类型不是集合或数组



提交JSF表单时,我收到以下异常:

Caused by: javax.faces.FacesException: Target model Type is no a Collection or Array 
    at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValuesForModel(MenuRenderer.java:388) [:2.0.3-] 
    at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValue(MenuRenderer.java:125) [:2.0.3-] 
    at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:311) [:2.0.3-] 
    at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1023) [:2.0.3-]     at javax.faces.component.UIInput.validate(UIInput.java:953) [:2.0.3-] 
    at javax.faces.component.UIInput.executeValidate(UIInput.java:1204) [:2.0.3-] 
    at javax.faces.component.UIInput.processValidators(UIInput.java:693) [:2.0.3-] 
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081) [:2.0.3-] 
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081) [:2.0.3-] 
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081) [:2.0.3-] 
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081) [:2.0.3-] 
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081) [:2.0.3-] 
    at javax.faces.component.UIForm.processValidators(UIForm.java:240) [:2.0.3-] 
    at org.ajax4jsf.component.AjaxViewRoot$3.invokeContextCallback(AjaxViewRoot.java:439) [:3.3.1.GA] 
    at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:238) [:3.3.1.GA] 
    at org.ajax4jsf.component.AjaxViewRoot.processValidators(AjaxViewRoot.java:455) [:3.3.1.GA] 
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:72) [:2.0.3-]   at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97) [:2.0.3-] 
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114) [:2.0.3-] 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308) [:2.0.3-]
    ... 42 more

这是如何造成的,我该如何解决?

javax.faces.FacesException: Target model Type is no a Collection or Array
    at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValuesForModel(MenuRenderer.java:388)

此异常表示视图中有一个UISelectMany组件,例如<h:selectManyMenu><h:selectManyListbox>其值绑定到集合或数组。这是不对的。它的值必须绑定到集合(如List<Entity>)或数组(如Entity[]),因为组件可以检索多个提交的值。

下面是一个启动示例,假设您使用的是String键入的项目,则正确<h:selectManyMenu>的外观:

<h:selectManyMenu value="#{bean.selectedItems}">
    <f:selectItems value="#{bean.availableItems}" />
</h:selectManyMenu>
<h:commandButton value="submit" action="#{bean.submit}" />

private List<String> selectedItems; // Note: List<String> and thus NOT String!
private List<String> availableItems;
@PostConstruct
public void init() {
    availableItems = Arrays.asList("one", "two", "three", "four", "five");
}
public void submit() {
    System.out.println("Selected items: " + selectedItems);
}

另请参阅:

  • 在JSF的情况下,如何从后端bean中的h:selectManyListbox获取所有选定的值?

我的解决方案是:我从<p:commandButton>标签的标签process中删除了属性"dtSubItem",一切正常。命令按钮正在提交事件上提交数据表。

处理第一个请求,但在第二个请求时,当填充数据表时,出现了错误。

<div class="ui-g-12 ui-md-6 ui-lg-2">
  <div class="espacoCampo">
      <p:outputLabel value=""  />  
          <p:commandButton  actionListener="#{managedBean.adicionarSubItemPanel(item)}"
                update="dtSubItem"
                title="Clique aqui para adicionar SubItem"
                icon="fa fa-plus"
                value="Adicionar"
                process="@this dtSubItem cadSubItens"
                iconPos="right"
                 >
      </p:commandButton>
    </div>
</div>
<p:dataTable var="subItem" id="dtSubItem" emptyMessage="Sem registros adicionados" value="#{item.btpResolucaoItemSubitemList}">
...
</p:dataTable>	

相关内容

  • 没有找到相关文章

最新更新