I want to set the modify authority of an p:inputText
in PrimeFaces, but I want to this on Xhtml page (not in the managed bean). For example I can use "Rendered" attribute to hide the p:inputText
for nonAdmin users. However, I want nonAdmin users to see the p:inputText
but they should not change the value, just admins can change/delete/update the value. The admins should have modify authority, non admin users should just have read authority. Is there any attribute like rendered
?
<p:inputText rendered="#{request.isUserInRole('Admin')}"
value="#{managedService.files.price}"/>
Note: I may do this on managed bean but I want to know whether it is possible on just xhtml page.
You can simply set the readonly
or disabled
attributes of the p:inputText
.
Or you could use the p:inplace
component and disable it:
<p:inplace disabled="#{not request.isUserInRole('Admin')}">
<f:facet name="output">
#{managedService.files.price}
</f:facet>
<f:facet name="input">
<p:inputText value="#{managedService.files.price}"/>
</f:facet>
</p:inplace>
If you are not "Admin", you can see the price, but not edit it.
But I would create a custom tag to keep your XHTML pages DRY and less verbose. See for example: How to create a custom Facelets tag?