There have been easier solutions using security, and you can create a backing bean as well to do this if you want. There was just a recent thread on this (rendering and security) here:
http://www.nabble.com/How-to-Secure-Views-in-JSF-t3811634.html If you are using facelets (or JSF 1.2 as well?) you can use custom EL functions to see if a set/map/list contains a string (permission in your case). For example: <t:inputText rendered="#{my:collectionContains(myBean.permissions, 'Admin')}" /> If you use a map, you don't need EL: public class UserPermissionBean { private Map<String, Boolean> permissions; public Map<String, Boolean> getPermissions() { return permissions; } } <t:inputText rendered="#{not empty userPermBean.permissions['Admin']" /> (The boolean is just a place holder) On 5/27/07, Pich <[EMAIL PROTECTED]> wrote:
Ok, I realize this solution might not be a good design. But what I am trying to do is to decide whether a specific component, must of the time commandButton, should be rendered or not. Deciding this is a matter of which permissions a specific user has. A user has a set of permissions and my thought was that I could specify an attribute for the component called "permission" holding the specific permission key. In the rendered attribute a method on a permissionBean is called. This method would in its turn call a service with the value of the permission attribute. The service knows the users permissions and would return the result to the bean, and the bean would return true or false. However, when I started implenting I realized I was not able to get the attribute "permission" from anywhere, unless I bind all components in a componentMap<UIComponent>, so that is why I dit that solution. So now I have all components using the attribute "permission" binded from 1, 2, 3 and so on in the map. In the rendered method permissionBean.getPermission() I have a counter going from 1, 2, 3 and so on. For each call to the method the counter is added with 1. I use this counter to get the "current component" componentMap.get(counter). Since I dit not like this design I was trying to figure out if it was a way to find the "current component" using the FacesContext. But I guess there is not. But do you have any idea on how I could design this and still solve my "permission to render" problem? Best regards Pich David Delbecq-2 wrote: > > Pich a écrit : >>> The renderer has access to the component and thus the attributes of that >>> >> component. >> >> This is what I want to do. How do I have accecss to the component and its >> attribute in the code of the rendered method? And remember that I do not >> use >> one component binding for each component. I have a Map<UICompontent> that >> I >> have all components in. How do I know which one, perhaps out of 10 >> components, is calling the rendered attribute? >> >> Best regards >> >> Pichdude >> > Hi, > > i think you have a big design issue. You are mixing the value binding of > the rendered attribute (which is a method use to know if a component > need to be rendered depending on "the state of a given bean"), whith > what andrew told you which is related on the "renderer" (the renderer > has access to current component because it's passed as a parameter). > > I think, in you case, as you already have component bindings in a map, > just create another Map for the rendered attribute. JSF by itself do not > write somewhere the "current component". However, as andrew suggested, > the datatable store the current index and current value in a request > scoped bean so that inner component can use it, maybe you can create > your own component bases on this code. > > However, as said, rendered attribute should be linked to a bean status, > not the current component, otherwise that would mean you would mix view > logic and buisness logic... > > -- View this message in context: http://www.nabble.com/Find-current-component-tf3818677.html#a10826713 Sent from the MyFaces - Users mailing list archive at Nabble.com.

