3

I have a visualforce page that uses various components to try to print data from a list of custom objects. The idea is that it will display a list of types of relationships and then if clicked it will display the names of people who have that type of relationship.

In my controller I have a:

Map<String, List<Relationship_Detail__c>> typeToRelationships

where it takes the relationship type as the key and gives back all of the custom objects with that type.

<apex:repeat value="{!typeToRelationships}" var="relationshipType" rendered="{!IF(sortedByType==true, true, false)}">
    <apex:commandLink action="{!relationshipTypeClicked}" rerender="relationsWithType">
        <apex:outputText value="{!relationshipType} ({!typeToNumberOfRelationships[relationshipType]})"/>
        <apex:param name="relationType" value="{!relationshipType}" assignTo="{!selectedType}"/>
        <apex:param name="idOfViewer" value="{!contact.Id}" assignTo="{!selectedIDForType}"/>
    </apex:commandLink>
    <apex:outputPanel id="relationsWithType" >
        <apex:dataList value="{!typeToRelationships[relationshipType]}" var="relation" rendered="{!IF(rendered[relationshipType]==true, true, false)}">
            <apex:commandLink action="{!relationDetailClicked}">
                various outputTexts
            </apex:commandLink>
        </apex:dataList>
    </apex:outputPanel>
</apex:repeat>

I want to modify it so that the string is the relationship type + the id of the contact page I am currently on.

The issue in doing that is with the dataList in the middle of the given code which renders based on a Map<String, Boolean> called rendered, which takes the same key and spits out true or false.

The code used rendered={!IF(rendered[relationshipType]... for the dataList but now I want to do something like this:

rendered={!IF(rendered[relationshipType+contact.id].

Is this possible? Or is there a way to have the rendered attribute call a function with those parameters which would return true or false?

1 Answer 1

1

It isn't possible to pass parameters to a controller method binding in a Visualforce page. From Controller Methods:

Visualforce markup can use the following types of controller extension and custom controller methods:

  • Action
  • Getter
  • Setter

You could rework typeToRelationships so that the keys already contain concatenated relationshipType and contact.Id.

Alternatively, you could put the apex:dataList into an apex:component. The component can have multiple apex:attributes defined. This will allow you to pass multiple parameters in.


One small personal crusade. The following is perfectly valid. However, it does contain a large amount of redundancy.

rendered="{!IF(sortedByType==true, true, false)}"

Instead, consider:

rendered="{!sortedByType}"

There is no need to compare a boolean to another boolean or wrap it in an IF statement.

1
  • Thank you very much and thank you for catching that redundancy. I will certainly look into the apex:component Commented Jun 30, 2014 at 12:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .