myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sasha Maksimenko <sasha.maksime...@gmail.com>
Subject Custom component in faceltes
Date Thu, 14 Aug 2014 15:09:11 GMT
hi!
I'm using myfaces 2.1.15

First of all I apologize for many details but I already simplified use 
case as much as possible.

I have problem when I try to use custom components with facelets tpgeather.
My custom component is quite simple, it just adds label inside itself

@FacesComponent("UISearchFormComponent")
public class UIForm extends UINamingContainer {
     private Integer columns;

     public Integer getColumns() {
         return columns;
     }

     public void setColumns(Integer columns) {
         this.columns = columns;
         if (getChildCount() == 0) {
             UIOutput component1 = new UIOutput();
             getChildren().add(component1);
             component1.setValue("custom label");
             component1.setId("customLabelId");
         }
     }
}

Now I have placed it inside simple facet page. This page contains 2 
command links and include. When user clicks on "a1" link then property 
testComponent.name="a1.xhtml" and it's content is included. If user 
clicks on "a2" link then testComponent.name="a2.xhtml" content is 
displayed. A2.xhtml contains my custom component and button "refresh" 
which refreshes common form

index.html:
     <p:form id="form">
         <p:commandLink action="#{testComponent.chooseA1}" value="a1" />
         <br/>
         <p:commandLink action="#{testComponent.chooseA2}" value="a2" />
         <br/>
         <ui:include src="#{testComponent.name}"/>
     </p:form>

a1.html:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:ui="http://java.sun.com/jsf/facelets"
                 xmlns:h="http://java.sun.com/jsf/html">
     <h:outputLabel value="a1"/>
</ui:composition>

a2.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:ui="http://java.sun.com/jsf/facelets"
                 xmlns:h="http://java.sun.com/jsf/html"
                 xmlns:p="http://primefaces.org/ui"
                 xmlns:iscu="http://infosynergi.com/iscustomer">
     <h:outputLabel value="a2"/>
     <iscu:searchForm columns="1"/>
     <p:commandButton value="refresh" update="form"/>
</ui:composition>


So what I have done:
1) open index.xhtml
2) click on a2 link and then to refresh button. label "custom label" is 
displayed
3) click on a1 link
4) click on a2 link again. label "custom label" is still displayed
5) click on refresh button again and label "custom label" disappears


I debugged this and what I can find out. At step
2)
DefaultFaceletsStateManagementStrategy.PostAddPreRemoveFromViewListener.handleEvent 
was called. And "Custom label" was added to  getClientIdsRemoved
      List<String> clientIdsRemoved = getClientIdsRemoved(uiViewRoot);
         ..
clientIdsRemoved.add(component.getClientId(_facesContext));
                 setClientsIdsRemoved(uiViewRoot, clientIdsRemoved);

This clientIdsRemoved list is checked everytime on restorestate phase 
and all components with clientid are contained in this list are removed 
(method : 
DefaultFaceletsStateManagementStrategy.handleDynamicAddedRemovedComponents)
So even after component "custom label" was added to component tree again 
it's deleted by this method.

So my question is why getClientIdsRemoved is stored between requests and 
what should I do to workaround this

Mime
View raw message