MyFist
MyFist

Reputation: 413

How to get rid of the auto generated j_idt ID in composite component

I'm using below composite component:

<composite:interface>
    <composite:attribute name="inputId" />
</composite:interface>
<composite:implementation>
    <h:panelGrid id="myTableId">
        <h:inputText id="#{cc.attrs.inputId}" value="..." />
        ...
    </h:panelGrid>
</composite:implementation>

And I'm using it in my form as below:

<h:form id="myForm">
    <myCompositeComp:test inputId="myInputTextBoxId" />
<h:form>

I've verified the view source for the page and this is how it is generated:

<table id="myForm:j_idt90:myTableId">
    ...
    <input type="text" id="myForm:j_idt90:myInputTextBoxId" />
</table>

How can I get rid of j_idt90 here? Is it the id of my composite component? I read from one of BalusC post that this issue will get fixed if I declare id as static. But I'm not able to identify the place to declare it in my code. Also can I assume <h:panelGrid> is a kind of UINamingContainer?

Upvotes: 4

Views: 6198

Answers (1)

Robin
Robin

Reputation: 538

Yes it is the id of your composite component, <h:panelGrid> is not a UINaminContainer but the composite component is (it has to be, otherwise you would have duplicate IDs if you use it several times inside the same form for example).

Why do you need to get rid of the ID? You can set it yourself if that solves your problem:

<h:form id="myForm">
    <myCompositeComp:test id="myComp" attr1="" attr2="" />
<h:form>

the genereated html should look like this:

<table id="myForm:myComp:myTableId">
        ....
        <input type="text" id="myForm:myComp:myInputTextBoxId"
</table>

Upvotes: 7

Related Questions