gpt4 book ai didi

jsf - selectItems java.lang.IllegalArgumentException

转载 作者:行者123 更新时间:2023-12-04 04:54:08 26 4
gpt4 key购买 nike

在发布之前,我真的花了很长时间,但我似乎并没有缩小到问题的根源。

我有这个“基本上”简单的代码,让我们说一旦我点击了 <p:commandButton> , 一个 Action 被触发来填充一个要在 <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

)

我检查了 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>

最佳答案

答案就在堆栈跟踪中。

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 的实例,或数组,或 IterableMap ,但完全不同且非法/不受支持的类型。

修复 <h:selectOneMenu>相应的用法基于 our selectOneMenu wiki page .

关于jsf - selectItems java.lang.IllegalArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17014942/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com