简体   繁体   English

JSF复合组件ID

[英]JSF Composite component ID

I created a JSF composite component to extend h:inputBox 我创建了一个JSF复合组件来扩展h:inputBox

        <p class="label clear">
            <label for="#{cc.attrs.id}" class="">
                #{cc.attrs.label}:
            </label>
        </p>
        <p>
            <h:inputText id="#{cc.attrs.id}" value="#{cc.attrs.value}" 
                size="#{cc.attrs.size}" />
            <ui:fragment rendered="#{cc.attrs.optional eq 'optional'}">
                <span class="optional">Optional</span>
            </ui:fragment>
        </p>

To use this component.. 要使用此组件..

<my:inputText id="firstName" label="First Name" value="#{nameTO.firstName}"/>

When this component is rendered on the browser, the ID is of the format "firstName:firstName". 在浏览器上呈现此组件时,ID的格式为“firstName:firstName”。

<input type="text" value="" name="firstName:firstName" id="firstName:firstName" gtbfieldid="3028">

Is this a standard naming convention with JSF 2.0 templates? 这是JSF 2.0模板的标准命名约定吗? I did not get this with JSF 1.2 Facelets templates. 我没有用JSF 1.2 Facelets模板获得这个。 Is there any way to generate the ID as just "firstName" instead of "firstName:firstName" 有没有办法生成ID只是“firstName”而不是“firstName:firstName”

A JSF 2.0 composite component is not the same as a JSF 1.x/2.x Facelets template. JSF 2.0复合组件与JSF 1.x / 2.x Facelets模板不同。

The composite component has its own ID as well. 复合组件也有自己的ID。 You're basically reusing it on the components in the implementation of the composite component. 您基本上是在复合组件实现中的组件上重用它。 You may want to consider to add or rename another ID attribute for the components in the implementation. 您可能需要考虑为实现中的组件添加或重命名另一个ID属性。 Eg 例如

<my:inputText name="firstName" label="First Name" value="#{nameTO.firstName}" />

with

<h:inputText id="#{cc.attrs.name}">

It'll however end up as id="ccId:firstName" in HTML where ccId is either the fixed or autogenerated id of my:inputText . 然而,它最终会在HTML中以id="ccId:firstName" ,其中ccIdmy:inputText的固定或自动生成的id You can also just leave it away and use 你也可以把它留下来使用

<h:inputText id="input">

Which ends up as id="firstName:input" in HTML. 最终在HTML中以id="firstName:input"结尾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM