gpt4 book ai didi

jsf - 复合组件和ID

转载 作者:行者123 更新时间:2023-12-04 06:06:59 24 4
gpt4 key购买 nike

我想在我的JSF复合组件中实现一些Java cript,但是id却有问题。我的Java脚本具有:

document.getElementById("myForm:customerId")

不起作用,因为id错误。我有JSF复合组件:
<composite:implementation>
<div id="element_customer">
<h2 class="element_title">Customer</h2>
<h:form id="myForm">
<h:inputText id="customerId" value="#{cc.attrs.customerId}"/>
</h:form>
</div>
</composite:implementation>

HTML输出是:
<div id="element_customer">
<h2 class="element_title">Customer</h2>
<form id="j_idt44:myForm" name="j_idt44:myForm" method="post" ... >
<input type="hidden" name="j_idt44:myForm" value="j_idt44:myForm" />
<input id="j_idt44:myForm:customerId" ... name="j_idt44:myForm:customerId" />
</form>
</div>

为什么在HTML输出中使用“j_idt44”?

最佳答案

复合组件是 NamingContainer 组件,例如<h:form><h:dataTable>等。这使您可以在同一 View 中使用多个组件,而不会导致ID冲突。

您还需要给复合组件一个固定的ID。例如。

<my:composite id="someId" />

我也建议使用 <div id="#{cc.id}">而不是 <div id="element_customer">。然后,在上面的示例中它将变为 someId

与具体问题无关的,这并不是复合组件的正确目的。复合组件旨在具有相同的 <h:inputText>等等。您似乎宁愿想要标记文件,也可能想要包含文件。另请参阅 When to use <ui:include>, tag files, composite components and/or custom components?

关于jsf - 复合组件和ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10356993/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com