inputCalendar forEach calling a exception

189 Views Asked by At

I'm receiving an exception with the code below.

<c:forEach var="calculoNotaUnidade" varStatus="counter" items="#{ configuracoesAva.calculoNotaUnidades }">
    <tr>
        <td>
            <t:inputCalendar id="${ counter.count }" value="#{ calculoNotaUnidade.dataFinalizacaoUnidade }" style="z-index:999;" popupButtonStyle="z-index:0;" renderAsPopup="true" renderPopupButtonAsImage="true" size="10" onkeypress="return (formataData(this,event));"  maxlength="10" title="Data de Finalização">
                <f:convertDateTime pattern="dd/MM/yyyy" />
            </t:inputCalendar>
        </td>
    </tr>
</c:forEach>

The exception is:

enter image description here

The exception it is called because my inputCalendar ID is wrong (and I don't know how to fix it).

When I don't put any ID, the page is loaded, but the inputCalendars doesn't work.

4

There are 4 best solutions below

2
Kukeltje On

I'm pretty sure your jstl c:foreach is not working looking at your stacktrace. Try to get that worling by e.g. looking at the namespace etc . And even if you do get it working, your ID's cannot start with a digit. Prepend them with an allowed prefix.

id="c_${counter.count}"

and try a # instead of an $

See also:

1
jaouad el aoud On

try this id="id_<c:out value="${counter.count}"/>"

3
Bonifacio On

JSF does not accept expression variable to set the ID. By the time that JSF prepares the HTML, it should already have the value available to generate the HTML, which is obviously not this case.

BTW, you shouldn't need to include the ID manually to set the index. JSF will do it automatically for you, for example this snippet:

<ui:repeat id="test" value="#{bean.collection}" var="item">
    <p:inputText id"testInput" value="#{bean.inputValue}"/>
</ui:repeat>

The HTML generated will be like this (assuming that the variable bean.collection has 3 records):

<input id="id:0:testInput"></input>
<input id="id:1:testInput"></input>
<input id="id:2:testInput"></input>

As you can see, the index is already appended to the HTML id, so this means that you actually does not need the logic you are trying to apply, because JSF does this automatically for you.

0
Subodh Joshi On

Here are the code what we r doing to generate the id dynamically and we never faced any issue

<c:forEach items="#{linkCreationBean.editLinkVO.genericFeaturesList}"
    var="genFeatCapacity" varStatus="genericFeatCapIndex">
    <h:outputText value="#{genFeatCapacity.label}"
        id="sub_#{genericFeatCapIndex.index}_equip" />
    <h:outputText value="" rendered="#{!genFeatCapacity.required}" />
    <c:if test="#{genFeatCapacity.enumValues.size() gt 0}">
        <h:selectOneMenu id="select_#{genericFeatCapIndex.index}_onemenu_sub"
            value="#{genFeatCapacity.value}">
        </h:selectOneMenu>
    </c:if>
</c:forEach>