6 Replies Latest reply on Sep 22, 2011 9:33 AM by bucpatr1

    Setting Multiple View States programtically

    bucpatr1 Level 2

      I have a components where I need to make multiple visual changes based on the 'roles' that a user is in. I'm trying to use view states to do that. The trouble is, a user can be in multiple roles, so I need to be able to apply any or all of the visual changes at once. The only thing I've been able to come up with so far is to create a view state for each possible combination of roles and then use state groups to control which parts of the component are actually displayed. Unfortunately, that solution does not work once you have more than 4 or 5 roles since the number of view states needed for all the combinations is unmanageable. Does anyone have a better suggestion of how I could handle this?

        • 1. Re: Setting Multiple View States programtically
          pramod.rao

          Instead of creating viewStates may be you can try to create the UI dynamically based on the user role.

          So you can create separate components and pass the role to each component and let them change their UI based on the role.

           

          Do tell if this helps solve your issue.

           

          -Pramod

          http://www.flexmycode.com

          • 2. Re: Setting Multiple View States programtically
            bucpatr1 Level 2

            If it was just a matter of showing and hiding containers mabey that could work, although it would mean a lot of extra classes that have no reuse. In this case though there are also controls like buttons that need to be handled by the view states. Any other suggestions?

            • 3. Re: Setting Multiple View States programtically
              pramod.rao Level 1

              Well, I don;t know how complex your application is, but I guess may be you can group the roles into 2-3 groups and create a UI (with states) for each of them separately. You can probably control the functionality through some ActionScript Class.

               

              -Pramod

              www.flexmycode.com

              • 4. Re: Setting Multiple View States programtically
                pauland Level 4

                Bind the visibility an participation in layout of role specific components to a role capabilities object. So, the "department overview" panel is only visible when person.isManager is true - bind the values: visible="{person.isManager}" includeInLayout="{person.ismanager}". You get the idea.

                • 5. Re: Setting Multiple View States programtically
                  bucpatr1 Level 2

                  Again, both good ideas but I breaking the component into multiple classes would require too much refactoring at this point and programticly changing the visiblity means I have to do a boolean check or switch statement for any properties I want to change with the states.

                   

                  I was thinking about adding/removing stateGroups from a view state in actionscript, but I can't figure out how to get the view to update after I modify the state. I tried invalidateDisplayList and invalidateProperties and neither had any effect.

                  • 6. Re: Setting Multiple View States programtically
                    bucpatr1 Level 2

                    I think I've managed to come up with a solution. In my actionscript method I first creat a new State object. Then I loop through all the states of the component and check to see if each state if a member of the stateGroup(s) I'm trying to activate. If a matching state is found, I concat() the 'overrides' array of the found state with the 'overrides' collection of the new state. Once all the states have been checked, I push the new state into the 'states' collection of the component and set 'currentState' to the name of the new state.

                     

                    So far it seems to work, the only catch is that the overrides have to be added in the reverse order from how they are displayed on the screen. So for example, if I have three containers A, B, and C that I want to display from left to right I have to concat the overrides corresponding to those containers in the order C, B, A.

                     

                    Still a somewhat complicated solution, if anyone has an easier way to do it let me know.