0

Dynamic change "IF" attribute

asked 2011-09-07 11:54:11 +0800

asocjal gravatar image asocjal
18

Hello,

In my application user will log in, and then, depending on its rights, he should be able to see or not some part of GUI. For example for normal user change password button should not exists, when for admin user it should be on page. I thing will be great if I could do this in this way:

<button if="${loggedUser.rights.changePassword}"/>

So I will have User class that will contain rights class, and this class contains changePassword variable that contains bool information has this user rights to change password or not.

When this value (loggedUser.rights.changePassword) changes from false to true, button should be automatically added to page, because now "if" parameter equals to true. How to do this?

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2011-09-09 04:23:14 +0800

samchuang gravatar image samchuang
4084 4

Hi

you could check this thread, check "caclark" 's sample code

link publish delete flag offensive edit

answered 2011-09-09 04:51:23 +0800

asocjal gravatar image asocjal
18

updated 2011-09-09 06:42:09 +0800

Thanks, but this not solves my problem.
When I use "visible" attribute, page on browser side contains element. I prefer situation when such components are not on browser side at all if there is "if" element set to false. This is safer.
So it looks "if" attribute is executed only on page loading? Maybe then better is to create 2 pages? First with login form, second with main application?

link publish delete flag offensive edit

answered 2011-09-09 09:47:17 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

The "if" attribute is absolutely only used in the rendering phase. That is its purpose. I'm not sure what safety you're referring to...
But, if you are using a GFC controller, hook the doBeforeCompose(...) method and set some variable that can be accessed by the "if". You can also use the "unless" in partnership with the "if" if you have 2 different UI elements to display (e.g. a label and list).

link publish delete flag offensive edit

answered 2011-09-09 11:06:33 +0800

asocjal gravatar image asocjal
18

Sorry, for my English. I will try to describe it as simple as I can. Maybe better I will write what I want to achieve.
I'm going to create such web application:

1. Application starts and shows login form.
2. User writes its name and password and clicks "Login" button.
3. "Login form" drops out of sight.
4. "Main application form" shows.
5. If logged user is John, he will be able to change his own name using textbox on "Main application form".
6. If logged user is Jack, he will not be able to change his own name. He doesn't have textbox on page and when he opens HTML page source code, he doesn't have this textbox there. This means, Jack doesn't know, that if he was John, he would had this option.

So now, should I make "Login" and "Main application" different web pages or is there any way to dynamically add "Main application form" after login to the same page?

link publish delete flag offensive edit

answered 2011-09-09 13:14:42 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

"So now, should I make "Login" and "Main application" different web pages "
That's the way I organize my projects. The main app can be created with Executions.createComponents(...). If you've set a value in some scope after the login to tell whether to put out a textbox or a label(or maybe nothing), this should work.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-09-07 11:54:11 +0800

Seen: 246 times

Last updated: Sep 09 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More