0

I am migrating application from JSF1.2/MyFaces+Facelets TO JSF2.1/MyFaces. I have following template which used to work with JSF1.2/MyFaces+Facelets.

<ui:component>
<f:subview id="#{id}">
.
.

<script
function blockLinkClicks(){
    //Disables all the HyperLink Controls to prevent repeated submits
    var allLinks = document.getElementById("#{id}:treeNodeForm").getElementsByTagName('a');
    var count = allLinks.length;
.
.
</script>
.
.
.
<h:form id="treeNodeForm">  
    <h:panelGroup id="treePanelId"> 
        <t:tree2 id="tree2Id" 
            value="#{treeBean.treeModel}" var="node" varNodeToggler="t"
            binding="#{treeBean.component}" clientSideToggle="false" showNav="false">
            <f:facet name="selectableNode">
                <h:panelGrid id="tree2PGridSelNodeId" columns="3" cellpadding="0" cellspacing="0" border="0">
.
.
.

After migration, I am getting the following error:

java.lang.IllegalStateException: component with duplicate id "mainLeftTree:treeNodeForm:tree2Id:tree2PGridSelNodeId" found at org.apache.myfaces.view.facelets.compiler.CheckDuplicateIdFaceletUtils.checkIds(CheckDuplicateIdFaceletUtils.java:100) at org.apache.myfaces.view.facelets.compiler.CheckDuplicateIdFaceletUtils.checkIds(CheckDuplicateIdFaceletUtils.java:116)

I have found similar questions here in SO but I was not able to relate the solutions, with my above issue. I have tried to find solution for many days/hours but could not.

Please help with your advice and pointers that I can try for a fix, as I am not sure if the issue is with f:subview or t:tree2 or jsf2 facelets.

Thank you very much in advance.

Regards, Kumar.

Kumar
  • 27
  • 1
  • 8

1 Answers1

1

I think the problem is caused by the use of <f:subview id="#{id}>", which obviously will break when PSS is enabled, because the EL is evaluated each time the view is built. Try first setting the web config parameter javax.faces.PARTIAL_STATE_SAVING to false. Or you can use the config parameter javax.faces.FULL_STATE_SAVING_VIEW_IDS to indicate which views needs full state saving. Maybe it is a good idea to avoid the EL in the id, and use other strategy in that part, but that could require some changes in the logic.

lu4242
  • 2,318
  • 1
  • 15
  • 15
  • Thanks very much for your time and excellent advices. Setting javax.faces.PARTIAL_STATE_SAVING to false, works. I am using subview and EL in more than 10 pages in the same above way. If possible, please help with strategy to avoid EL in the subview id. Is composite component is a alternate solution ? If yes, will I able to use Javascript in composite component definition as I used in my above code (ie., to get elements by id) ? – Kumar Jul 03 '12 at 12:15
  • 1
    I think wrap everything into a composite component is better. Instead use #{id}, you can use #{cc.clientId}, and with that change, you can enable PSS again. After all, one of the intentions behind composite components was replace facelets templating in cases like this one (but not in all cases). – lu4242 Jul 03 '12 at 12:46