Question

When doing the firstcup-war tutorial for Java EE http://docs.oracle.com/javaee/7/firstcup/doc/web-application005.htm The error message is not shown because it cannot select the right html element. I have the following code:

    <fc:inputDate id="userBirthday" date="#{dukesBDay.yourBD}" />
      <h:outputText value=" #{bundle.Pattern}"/>
      <p/>
      <h:commandButton value="#{bundle.Submit}" action="#{dukesBDay.processBirthday}"/>
      <p/>
      <h:message for="userBirthday" style="color:red"/>

When looking at the source code in the browser I see that the name tag is actually "j_idt6:userBirthday:j_idt16". So if I change the last line of the above posted code to:

        <h:message for="j_idt6:userBirthday:j_idt16" style="color:red"/>

It works again. Why does Java EE append j_idt6 and j_idt16 at the beginning and end of the name tag. And Why is the code in the tutorial not working. What can I do to make it work, without having to check the source code, what the actual tag name looks like.

Était-ce utile?

La solution

The final ID for the inputDate will be generated in the following format: formID:ComponentId:InternalComponentId

Your form has no ID, so that a unique id will be generated.
Your inputDate component has the ID "userBirthday".
Your internal inputText has no ID, so that a unique id will be generated.

But you can avoid this by defining IDs for each component.

inputDate.xhtml:
<h:inputText id="inputDateId" value="#{cc.attrs.date}">

greeting.xhtml:
<h:form id="greetingFormId"> ... <fc:inputDate id="userBirthdayId" date="#{dukesBDay.yourBD}" /> ... <h:message for="greetingFormId:userBirthdayId:inputDateId" style="color:red"/>

Then you will get an error message like the following:

greetingFormId:userBirthdayId:inputDateId: '23.12.2001' konnte nicht als Datum interpretiert werden. Beispiel: 05/06/2014

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top