-2

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.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
FabianoLothor
  • 2,752
  • 4
  • 25
  • 39

4 Answers4

0

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:

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • Using `#` java.lang.IllegalArgumentException: c_#{ counter.count } at javax.faces.component.UIComponentBase.validateId(UIComponentBase.java:555) at javax.faces.component.UIComponentBase.setId(UIComponentBase.java:351) at javax.faces.webapp.UIComponentTag.createComponent(UIComponentTag.java:219) at – FabianoLothor Jul 19 '18 at 16:58
  • Well, I thought the error was sort of not completely right, but maybe inputCalendar just does not accept EL at all like the error states. – Kukeltje Jul 19 '18 at 18:43
0

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

0

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.

Bonifacio
  • 1,482
  • 10
  • 19
  • Wrong, jsf allows an id to be set IF you do it view create via jstl – Kukeltje Jul 25 '18 at 18:56
  • The stacktrace says otherwise, let's wait for OP response – Bonifacio Jul 25 '18 at 19:04
  • That might be because of this component or maybe even that the jstl does not work and the EL is evaluated rendertime. And for JSF in general, including PrimeFaces, you can set an id via jstl at view create time, believe me, I use it in production. And see https://stackoverflow.com/questions/9147771/how-can-i-set-id-of-a-component-tag-inside-uirepeat – Kukeltje Jul 25 '18 at 20:56
0

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>
Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202