3 Replies Latest reply on Jan 20, 2009 4:45 PM by Francisco Jose Peredo Noguez

    ScopeType.COMPONENT: How to emulate it before JSF 2.0?

    Francisco Jose Peredo Noguez Master

      We do not have it (pdf)... but if we had a ScopeType.COMPONENT that we could place a single component multiple times at various places around the page (it seems that we might have something like that in JSF 2.0.


      But right now, how do you deal with this? In my case, I modified the EntityList generated by seam-gen to be re-usable inside a modal panel:


      <rich:modalPanel id="modalPanelEmpleadoList" width="640" height="480">           
                        <f:facet name="header">
                            <h:panelGroup>
                                <h:outputText value="Seleccionar empleado"></h:outputText>
                            </h:panelGroup>
                        </f:facet>
                        <f:facet name="controls">             
                            <h:panelGroup>                                                  
                                <h:outputText value="X" style="cursor:pointer" id="hidelinkEmpleado"></h:outputText>
                                <rich:componentControl for="modalPanelEmpleadoList" attachTo="hidelinkEmpleado" operation="hide" event="onclick"/>                
                            </h:panelGroup>
                        </f:facet>      
                         <f:subview id="empleadoSubView">   
                            <ui:include src="/Crud/Empleado/EmpleadoList.xhtml" >
                                  <ui:param name="isModalPanel" value="#{true}"/>        
                                  <ui:param name="parentHome" value="#{equipoProyectoHome}"/>
                                  <ui:param name="parentAction" value="wire"/>
                                  <ui:param name="parentRelationship" value="empleado"/>                  
                             </ui:include>    
                        </f:subview>              
                    </rich:modalPanel>
                 
                    <h:commandButton id="empleadoButton" value="Elegir empleado">
                        <rich:componentControl for="modalPanelEmpleadoList" attachTo="empleadoButton" operation="show" event="onclick">        
                        </rich:componentControl>
                    </h:commandButton>
      



      In this case, it is a link between the entity EquipoProyecto and the entity Empleado. I built this to overcome the problem described in CRUD is conversational, seamgen is not, it works, but now I have a new kind of problem, my new code works fine as long as there is only 1 relationship between 2 entities:


      
      Question (asked by)ManyToOne Person
      
      



      But, if I have 2 relationships:


      
      Question (asked by)ManyToOne Person
      Question (answered by)ManyToOne Person
      
      



      Then that means that I will have 2 ui:include referencing PersonList.xhtml in QuestionEdit.xhtml... and since there are some state in PersonList binded with ScopeType.PAGE (AFAIK it is the only sane way to deal with nested h:selectOneMenu ) that state is going to be automatically shared between the 2 instances of PersonList.xhtml.


      Any hints on how to deal with this? (I can not wait until we get ScopeType.COMPONENT with JSF 2.0!! )

        • 1. Re: ScopeType.COMPONENT: How to emulate it before JSF 2.0?
          Vladimir Kovalyuk Apprentice

          It is not about how to emulate COMPONENT scope. You can just pass the appropriate instance of PersonList as an ui:include parameter.

          • 2. Re: ScopeType.COMPONENT: How to emulate it before JSF 2.0?
            Francisco Jose Peredo Noguez Master

            The the appropriate instance of PersonList.xhtml?, but PersonList.xhtml is the thing included with ui:include... right now it looks like this:


            I have (askedBy):


            
            <f:subview id="askedBySubView">   
                                  <ui:include src="/Crud/Empleado/PersonList.xhtml" >
                                        <ui:param name="isModalPanel" value="#{true}"/>        
                                        <ui:param name="parentHome" value="#{questionHome}"/>
                                        <ui:param name="parentAction" value="wire"/>
                                        <ui:param name="parentRelationship" value="askedBy"/>                  
                                   </ui:include>    
                              </f:subview>     
            
            



            and (answeredBy)


            
            <f:subview id="answeredByView">   
                                  <ui:include src="/Crud/Empleado/PersonList.xhtml" >
                                        <ui:param name="isModalPanel" value="#{true}"/>        
                                        <ui:param name="parentHome" value="#{questionHome}"/>
                                        <ui:param name="parentAction" value="wire"/>
                                        <ui:param name="parentRelationship" value="answeredBy"/>                  
                                   </ui:include>    
                              </f:subview>
            
            



            both of them are included in QuestionEdit.xhtml, and I one to have some state variables that live as long as I am in the same page (ScopeType.PAGE) but that are not shared between the PersonList.xhtml inside <f:subview id="askedBySubView"> and the PersonList.xhtml inside <f:subview id="answeredByView">.


            How can I can pass the appropriate instance of PersonList.xhtml as an ui:include parameter for a ui:include that points to PersonList.xhtml?

            • 3. Re: ScopeType.COMPONENT: How to emulate it before JSF 2.0?
              Francisco Jose Peredo Noguez Master

              BTW remember that PersonList.xhtml is not to edit persons, is to search for persons, so I can not pass a instance of Person to it (it just does not make sense to do that for search component, I do want to display or edit a different person on each PersonList.xhtml, I one to do 2 different searches)