Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Duplicate ID exception when using composite component with c:if #4244
I have a duplicate ID exception when using a composite component two times at same page.
I already asked at stackoverflow but got no answer:
Below the reproducer code:
A session scoped Bean: TestBean
A simple composite component: testCmp
A using page which allows switching between hide/show this component
When i switch between hide/show i get the exception:
I tested with 2.2.14 and 2.3.0-m11
My explanation of this is, having 2 components of type "mycomposite", the first composite with conditional rendering c:if, the c:if puts some kind of flag in the view like "render" that affects all components it finds of type "mycomposite" it finds afterwards, therefore, "mycomposite2" gets re-rendered. The "scope" of the "flag" is wrong.
If you move the c:if to the second composite, it works fine as the first composite was evaluated before the c:if sets the "flag".
I'm still waiting for a fix. I tried to figure out a solution myself, but the code appeared to be a bit too complex for me to understand. Some documentation about the internals of Mojarra would have been useful, but I couldn't find anything besides the source code itself.
I've been looking to this issue and the problem is related to how the internal IDs are calculated in mojarra. In the example:
1.- The first time the c:if is evaluated to false and only one composite is created "test2":
2.- When you click the show link, the c:if is true and therefore two composites appear ("test1" and "test2"). The first one is:
You see the MARK_ID is exactly the same as in point 1. The IDs are assigned using the composite hierarchy (only one here) and the tag. When there are more than one a number suffix is added (see later). Here because the "test1" is the first composite being evaluated it receives the same ID "test2" received in the previous request: "-1950651219_36361211".
3.- When the JSF implementation reaches the "test2" composite the HtmlOutputComponent received the ID "-1950651219_1_36361211_1" because there is already one with the same ID and the suffix is incremented (I mean, because "test1" exists, "test2" components get a "_1" suffix). But the previous value remains and it finally finishes with a duplicated component:
You see that the HtmlOutputComponent is duplicated, one is the old component (the rendered in the previous request) and the other is the new one (calculated this request). The problem is related to how the component IDs are calculated and not marking to delete composite children. I have a little patch you can test and I'm going to put in a second comment.
I have prepared a little change over 2.2.14 tag that does the marking and the deletion commented before. I have just test it against the mojarra automated test on version 2.2.14 and it passes all of them (but nothing more).
Please, consider this patch or a similar solution, but clearly this is a BUG cos this issue makes absolutely incompatible composites with JSTL that changes the component tree (c:if in this example).
Thanks in advance!
This was referenced
Jun 12, 2017
@xinyuan-zhang thank you for quick reply.
I am not sure it is fixed. I have very simple app with following page and composite and it is still not working with mojarra 2.2.14 (Myfaces works)
Hi @arjantijms ,
Hi @martin654 ,