I've seen this question asked on Flexcoders many times: how do you show/hide various parts of the application? And normally the person asking this question is proposing some complex solution when in fact the answer is simple. First step is to load all the roles for the user from the server-side and then maintain them in some class, typically a User class, like so:
public class User {
...
public var roles:ArrayCollection;
...
}
In a simple scenario, every role is just a string that is held in the roles list as you can see from the sample code above. However, every application is different and it may be more complex in your case.
Next your User class should have a function name isUserInRole( role:String ), analogous to the method used in JSP/Servlets for J2EE applications. This function should take the role provided and make sure it exists in the roles list for the user. If it does, the function should return true, otherwise it returns false.
The final part is to use this logic on various containers and controls. Say you want to give or restrict access to a Save button in your application, your code might look like so:
<mx:Button enable="{user.isUserInRole('EDIT_ITEM')}"/>
In the example above the button will be enabled only if the user has the EDIT_ITEM role. It is that simple.
Some extra things to consider, sometimes you want to completely hide the container/control, so you have to apply the same logic as above but to the visible property of the container/control. One final trick is if you don't want the container/control to take up any space while it is hidden, set its includeInLayout property the same way.
2008-03-01
Printing TextArea content
Just this past week an issue in one of our applications was pointed out to me. The feature allows a user to print the contents of a TextArea control, however it does not handle multi-page printing, meaning when the contents of the TextArea actually spans several printing pages. So I started working on adding this capability but after a while was wondering why I wasting my time and starting googling for this solution, since someone must have already done it. Didn't take long to find it actually. Someone has created a PrintTextArea control and included it as part of a project called FlexReport, which you can find here. Only one problem, the website contains no SWC file to download, so I just copied the code and compiled it as a library and used it in my project. I recommend you do the same, before this source code is lost, as this is a very useful control. Many thanks to the developer who created it, wherever you are :)
2008-02-26
Week of new beginnings: F3, AIR, DevCenter
So far this week has been all about new beginnings. First, yesterday the most feature rich version of Flex went out the door, version 3.0. That was big because secondly, Flex 3.0 supports AIR, which made its first apperance into the wild and will most likely bring about great innovation in 2008 and beyond. And for developers world wide looking for information and samples, the Adobe Development Center has been updated to make it easier to find said information. Happy coding everyone!!
2008-02-22
Ease of deployment is the key
There are many reasons why Flex is growing into a popular platform for creating RIAs: familiarity, great framework, simple yet powerful, etc... But the most important one I believe is ease of deployment. Think about it, even without the server component (now even that is free, see BlazeDS), you can create something pretty compelling. Case in point, just this week one of my work colleagues decided to dive head first into Flex. He comes from a Java/Swing background and started building a small application to learn the ropes, an album manager/viewer for his family and friends. He is loving it, but the best part is that he is going to make it available to his family and friends by hosting it on a server he is already using for other things. Nothing special for him to do, just drop the SWF file on the server and everyone can access it, thats how easy it is and that is why Flex is so successful. Could he have done this so easily in Swing? Nope, the client install would have been tedious, not impossible, but still quite an effort. The small footprint of the Flash player and seemless install is what makes this all possible. Who would have thought 10 years ago the little Flash Player would have been this powerful... great things come in small packages.
2008-02-12
VW UK in Flex
My brother and I currently own VWs and my dad owned 2 himself, so it is pretty cool working in Flex to see that a large car company like VW re-worked their UK site with Flex. It is very well done and I really like the animation when you select the color of your car, you actually see two robot arms appear and apply the new paint job. That is what RIAs are all about, useful and fun at the same time, captivating your imagination. And my three-door Golf R32 250hp only costs 27,745.00 euro btw. Only :)
2008-02-09
Contributing to AIR Unleashed
I've recently been contributing to a book called AIR Unleashed being written by my partner in crime Stacy Young. The book covers everything you need to know about Adobe's upcoming AIR platform from A to Z, literally! This book covers all the basics from working with windows, file operations and OS integration to the more advanced stuff such as using application frameworks, unit testing and continuous integration. If you are salivating at the chance of getting this book, you can already pre-order it on Amazon.
2008-02-02
Flex articles at InfoQ
It's Saturday morning and I am doing my regular tech web rounds and I found that the InfoQ website has no less that 3 Flex articles on their main page. One is about FlexReport, a tool for adding better printing capabilities, and God knows Flex needs help in that department. Second is a Java-based compiler API. I know you are going to say, that this exists today and lots of people of using it via ANT, but this is a bit different. It is an actual API, so you can create a Java class that uses the API to compile a Flex application and in some cases by just having the Flex application in memory, no actual file on disk. Interesting in seeing what that this is going to produce. And last but no least, FlexSpy and tool similar to FireBug but for Flex applications. I guess this is for those you won`t be able to have the Flex Building debugger but still want to look inside their Flex application at run and solve some problem they are having, big thumbs up here.
Subscribe to:
Posts (Atom)