2 Replies Latest reply on Jun 22, 2011 7:24 AM by ChristophFlex

    Presentation Patterns - Presentation Model




      i read this article  (http://blogs.adobe.com/paulw/archives/2007/09/presentation_pa.html)  about design patterns and decided to use the Presentation Model in a  mobile Project. The example Apps from the Flex mobile site  (DashboardMobile or CRUDMobile) also use this pattern.


      So i decided to give it a try and i will use this pattern in my current mobile project. But i am little bit stuck now...



      I  have a LoginView and i want a PopUp to be opened when the login fails.  How do the LoginView should notice that the PopUp should be shown? In  the LoginViewPresenter i made a boolean showFailPopUp which i could  change to true, but how should this change broadcasted to the View?


      thx for your help

        • 1. Re: Presentation Patterns - Presentation Model
          UbuntuPenguin Level 4

          I use Mate for my framework ( even though I plan to check out Swiz soon).  Over at the Mate forums, someone had a very similar question of how to use popups with presenters since a popup is view component, and the presenter should have not knowledge of views and how they operate.  Here is the response given by Theo Hultberg http://mate.asfusion.com/forums/topic.php?id=591.  Here is the example ruthlessly ripped from the forum post. I stripped out the comments for readability but I STRONGLY recommend you go read the whole thing.


          public class SomePresentationModel extends EventDispatcher
               [Bindable]   public var popupRelatedProperty : Object;
                 // this is the setter that is called by the injector  
               public function set someProperty( value : Object ) : void
                    popupRelatedProperty = value;  

          Essentially, the presenter has an object and whether or not this object is null lets your view interpret whether or not the popup should be visible.


          public var model : SomePresentationModel;
          private var popup : UIComponent;
          private function onPreinitialize( event : Event ) : void
          BindingUtils.bindSetter(popupRelatedPropertyChanged, this, ["model", "popupRelatedProperty"]);

          private function popupRelatesPropertyChanged( value : Object ) : void

          private var popUp:Object;
          override protected function commitProperties( ) : void
            // check that "model" isn't null to avoid null pointer exceptions when this is called  
          // before the presentation model has been injected  
          if ( model )
               if ( model.popupRelatedProperty != null && popup == null )
                      popup = PopUpManager.createPopUp(...);    
               else if ( model.popupRelatedProperty == null && popup != null )
                    popup = null;    


          Now the view is where the real display logic occurs.  On preinitialization of the component, we bind to the "popUpRelatedProperty" of the presenter, and have the setter function in our view as "popupRelatedPropertyChanges".  Whenever the value of the related property changes on the presenter, it will trigger popuprelatedproperty changes which in turn tells our view that it should invalidate its properties.


          During the next redrawing, commitProperties is called.  In this example, "super.commitProperties" isn't listed, but I put it in my overriden functions.  When commitProperties is called, we check to see if we have a presenter to stave of null pointer exceptions. If the popupRelated property is not null and the popup object in the view is null ( we aren't already showing the popup) then we create the popup.  If the popupRelated property is null and the popup is not, then we interpret that as we shouldn't be showing the popup and it needs to be removed.

          That is the way I handle popups using presenters, of course you could call it from the presenter, or have something like a supervising presenter, but I GREATLY prefer this method.  Once again, I would check out that forum post.

          1 person found this helpful
          • 2. Re: Presentation Patterns - Presentation Model
            ChristophFlex Level 1

            thx i will give this a try