2 Replies Latest reply on Jan 19, 2011 3:35 AM by pouria62

    What about a new ScopeType?

    antibrumm.mfrey0.bluewin.ch

      Hello all


      I faced now several times the issue that the Event Scope is to big and the Stateless Scope is to small. For example with methods like isManaged() from the EntityHome.


      Let me explain this:


      I have a page to create/update/view an entity. If i want to create one the rendered page will call isManaged() several times to evaluate the rendered attribute for which button to display.



      • Not Managed - Persist button

      • Managed - Update button





      This happens in the jsf phase Restore view and again in Render Response.
      Each method call does not consume alot of time, but since you can have several fields in the page which use that method it will increase the processing alot in total.
      Now we know about Scopes and use a factory in the Event scope for this to speed up the processing.


      And here the issue comes up.
      Since the rendered attribute is evaluated already in the Restore view phase, to check which fields to process, and the event scope spawns the complete request we will persist the object and in the Render Response phase this attribute exists in the context and is not evaluated again. Because of that we will still see the Persist button and not the Update button yet.
      If you choose now the Stateless scope it is just a beautifier for the xhtml page.





      Here i think we could introduce a new kind of Scope. SubEvent or something like this. I think it should spawn for the first 5 jsf phases and spawn again for the Render Response phase.



      isManaged is probably not the best example but what about an isEditMode which is used by each field on the page to evaluate if it should display a text or a textfield?
      Or a select box which changes the content because of a change on the entity? There I think we could catch alot of speedup.


      I tried to take a look at the seam source but honestly i have no clue where to start :D
      Could this be solved by a simple phase listener aside the Seam Framework? But then we cannot use the Factory annotation and need something else.


      Does someone know if there is a possible way to introduce new context types in Seam or is able to point me in the right direction inside the seam code, i'm very willing to investigate there a little.


      Please let me know what you think about it.


      KR
      Martin

        • 1. Re: What about a new ScopeType?
          antibrumm.mfrey0.bluewin.ch

          Hey guys,
          I've had a bit of time today and came up with a quite simple solution for the sub-scope issue.


          It looks very promising in my current application right now but i will have to test it alot.


          I use now an observer on the beforePhase and clean vars in the EventContext if the factory method is annotated with SubEventScope. This seems to solve alot of caching issues.


          Here's the piece. Let me know if you see some deep impacts!




          /**
           * The Class SubEventScopeFilter. Implements a phase listener to clean Event Scoped variables if the factory method is
           * annotated with a SubEventScope annotation.
           */
          @Name("subEventScopeFilter")
          @Scope(ScopeType.APPLICATION)
          public class SubEventScopeFilter implements Serializable {
          
               /** The log. */
               private static Log log = LogFactory.getLog(SubEventScopeFilter.class);
          
               /**
                * 
                */
               private static final long serialVersionUID = 1L;
          
               @Observer(value = "org.jboss.seam.beforePhase")
               public void cleanSubEventVars(PhaseEvent event) {
                    if (PhaseId.RENDER_RESPONSE.equals(event.getPhaseId())) {
                         log.info("Cleaning Sub-Event-Vars before RenderResponse");
                         // loop through the event context variables and check if the factory method is annotated with SubEventScope
                         Context ctx = Contexts.getEventContext();
                         Init init = Init.instance();
                         String[] varNames = ctx.getNames();
                         for (String name : varNames) {
                              FactoryMethod fm = init.getFactory(name);
                              if (fm != null) {
                                   if (fm.getMethod().isAnnotationPresent(SubEventScope.class)) {
                                        ctx.remove(name);
                                   }
                              }
                         }
          
                    }
               }
          }
          



          • 2. Re: What about a new ScopeType?
            pouria62
            hi experts today i encountered another problem with selectmanycheckbox ;the snippet code including

            <h:selectManyCheckbox value="#{conversationBean.oneList}">
                <s:selectItems value="#{conversationBean.anotherList}" var="something" label="#{something.name}">
            </s:selectItems>
            </h:selectManyCheckbox>


            and now i need to persist a list of selected(checked) from conversationBean.anotherList into conversationBean.oneList . i don,t know how to? please F1 me.(i mean i,m really get in trouble and really need your help)