9

Situation

JavaServer Faces Version: 2.1.6

I got a parent composite component with two nested cc. One of them contains a HtmlPanelGroup, which has a component binding. I use that binding to programmatically add HtmlCommandLink-Objects to the HtmlPanelGroup.

Let's call some IDs:

  • PARENT for the parent cc
  • CHILD_FIRST for the first child cc, nested in PARENT
  • CHILD_SECOND for the second child cc, nested in PARENT
  • GROUP for the PanelGroup, nested in CHILD_SECOND
  • LINK_1 for the first HtmlCommandLink-Object, progammatically added to GROUP

Expectation

I expect the following ID Chaining (with default javax.faces.SEPARATOR_CHAR):

PARENT (Composite Component, declarative)
  PARENT:CHILD_FIRST (Composite Component, declarative)
  PARENT:CHILD_SECOND (Component Component, declarative)
    PARENT:CHILD_SECOND:GROUP (HtmlPanelGroup, declarative)
      PARENT:CHILD_SECOND:GROUP:LINK_1 (HtmlCommandLink, programmatically)

Problem

The ID of the HtmlCommandLink-Object is wrong at the first page visit. Instead of "PARENT:CHILD_SECOND:GROUP:LINK_1" the ID is only "CHILD_SECOND:GROUP:LINK_1". After I refresh the page the ID is correctly "PARENT:CHILD_SECOND:GROUP:LINK_1". In fact every component in the second composite component ("CHILD_SECOND") is missing the first part of the ID ("PARENT"). After refresh all IDs are correctly.

Solution

I might automatically refresh the page after the first visit. But I don't want to.

4

1 回答 1

-2

浏览器解释后的 id 和你想的不一样。据我所知不超过3级。例如:

 <h:form id="form">
    <h:panel id="panel">
        <h:panel id="panel1">
            <h:label id="lab"/>
        </h:panel>
        <h:panel id="panel2">
        </h:panel>    
    </h:panel>
</h:form>

那么标签的 id 将不是 form:panel:panel1:lab 而是 form:panel:lab。如果您想要获取 id 的小部件更深,那么我无法判断,但它不会超过 3 个级别。我可以告诉你如何找到身份证。您可以只编写页面,然后在 chrome 或 firefox 上查看它,您可以在其中看到解释后的源代码。所以你可以得到你想要的id。

祝你好运!

于 2013-08-21T14:39:33.833 回答