logo

Flex With Domino Quick Start - Part 5

By request, today I'm going to talk about user-based "hide whens" in Flex. Before we can do this we need to know as much as we can about the user.

Remember ages ago I talked about the "DEXT" object for JavaScript? Well, I've converted it in to a Flex-ready XML version, which you can see here.

By having Flex fetch this XML we know all we need to know about the user and whether to show them certain features. For example, here's the Simple app we're working on before the user has logged in:

ScreenShot001

Notice it says "Welcome Anonymous", there's a Login button and the "Create New Car" button is disabled. If you were to click the Login button and login (which you can try in the demo) you'd then see the screen re-adjust itself to look like this:

ScreenShot002 

Notice that Anonymous has been replaced with the user's name, the Login button now says Logout and the new Car button has been disabled.

How Did It Do That?

The key to all this is binding. Let's look at the new Car button:

ScreenShot004

The enabled property of the button is tied (bound) to the last XML result of the httpSession object, which is used to fetch the user-defining XML from the server. Whenever the httpSession fetches the XML again the lastResult updates and so then does the enabled property of the button as they're bound together. There's no need to do anything other than trigger a request for the XML.

The same is true of the user name display and the label of the "login" button:

ScreenShot005

Sorry about the blurry images. You can see the code in full by right-clicking the demo.

So, do you get the notion of binding? Clever init!?

The only other note-worthy addition is the login dialog. Notice in the source code that there's now a new file called Login.mxml. This is a component. The idea being we can separate the login/out logic from out app and re-use it elsewhere. I've made a bit of a mess of it, but you get the idea.

Note that by creating components as separate files you can reference them in code by that filename as the name of the object. For example our code does this:

ScreenShot006

Notice we've created an instance of the Login component called loginWindow and then opened it using the PopupManager.

What Next?

I've been asked to talk about charts with Domino data so I think I'll cover that next. Then I'll probably talk about creating forms/document from Flex. If I get chance I'll re-factor all the code and then make it available for download again.

Comments

  1. Hi Jake,

    Congratulations for this magnific example !

    Thanks !

  2. Reading along intently, Jake. Thanks very much for this introduction. As a result we are now discussing flex with some customers to test the waters. I'll let you know how that turns out.

    • avatar
    • Jenz J
    • Mon 9 Feb 2009 10:09 AM

    Jake,

    While enjoying my second Hammerhead of the day, I surfed into your Flex blogs. It was déjà vu. Wow, I've been experimenting with Flex and Notes also. Flex (and Flash) are a real double-shot. But I confess I've gone down a slightly different path, so, I thought I'd ask your opinion…

    • I found it easier using an agent to generate XML from a view. Maybe it was just me, but using the $$ViewTemplate approach and assembling the tags seemed so retro. It made me long for the Release 5 days. Instead, I instinctively turned to an agent and the very clever NotesForm.fields you can use. Worked out very nicely & I can do other things at the same time. (Like write to my aunt who hasn't heard from me in ages! But I digress.) Why not use an agent for packaging up your views into XML? Am I being blindsided here?

    • I liked your Login component, nifty. Although it would be nice to see an event generated on a successful login. However, I was a bit confused. Is it really necessary to include a login popup in an application if you already embed the SWF into a Notes database? Seems redundant. Seems redundant. The user is forced to log into the database anyway. And since the views will self-organize themselves (ala Reader / Editor fields) doesn't this eliminate the need to manually test for access rights with Ext? Anyway, I was a bit confused at this juncture. You might elaborate on your thinking here…

    • Yesterday, I ran into the BrowserManager and did not like this at first blush. It seems awfully convoluted to instantiate this object just to refresh a page. Tell me it ain't so!

    Needless to say, I enjoyed your blog, found it hugely enlightening, and saved me some time to boot. Nice job!

    Cheers,

    JJ

  3. Hi Jake,

    Thanks for the flex articles. Need help. I tried the code and I am able to authenticate successfully, but the Welcome text and Link button values are not changing after login was successfull. I need to manually refresh for many times to reflect the change. Please help. If you could post the database with the required forms that would be helpful.

    Thanks

    Rob

    • avatar
    • Jake Howlett
    • Mon 9 Feb 2009 03:28 PM

    Hi Rob. Sounds like it could be caching the Form that contains the post-login details. Add an Alert.show() after the login result is returned to see what the values are. Alternatively, try a HTTP sniffer to see the traffic going back/forth.

  4. Hi Jake,

    Yes, its caching issue. I have used Alert.show(), first time when I login it gives the name of the user logged in alert box, if I Login again with a different name the alert shows previous login name only. If I clear the cache and open again and login then its showing the newly logged in user name. How can we avoid this?

    Thanks

    Rob

  5. Hey Jake,

    As a mid-level Flex developer I'd like to offer a bit of best practice advice. You shouldn't ever bind to your results from http calls. There are issues using lastResult under some conditions that can cause it to be null. . .

    So httpSession.lastResult.session.user.@authentication . . .

    you should have something like this. ..

    [Bindable]

    private var session : XML = new XML( httpSession.lastResult.session );

    then you can bind to it " {session.user.@authentication}"

    It's much easier to debug that way as well. . .

    Food for thought. . .

    • avatar
    • Harold
    • Fri 13 Feb 2009 02:25 AM

    Great tutorial, thanks a lot! It seems for me, that after more then 10 years Notes client programming I found the right platform for stepping into Notes-Web development...

    I didn't find the session.object source in the downloaded database. Any idea where to find it?

    Harold

    • avatar
    • Jake Howlett
    • Fri 13 Feb 2009 04:37 PM

    Hi Harold,

    I meant to make a new copy available but forgot. Will do at some point soon.

    Jake

    • avatar
    • Aritz
    • Mon 16 Feb 2009 11:25 AM

    Hi Jake,

    You've left us in the oblivion with flex :-)

    Aritz

  6. Hi Jake,

    Thanks for the great tutorial.

    Can you please make the accounts.nsf available for download.

    Regards

    Nagarajan P.V.

    • avatar
    • Kristof P.
    • Tue 10 Mar 2009 02:29 AM

    Hi Jake,

    Thanks for all the good work!

    I really learned a lot already from your tutorials.

    However, I can't figure one small detail on this tutorial.

    Can somebody explain how and where I should create the session.object file/form please?

    Thanks!

    Kristof

  7. Hey Jake,

    Do you have any code to force a logout or Domino from Flex? I'm struggling to get it to work. . .

    I've tried this:

    function PortalLogout( redirectURL )

    {

    document.cookie="DomAuthSessId=;path=/";

    window.location.href = "some url"

    }

    or

    http://lmsestar.lmsnet.com/names.nsf?logout&redir=......

    Nothing seems to work.

    Your thoughts?

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Fri 6 Feb 2009

Share This Page

# ( ) '

Comments

The most recent comments added:

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content