You need to sign in to do that
Don't have an account?
Victor19
Conditional display of html tag on a visualforce page
Hi,
I have a html tag for a checkbox field that I display on visualforce page. The field will be visible only to certain people, so my requirement is I want this html tag to be visible on the visualforce page only to the people who have access to this checkbox field. How do I achieve this? Does anybody have any suggestions or some sample code that I could use for my page?
Thanks!
Vic
Hi,
Yeah you can achieve this by querying the particular profile user in the Controller and rendering the field based on the condition.
For example,
Controller:
public class demoCon{
public List<User> ulist{get;set;}
public ID userID{get;set;}
...............
public demoCon(){
Profile p = [select id,name from profile where name =: '<Your profile name>' limit 1];
ulist = [select id,name,profileID from user where profileID =: p.id limit 1];
if(ulist.size() > 0){
if(user u1 : ulist){
userID = u1.id;
}
}
}
......................
}
VF page:
<apex:page standardController="Account" class = "democon">
<apex:form>
................
<apex:inputfield value="{!Account.checkboxField__c}" rendered="{!Account.OwnerId == userID}"/>
.................
</apex:form>
</apex:page>
In the above example, controller itself we are querying the condition for the profiles you need to show the field. In the Vf page we are rendering the field based on the owner equals to that id.
Hope so this helps you...!
Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.
Thanks Kamatchi for your suggestion! I would to conditionally display a html tag on a visualforce page. As in if a field is visible to the user, then display the html tag.
Sorry, its not clear can you please explain in detail?
Say with an example.