2008-03-01

Handling user roles in the UI

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.

4 comments:

Laurent said...

thank you for this note, it helps me a lot

Anonymous said...

酒店打工

酒店兼職

台北酒店

打工兼差

酒店工作

酒店經紀

禮服店

酒店兼差

酒店上班

酒店PT

酒店

酒店喝酒

酒店消費

喝花酒

粉味

酒店上班請找艾葳 said...

艾葳酒店經紀公司提供專業的酒店經紀, 酒店上班小姐,八大行業,酒店兼職,傳播妹,或者想要打工兼差打工,兼差,八大行業,酒店兼職,想去酒店上班, 日式酒店,便服店,制服酒店,ktv酒店,禮服店,整天穿得水水漂漂的,還是想去制服店日領上班小姐,水水們如果想要擁有打工工作、晚上兼差工作兼差打工假日兼職兼職工作酒店兼差兼差打工兼差日領工作晚上兼差工作酒店工作酒店上班酒店打工兼職兼差兼差工作酒店上班等,想了解酒店相關工作特種行業內容,想兼職工作日領假日兼職兼差打工、或晚班兼職想擁有鋼琴酒吧又有保障的工作嗎???又可以現領請找專業又有保障的艾葳酒店經紀公司!

艾葳酒店經紀是合法的公司工作環境高雅時尚,無業績壓力,無脫秀無喝酒壓力,高層次會員制客源,工作輕鬆,可日領現領
一般的酒店經紀只會在水水們第一次上班和領薪水時出現而已,對水水們的上班安全一點保障都沒有!艾葳酒店經紀公司的水水們上班時全程媽咪作陪,不需擔心!只提供最優質的酒店上班,酒店上班,酒店打工環境、上班條件給水水們。心動嗎!? 趕快來填寫你的酒店上班履歷表

水水們妳有缺現領、想要兼職、有缺錢的煩腦嗎?想到日本留學缺錢嗎?妳是傳播妹??想要擁有高時薪又輕鬆的賺錢,酒店和,假日打工,假日兼職賺錢的機會嗎??想實現夢想卻又缺錢沒錢嗎!??
艾葳酒店台北酒店經紀招兵買馬!!徵專業的酒店打工,想要去酒店的水水,想要短期日領,酒店日領,禮服酒店,制服店,酒店經紀,ktv酒店,便服店,酒店工作,禮服店,酒店小姐,酒店經紀人,
等相關服務 幫您快速的實現您的夢想~!!

Anonymous said...

酒店打工 酒店兼職
台北酒店 打工兼差 酒店工作 禮服酒店
酒店兼差 酒店上班 酒店應徵 酒店 酒店經紀