所以我使用JSF开发了一个Web应用程序,并为我的按钮/文本输入字段提供了名称和ID。但是当我打开网页并执行Inspect Element时,我没有看到每个字段的相应名称/ ID。相反,我看到了这个:j_idtx:j_idty,其中x和y是一些数字,例如:j_idt2:j_idt5。
在使用JSP而不是JSF进行开发时,我没有看到这个问题。
以下是将按钮设置为特定名称的示例代码:
<ui:composition template="WEB-INF/templates/BasicTemplate.xhtml">
<ui:define name="content">
<h:form>
<h:commandButton action="login_page" value="Login" name="loginButton"></h:commandButton>
<br></br>
<br></br>
<h:commandButton action="registration_page" value="Register" name="registrationButton"></h:commandButton>
</h:form>
</ui:define>
</ui:composition>
那么如何确保我的姓名和ID正确显示?
由于
答案 0 :(得分:0)
如果未指定ID,则会自动生成。您确实指定了一个ID,但是您没有表单,因为这些元素是关闭子项的。因此,jsf生成的表单ID将自动添加到最终版本中的ID中,例如j_idt2:myid。
在表单中添加一个id,如果你想找到带有id的元素,你必须这样做:&#34; form:myid&#34;
像这样:
<h:form id="myform">
<h:inputText id="input"/>
</h:form>
输入的ID为:myform:input