复合组件和ID [英] Composite components & ID

查看:151
本文介绍了复合组件和ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to implement some javas cript into my JSF composite component, but I have problem with id. My java script with:

document.getElementById("myForm:customerId")

不起作用,因为ID错误.我有JSF复合组件:

does not work, because the id is wrong. I have JSF composite component:

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

Why is "j_idt44" used in HTML output?

推荐答案

复合组件是

Composite components are NamingContainer components like <h:form>, <h:dataTable>, etc. This allows you to have multiple of them in the same view without conflicting IDs.

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

You need to give the composite component a fixed ID as well. E.g.

<my:composite id="someId" />

我也建议使用<div id="#{cc.id}">代替<div id="element_customer">.在上面的示例中,它将变为someId.

I'd also suggest to use <div id="#{cc.id}"> instead of <div id="element_customer">. It will then become someId with the above example.

无关与具体问题无关,这并不是复合组件的正确目的.复合组件的用途与<h:inputText>相同,以此类推.您似乎更希望使用标记文件或包含文件.另请参见何时使用< ui :include> ;、标记文件,复合组件和/或自定义组件?

Unrelated to the concrete problem, this isn't entirely the right purpose of a composite component. A composite component is intented to be of the same kind of <h:inputText>, etc. You seem to rather want a tag file or maybe an include file. See also When to use <ui:include>, tag files, composite components and/or custom components?

这篇关于复合组件和ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆