0

It's my first post here, so be critical for my question, let me know if i ask it wrong way.

The problem is that I want to make <h:inputText> inside a <c:forEach> loop. The fields should get values to store in a bean's property, which is an array of Integers.

When I use it without loop, as below, it works very well. mac is a bean representing a matrix. el is an array that represents nine elements of the matrix.

<table>
    <tr>
        <td><h:inputText value="#{mac.el[0]}" /></td>
        <td><h:inputText value="#{mac.el[1]}" /></td>
        <td><h:inputText value="#{mac.el[2]}" /></td>
    </tr>
    <tr>
        <td><h:inputText value="#{mac.el[3]}" /></td>
        <td><h:inputText value="#{mac.el[4]}" /></td>
        <td><h:inputText value="#{mac.el[5]}" /></td>
    </tr>
    <tr>
        <td><h:inputText value="#{mac.el[6]}" /></td>
        <td><h:inputText value="#{mac.el[7]}" /></td>
        <td><h:inputText value="#{mac.el[8]}" /></td>
    </tr>
</table>

However, when i wrap it up with a loop, as below, it doesn't.

<table>
<c:forEach items="#{mac.el}" varStatus="loop">
  <c:if test="${loop.index%3==0}"><tr></c:if>
  <td>
  <h:inputText value="#{mac.el[loop.index]}" />
  </td>
  <c:if test="${loop.index%3==2}"></tr></c:if>
</c:forEach>
</table>

At first, i had an casting exception, but found a question where I found out that I should use Integer[] instead of int[]. Now it throws IllegalArgumentException, but at least it works without the loop.

java.lang.IllegalArgumentException
    at javax.el.ArrayELResolver.toInteger(ArrayELResolver.java:339)
    at javax.el.ArrayELResolver.getType(ArrayELResolver.java:108)
    at com.sun.faces.el.DemuxCompositeELResolver._getType(DemuxCompositeELResolver.java:220)
    at com.sun.faces.el.DemuxCompositeELResolver.getType(DemuxCompositeELResolver.java:248)
    at com.sun.el.parser.AstValue.getType(AstValue.java:91)
    at com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:201)
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
    at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1122)
    at javax.faces.component.UIInput.validate(UIInput.java:1030)
    at javax.faces.component.UIInput.executeValidate(UIInput.java:1334)
    at javax.faces.component.UIInput.processValidators(UIInput.java:757)
    at javax.faces.component.UIForm.processValidators(UIForm.java:269)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1298)
    at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1332)
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:77)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:201)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:670)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1540)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:119)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:611)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:550)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:114)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:199)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:463)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:168)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:242)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:539)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
    at java.lang.Thread.run(Thread.java:748)
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

0

The JSTL c:forEach is a tag handler and is invoked during view build time. This causes issues with JSF since it renders its components during render response. Don't mix them.

You can resolve your problem by using ui:repeat.

You can check the answer of this question for a much better explanation.

raupach
  • 3,092
  • 22
  • 30
  • Hi, thanks for reply. Now i understand why it doesn't work, although [here](https://stackoverflow.com/questions/13634102/dynamic-hinputtext-to-backing-bean-array-in-jsf-classcastexception/13634311#13634311?newreg=6b5d91ee587d446bb400be24e04e1b06) they say it can be used this way. Another problem is, that I'm not able to include `ui` taglib in my JSP (I get: "PWC6188: The absolute uri: http://java.sun.com/jsf/facelets cannot be resolved in either web.xml or the jar files deployed with this application"). Is there any way to include `ui` in my jsp page? – DeeJayMefju Dec 21 '20 at 19:00