2

I have a pageblock table with 2 columns.. Interests(custom field) and another column - just a static text that will be rendered based on some condition from a method.

<apex:pageBlockTable value="{!engListWrap}" var="item">
<apex:column >        
       <label>Interests</label>
       <apex:outputText value="{!item.eng.Interests_Top__c}" />
</apex:column>
<apex:column > 
       <apex:inputCheckbox value="{!item.selected}" rendered="{!NOT(checkForSavedMatch)}"/>  
       <apex:outputText value="Saved" rendered="{!checkForSavedMatch}" />                    
 </apex:column>
</apex:pageBlockTable>

Here is the method Im calling in the rendered property

public boolean getCheckForSavedMatch(){  
     List<Match__c> savedMatches = new List<Match__c>();   
     for(EngagementWrapper engwrapper : engListWrap)
        {                        
            savedMatches = [SELECT Id FROM Match__c WHERE Engagement__c=:engwrapper.eng.Id LIMIT 1];
        }      
        if(savedMatches.size()>0){
            return true;
        }
        else
            return false;
 }

My output is 4 rows and 2 columns (4 rows : engListWrap had 4 records).

The problem here is I have pass that item.eng.Id into renderedMethod CheckForSavedMatches. So, for that particular eng.Id, I will run a query based on that engId and return true or false. I need to use that eng.Id in the WHERE condition of the query in that method.

How do I pass that engId to the method? I tried apex:param, but didn't really work. Any idead how to proceed? I want to know whats the current item that we are looping through.

Help please.

Here is the wrapper code

public class EngagementWrapper
{
    public Engagement__c eng{get; set;}
    public Boolean selected{get; set;}                

    public EngagementWrapper(Engagement__c e)
    {
       eng = e;
       selected = false;

       System.debug('*****e:'+e);
       System.debug('*****selected:'+selected);
    }
}
  • Why don't you just add another Boolean variable in your wrapper class and populate it on init (go through each item and check for matches) and then work out of that on your page - <apex:column rendered="{!item.BooleanVar}">? – Boris Bachovski May 8 '14 at 5:49
  • I already have a boolean. I have added the column there. Now how? Added wrapper code, just in case. The checkbox will be rendered if the method is false. I have to add the render there also. – sfdcFanBoy May 8 '14 at 6:01
0

When you initialise your wrapper items, add the following code after that in order to identify which of your items should be selected or not.

Set <Id> savedMatchIds = new Set <Id> ();
Set <Id> engagementIds = new Set <Id> ();

for (EngagementWrapper engwrapper : engListWrap)
{
    engagementIds.add(engwrapper.eng.Id);
}

for (Match__c match : [SELECT Id, Engagement__c FROM Match__c WHERE Engagement__c IN :engagementIds AND Status__c = 'Saved'])
{
    savedMatchIds.add(match.Engagement__c);
}

for (EngagementWrapper engwrapper : engListWrap)
{
    if (savedMatchIds.contains(engwrapper.eng.Id))
    {
        engwrapper.selected = true;
    }
    else
    {
        engwrapper.selected = false;
    }
}

Then in your page simply render the column based on the "selected" variable:

<apex:column rendered="{!item.selected}">

I don't know what else is happening in your code, but based on what you've provided so far in your question, this should work.

  • The selection of the rows functionality is already there and is working absolutely fine. Ok, to make it simpler. I have added another outputtext in the checkbox column.. so I would like to render the checkbox or the outputText within the same column. The condition for the rendering is in the method in my class. In my method, i will have to check what is the ID of that row and do a soql query (Id is used in WHERE condition) and just return boolean to hide/unhide the checkbox/outputtext in that column. – sfdcFanBoy May 8 '14 at 7:27
0

I had used another parameter (Id) in the wrapper class and then while retrieving the list, I assign the values to the wrapper.

So, I just had to wrap more details in the wrapper class. As simple as that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.