New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duplicate ID exception when using composite component with c:if #4244
Comments
@javaserverfaces Commented |
@javaserverfaces Commented 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". |
@javaserverfaces Commented See:
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. |
@javaserverfaces Commented 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. |
@javaserverfaces Commented 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! |
@javaserverfaces Commented I'll have to setup a build environment for Mojarra and try your patch ... and understand how it works. |
@javaserverfaces Commented jsf-ri/src/main/java/com/sun/faces/facelets/tag/jsf/ComponentSupport.java | 24 +++++++++++++++++++----- |
@javaserverfaces Commented |
@arjantijms Commented Gave this a brief glance with @BalusC and it looks like the following check is missing for the new delete case:
Was that intentional or just forgotten? |
@martin654 Commented |
@xinyuan-zhang Commented |
@jensberke Commented |
@xinyuan-zhang Commented |
@martin654 Commented 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) Page:
Composite:
Bean:
|
@jensberke Commented |
@jensberke Commented |
@martin654 Commented |
@martin654 Commented I tested version 2.2.8-22 in my example and it works. I do not see the changes from 2.2.8-22 in the 2.2.14 version. It seems to me that it could be merged into 2.2.15... |
@arjantijms Commented That change set is indeed in the 2_2 rolling branch and done a good while after 2.2.14 was released, so obviously it's not in 2.2.14. @xinyuan-zhang @ren-zhijun-oracle It's probably high time to do a 2.2.15 release cut as well. What do you think? |
@xinyuan-zhang Commented Hi @martin654 , |
@arjantijms Commented |
@xinyuan-zhang Commented |
@jensberke Commented |
@martin654 Commented |
|
I have a duplicate ID exception when using a composite component two times at same page.
Both components have different IDs.
One component is conditionally rendered with <c:if>, the other one isn't
I don't have this exception when doing exactly the same thing but using a plain JSF component instead.
I already asked at stackoverflow but got no answer:
http://stackoverflow.com/questions/42863043/duplicate-id-exception-when-using-cif-with-composite-component
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:
"Component ID testForm:test2:text has already been found in the view"
When i don't use a composite component but a plain JSF component like e.g. <h:outputText> anything works well.
I tested with 2.2.14 and 2.3.0-m11
Affected Versions
[2.2.14, 2.3.0-m10]
The text was updated successfully, but these errors were encountered: