0

I'm in trouble with valuation of conditional expression in Flex.

Let me explain.

I have this :

    <s:Label text="SomeTextLawyer" includeInLayout="{Session.isLawyer()}"
 visible="{Session.isLawyer()}"/>
    <s:Label text="SomeTextDoctor" includeInLayout="{Session.isDoctor()}"
 visible="{Session.isDoctor()}"/>

This Session object is defined as below :

public class Session extends Singleton
{
    [Bindable]
    private static var user:User;

[...]

    public static function isDoctor():Boolean {
        return Session.user.type == model.type.DOCTOR;
    }

    public static function isLaywer():Boolean {
        return Session.user.type == model.type.LAWYER;
    }
}

I have a mechanism that change the user, so my user can be first a doctor and then a lawyer. Problem is that my labels keep their first valuation. If I connect as a doctor first, I still have the doctor label displayed if I change my user as a lawyer. And vice versa...

On the AS code, my user is the good kind of user, but not on my mxml files... So only the displayed part doesn't see the user switching.

Any idea ?

Thank you in advance !

ketan
  • 19,129
  • 42
  • 60
  • 98
Guillaume
  • 466
  • 5
  • 19
  • The method `isLawyer()` is not defined in the Session`` class ??? – Maraboc May 18 '15 at 08:59
  • Yes, just edited my code (My code is in French, it's bad, I know, but like this...) – Guillaume May 18 '15 at 09:03
  • This not the problem i mean the method name ?? – Maraboc May 18 '15 at 09:04
  • I've let the french name of the function, but isLaywer() is well defined, and I edited the code... – Guillaume May 18 '15 at 09:11
  • Did you update your display? if not you should update it, with this update the label will reload the methods `isDoctor()` and `isLawyer` – Maraboc May 18 '15 at 09:20
  • I think I don't, because the display is not refreshed. How do you update the display ? Please not that I don't change my user on the same page I have the problem. So I go to another page, change my user, and go back the page I have my two labels. – Guillaume May 18 '15 at 09:26
  • Try to use `validateNow()` as mentioned in this post [Forcing Flex to update the screen](http://stackoverflow.com/questions/1120822/forcing-flex-to-update-the-screen) – Maraboc May 18 '15 at 09:35
  • Try to use `invalidateDisplayList()` on the view – Maraboc May 18 '15 at 09:55
  • Same... I still have the lawyer part displayed when I'm doctor and I use first a lawyer... – Guillaume May 18 '15 at 10:01
  • Did you click on some button if you switch from doctor to lawyer ? – Maraboc May 18 '15 at 10:17
  • Yeah, actually, I've a popup in the header to change my user. When I click OK, i go back main page and I had my problem in another page than the main one. – Guillaume May 18 '15 at 11:26

1 Answers1

0

try using a bindable boolean var to check the user type, for example :

[Bindable] public var isDoctor:Boolean;
[Bindable] public var isLawyer:Boolean; 

and set their values in your show control routine, for example:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
               creationComplete="application1_creationCompleteHandler(event)">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

                [Bindable] public var isDoctor:Boolean;
                [Bindable] public var isLawyer:Boolean; 

            protected function application1_creationCompleteHandler(event:FlexEvent):void
            {
                isDoctor = Session.isDoctor();
                isLawyer = Session.isLawyer();
            }

        ]]>
    </fx:Script>
    <s:VGroup>
        <s:Label text="Some Text Lawyer" includeInLayout="{isLawyer}"  visible="{isLawyer}"/>
        <s:Label text="Some Text Doctor" includeInLayout="{isDoctor}"  visible="{isDoctor}"/>
    </s:VGroup>
</s:Application>
Jileni Bouguima
  • 444
  • 2
  • 6
  • Well, I have a strange behavior, because I go only once to the creationCompleteHandler. I connect as a lawyer, then as a doctor, and I go only once to the creationCompleteHandler function. – Guillaume May 18 '15 at 12:01
  • i mention it just as example on creation complete but you should change the values of your booleans every time a user connect, on connection method for example – Jileni Bouguima May 18 '15 at 12:09
  • I used your workaround with [Bindable] properties, setting properly each boolean when necessary, and it works better. I don't know why it doesn't work directly... Thank you for the idea – Guillaume May 18 '15 at 13:20