【问题标题】:Java EE tutorial, cannot access "userBirthday" input DateJava EE 教程,无法访问“userBirthday”输入日期
【发布时间】:2014-03-24 23:09:44
【问题描述】:

在为 Java EE http://docs.oracle.com/javaee/7/firstcup/doc/web-application005.htm 进行 firstcup-war 教程时,由于无法选择正确的 html 元素,因此未显示错误消息。我有以下代码:

    <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"/>

在浏览器中查看源代码时,我发现名称标签实际上是“j_idt6:userBirthday:j_idt16”。因此,如果我将上面发布的代码的最后一行更改为:

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

它再次工作。为什么Java EE 在名称标签的开头和结尾处附加j_idt6j_idt16。以及为什么教程中的代码不起作用。我该怎么做才能让它工作,而不必检查源代码,实际的标签名称是什么样的。

【问题讨论】:

    标签: java html reference enterprise


    【解决方案1】:

    inputDate 的最终 ID 将按以下格式生成:formID:ComponentId:InternalComponentId

    您的表单没有ID,因此会生成一个唯一的ID。
    您的 inputDate 组件的 ID 为 "userBirthday"
    您的内部 inputText 没有无 ID,因此将生成一个唯一的 ID。

    但您可以通过为每个组件定义 ID 来避免这种情况。

    inputDate.xhtml:
    &lt;h:inputText id="inputDateId" value="#{cc.attrs.date}"&gt;

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

    然后你会得到如下错误信息:

    greetingFormId:userBirthdayId:inputDateId: '23.12.2001' konnte nicht als Datum interpretiert werden。新闻:05/06/2014

    【讨论】:

      猜你喜欢
      • 2016-10-13
      • 2020-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-09
      • 2018-09-04
      • 2013-10-29
      • 1970-01-01
      相关资源
      最近更新 更多