+ Start a Discussion
sfdc18sfdc18 

Dynamically assign the value to "Rendered" attribute

Hi,
I have List<User> and its count.
I am iterating over a user count to display outputPanels for each and every user.
How to dynamically assign the value to "Rendered" attribute. i.e. In place of ABC in below example.
for eg.

<apex:repeat value="lstuser" var="u">
<apex:repeat value="list2" var="v">
<apex:outputPanel rendered="{!If(v.Name == 'ABC', true, false)}">
</apex:outputPanel>
</apex:repeat>
</apex:repeat>

Thanks.
Rajkumar VenkatRajkumar Venkat
What value you are trying to assign inplace "ABC".. Do you want compare two list(list2, and lstUser).. Still your issue is open, kindly share more info. 

<apex:outputPanel rendered="{!If(v.Name == u.Name, true, false)}">
sfdc18sfdc18
Some dynamic value of user from list as you mentioned above.
<apex:outputPanel rendered="{!If(v.Name == u.Name, true, false)}">
Rajkumar VenkatRajkumar Venkat
okay..  Instead of <apex:outputPanel rendered="{!If(v.Name == u.Name, true, false)}">.,  if you want to compare two lists of Users with some xyz conditions, You could get the list of valid user lists in apex Controller using collections and display only those user records in VF page. you could try this if you havent thought about this approach already
sfdc18sfdc18
I tried this already, but it is not working. Do you know any other approach?
Anupam RastogiAnupam Rastogi
Hi,

Did you try invoking a controller method from with the IF statement of the Rendered attribute. And within this method check whatever condition you wish to check and return True or False.

Thanks
sfdc18sfdc18
Hi Anupam,

No.
How to invoke a controller method from with the IF statement of the Rendered attribute?

Thanks
Anupam RastogiAnupam Rastogi
Hi Mayur,

Just create a getter within the Controller and call it from the Rendered attribute within the IF statement. 

So if you create a getter method in the Controller like - 
public String getShowColumn() {
        
        //---- Write the logic to check whether to show this column or not
        if(logic true)
            return True; //--- Return True if the logic is satisfied
        else
            return False; //--- Return False if the logic is not satisfied
    }

Within the IF statement you can write - 
rendered="{! IF(ShowColumn = True, True, False) }"

This VF page will call the getter method from the IF statement and return True or False depending on whether the logic was satisfied. This will display or hide the respective component from the page.

Thanks
AR

If the reply resolves your problem then please mark it as best answer.
Rajkumar VenkatRajkumar Venkat
Alternative method to above one, if your list of users is more, just create a wrapper class like below

public class userWrapper{

public user aUser {get;set;}
public boolean isShowColumn {get;set;}

public userWrapper(User theUser, boolean Isvalue){
 this.aUser=theUser;
  this.isShowColumn= isValue;
}

and use this wrapper in your constructor or your action methods and pass your values to this wrapper class.

public class userController{
public list<userWrapper> lstUsers {get;set;}

public void getUserlists(){

  //write your logic and get the lstUsers data. 

}

}

Hope this helps you.