tags:

views:

28

answers:

2

For my application I want to have users with different permissions. One permission would allow a user to view the data from my database, while another permission would allow them to edit the data. On log in I would check their permission to determine wether they can edit the data. I am looking for some way to disable the entirety of my page if the user has the read-only permission. Is there a simple way to disable everything within the <h:form> tag? I would need to be able to disable multiple pages, hopefully by just looking at one boolean in by backingbean. Any help would be greatly appreciated.

-EDIT-
Is there any containers or like that I could wrap around my inputs that could be set to disabled? This way I would only need to reference the diable in one place and could also leave each field to set its own disable property if that is needed in other logic I have?

+3  A: 

You can disable the buttons, links, input fields (everything that allows editing) etc... pointing them all to the same value in the backing bean.

<h:inputText disabled="#{!bean.permissionToWrite}">

I don't know any way to disable everything contained in a form, but you may not want to do that because you may want the user to submit search queries (i.e. a search box) withing the form.

Update: answering to the comment of Alex Larzelere.

IMHO in this case is better to use disabled rather than rendered because you may want to display the value of a field to the user in an inputText box, but not let him to modify it. If you don't render it, he can't see it. You could use outputText as well to display it but then you have to maintain two elements instead of one.

Update answering to the edit in the question: You can wrap your components inside a h:panelGroup for example and render it or not depending on your logic, but you can't disable the input fields that are inside from the h:panelGroup, you have to do it individually.

pakore
+1 Beat me to it. An alternative is to use `rendered` and just hide anything that gives the ability to edit from users who are not authorized to do so.
Alex Larzelere
That could be an option, though that will be a lot of work. I was hoping there would be something more elegant like (which I know is not possible) `<h:form disable="#{bean.permission}" />`
SomeFatMan
is not that much work, when adding an element, just add the disable parameter. Even in the future you could group permissions according to roles or groups for example :)
pakore
A: 

Most of Tomahawk's components has displayValueOnly, visibleOnUserRole and enabledOnUserRole attributes to control elements visibility.

Hope following links will be useful to you:

php-coder