2

在发布它之前我真的给了这个相当长的时间,但我似乎并没有缩小到问题的根源。

我有这个“基本上”简单的代码,让我们说,一旦我点击 a <p:commandButton>,就会触发一个动作来填充要在 a 上调​​用的 ArrayList <p:dataTable>

<p:commandButton>的是:

<p:commandButton value="Afficher" actionListener="#{fieldController.fillListFields()}" ajax="false"/>  

至于我的<p:dataTable>,是这样的:

<p:dataTable var="car" value="#{fieldController.listFields}" id="carList" editable="true">

#{fieldController.listFields}是一个#{fieldController.fillListFields()}必须负责填充的 ArrayList。的代码fillListFields()是:

public void fillListFields() throws NamingException, SQLException {

        InitialContext ctx = new InitialContext();
        DataSource ds = (DataSource) ctx.lookup("postgresJNDI");
        Connection connection = ds.getConnection();
        Statement st = connection.createStatement();
        ResultSet rs = st.executeQuery("SELECT * FROM " + consultCarto.getForm());


        ResultSetMetaData rsmd = rs.getMetaData();
        int columnCount = rsmd.getColumnCount();

        for (int i = 1; i < columnCount + 1; i++) {
            listFields.add(new Field(rsmd.getColumnName(i), ""));
        }

        rs.close();
        st.close();
        connection.close();

    }

现在我已经调试了这个方法并且 ArrayListlistFields被很好地填充了,我可以向你保证。问题是一旦我部署应用程序并单击<p:commandButton>我得到一个java.lang.IllegalArgumentException,我不知道 JSF 页面上的哪个组件没有收到正确的参数(顺便说一句,我知道它在 JSF 页面中,因为我得到了

SEVERE: Error Rendering View[/consult_carto.xhtml]
java.lang.IllegalArgumentException

)

我检查了 setter 和 getter,它们看起来还不错。

关于我应该看哪里的任何迹象?

堆栈:

java.lang.IllegalArgumentException
    at com.sun.faces.renderkit.SelectItemsIterator.initializeItems(SelectItemsIterator.java:216)
    at com.sun.faces.renderkit.SelectItemsIterator.hasNext(SelectItemsIterator.java:135)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:762)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:844)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:298)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
    at org.primefaces.component.celleditor.CellEditorRenderer.encodeEnd(CellEditorRenderer.java:43)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
    at org.primefaces.component.datatable.DataTableRenderer.encodeCell(DataTableRenderer.java:808)
    at org.primefaces.component.datatable.DataTableRenderer.encodeRow(DataTableRenderer.java:773)
    at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:651)
    at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:234)
    at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:196)
    at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:82)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeDynamicBody(PanelGridRenderer.java:92)
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeBody(PanelGridRenderer.java:60)
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:49)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeDynamicBody(PanelGridRenderer.java:92)
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeBody(PanelGridRenderer.java:60)
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:49)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)

Thanks. 

我的标记的重要部分:

<h:form id="form" style="font-size: 13px;">
            <p:panelGrid columns="2">
                <f:facet name="header">  
                    Consulter les données cartographiques 
                </f:facet>
                <p:panelGrid columns="1">
                    <p:panelGrid columns="2" style="width: 100%;text-align: center">
                        <p:outputPanel> 
                            <h:outputText value="Choisir un formulaire : " /> 
                            <br></br> 
                            <br></br> 
                            <p:selectOneMenu value="#{consultCarto.form}" >  
                                <f:selectItem itemLabel="Select One" itemValue="" />  
                                <f:selectItems value="#{consultCarto.forms}" />  
                            </p:selectOneMenu> 
                        </p:outputPanel> 
                        <p:commandButton value="Afficher" actionListener="#{fieldController.fillListFields()}" ajax="false"/>                        
                    </p:panelGrid> 
                    <!--  start of filter panel -->
                    <div id="filter_datatable" >
                        <p:dataTable var="car" value="#{fieldController.listFields}" id="carList" editable="true">
                            <f:facet name="header">
                                Requête 
                            </f:facet>

                            <p:ajax event="rowEdit" listener="#{fieldController.onEdit(event)}" />
                            <p:ajax event="rowEditCancel" listener="#{fieldController.onCancel(event)}" />

                            <p:column style="width:6%">
                            </p:column>


                            <p:column headerText="Champ" style="width:24%">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value="#{car.field}" />
                                    </f:facet>
                                    <f:facet name="input">
                                        <h:selectOneMenu value="#{car.field}" >
                                            <f:selectItems value="#{car.field}"
                                                           var="man" 
                                                           itemLabel="#{man}"
                                                           itemValue="#{man}" />
                                        </h:selectOneMenu>
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>
                            <p:column headerText="Valeur" style="width:20%">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value="#{car.value}" />
                                    </f:facet>
                                    <f:facet name="input">
                                        <p:inputText value="#{car.value}" style="width:100%" label="pseudo"/>
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>
                            <p:column style="width:6%">
                                <p:rowEditor />
                            </p:column>
                        </p:dataTable>
                        <p:commandButton value="Filtrer"/>
                    </div>
                    <!-- end of filter panel -->
                </p:panelGrid>
                <iframe name="iframe" src="carto.jsp" height="500" width="950" id="iframe"></iframe>
            </p:panelGrid> 
        </h:form>    
4

2 回答 2

3

答案就在堆栈跟踪中。

java.lang.IllegalArgumentException
    at com.sun.faces.renderkit.SelectItemsIterator.initializeItems(SelectItemsIterator.java:216)
    at com.sun.faces.renderkit.SelectItemsIterator.hasNext(SelectItemsIterator.java:135)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:762)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:844)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:298)

MenuRenderer用于<h:selectOneMenu>. 被SelectItemsIterator用于<f:selectItems>. 仅查看SelectItemsIterator堆栈跟踪中标识的第 216 行会很有帮助:

203            if (value != null) {
204                if (value instanceof SelectItem) {
205                    updateSingeItemIterator((SelectItem) value);
206                    items = singleItemIterator;
207                } else if (value.getClass().isArray()) {
208                    items = new ArrayIterator(ctx, (UISelectItems) kid, value);
209                } else if (value instanceof Iterable) {
210                    items = new IterableItemIterator(ctx,
211                                                     (UISelectItems) kid,
212                                                     (Iterable<?>) value);
213                } else if (value instanceof Map) {
214                    items = new MapIterator((Map) value);
215                } else {
216                    throw new IllegalArgumentException();
217                }
218            }

因此,这是由于<f:selectItems value>不是SelectItem, or 数组, or Iterableor的实例Map,而是完全不同且非法/不受支持的类型。

<h:selectOneMenu>根据我们的selectOneMenuwiki 页面相应地修复使用情况。

于 2013-06-10T13:43:18.980 回答
0

你的问题看起来像

<h:selectOneMenu value="#{car.field}" > <f:selectItems value="#{car.field}" var="man" itemLabel="#{man}" itemValue="#{man}" /> </h:selectOneMenu>

你能检查'car.field'的值吗?然后你删除 ajax=false。

于 2013-06-10T12:55:15.777 回答