在发布之前我确实已经花了相当长的时间,但我似乎并没有缩小到问题的根源。
我有这个“基本上”简单的代码,让我们说一旦我点击<p:commandButton>
,就会触发一个动作来填充要在<p:dataTable>
上调用的ArrayList。
我的<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();
}
现在我调试了这个方法,并且ArrayList listFields
已经很好了,我可以向你保证。
问题是,一旦我部署应用程序并单击<p:commandButton>
我得到java.lang.IllegalArgumentException
,我不知道JSF页面上的哪个组件没有收到正确的参数(顺便说一句,我知道它在JSF页面中,因为我得到了
SEVERE: Error Rendering View[/consult_carto.xhtml]
java.lang.IllegalArgumentException
)
我检查了安装员和吸气剂,他们看起来还不错。
我应该注意哪些迹象?
筹码:
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>
答案 0 :(得分: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
或数组,Iterable
或Map
的实例,而是完全不同且非法/不受支持的类型。
根据our selectOneMenu
wiki page相应地修正<h:selectOneMenu>
用法。
答案 1 :(得分:0)
您的问题似乎来自
<h:selectOneMenu value="#{car.field}" >
<f:selectItems value="#{car.field}"
var="man"
itemLabel="#{man}"
itemValue="#{man}" />
</h:selectOneMenu>
你可以查看'car.field'的价值。并删除ajax = false。