tags:

views:

33

answers:

1

Hi,

I've been literally struggling with this, although there are tons of tutorials on the topic. I'm testing the functionality of the h:dataTable component in JSF 2.0. I have the following list:

        <h:dataTable border="1" styleClass="data zebra" value="#{testTableWB.testList}" var="items">   
            <h:column>
              <f:facet name="header">
               <h:outputText  value="id"/>
              </f:facet>
               <h:outputText value="#{items.id}"/>
            </h:column>

            <h:column>
                <f:facet name="header">
            <h:outputText  value="name"/>
                </f:facet>
            <h:outputText value="#{items.name}"/>
            </h:column>
            <h:column>
              <f:facet name="header">
                <h:outputText  value="description"/>
              </f:facet>
               <h:outputText value="#{items.description}"/>
            </h:column>
            <h:column>
              <f:facet name="header">
              </f:facet>
                <h:selectManyCheckbox id="ids" value="#{items.id}">
                    <f:selectItem value="#{ids}" itemLabel="" />
                </h:selectManyCheckbox>
            </h:column>
            <h:column>
              <f:facet name="header">
              </f:facet>
                <h:commandLink action="testTableWB.someStupidAction" value="Edit">
                    <f:param id="itemIDEdit" value="items.id"/>
                </h:commandLink>
            </h:column>
            <h:column>
              <f:facet name="header">
              </f:facet>
                <h:commandLink action="testTableWB.someStupidAction" value="Show">
                    <f:param id="itemIDShow" value="items.id"/>
                </h:commandLink>
            </h:column>             
        </h:dataTable> 

My Managed Bean looks like this:

@ManagedBean(name="testTableWB") @RequestScoped public class TestTableWBR extends VerificationWBR {

private List<TestElement> testList;

public List<TestElement> getTestList() {
    testList = new ArrayList<TestElement>();

    for (int i=0; i<5;i++){
        testList.add(new TestElement(new Long(i),"name"+i, "descrition"+i));
    }

    testList.add(new TestElement(10L,"mark", "test element"));

    return this.testList;
}

public void setTestList(List<TestElement> pTestList) {
    this.testList = pTestList;
}

public void someStupidAction(){
    String parameter =  FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("itemIDEdit");

}

So when I click on one of the command links - Edit or Show, I'm expecting the action to be called and I'm having a breakpoint there. Instead I get an error : Target model Type is no a Collection or Array and the following stacktrace:

    javax.faces.FacesException: Target model Type is no a Collection or Array
    at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValuesForModel(MenuRenderer.java:390)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValue(MenuRenderer.java:127)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:313)
    at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1008)
    at javax.faces.component.UIInput.validate(UIInput.java:934)
    at javax.faces.component.UIInput.executeValidate(UIInput.java:1189)
    at javax.faces.component.UIInput.processValidators(UIInput.java:691)
    at javax.faces.component.UIData.iterate(UIData.java:1424)
    at javax.faces.component.UIData.processValidators(UIData.java:1015)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
    at javax.faces.component.UIForm.processValidators(UIForm.java:243)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1080)
    at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1179)
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:310)
    at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:333)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at com.bmw.verdict.web.fupload.UploadFilter.doFilter(UploadFilter.java:70)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:313)
    at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1093)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
    at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1093)
    at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:291)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:666)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:597)
    at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:872)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
    at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
    at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:382)
    at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:264)
    at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)

According to the documentation the dataTable component should work with the List data type. I'm not getting to the managed bean at all, so I guess something goes wrong before that in the life cycle. So where am I going wrong here? Thanks for the help in advance.

Regards, al

+1  A: 

OK, solved. Used secletBooleanCheckBox instead.

al
Indeed, the exception is basically telling you that a `value` of a h:selectManyCheckbox isn't a `List<T>` or a `T[]` while it is the expected value type. But you're actually not after this, just a `boolean` property.
BalusC