+ Start a Discussion
theitdeptrockstheitdeptrocks 

Dynamic Render Class Help

Hi all,

 

I am trying to create a matrix map that is referrenced to determine whether or not an apex:inputField should be rendered on a page or not.  The problem is that I am currently needed to create a new getter method for each inputField.

 

Ideally, I'd love to have one method that the field name is passed into, which then checks against my matrix, and returns true or false.

 

Here's a sample of what it looks like now:

 

Class:

public with sharing class dynLayout{
    public Map<String,boolean> Criteria_1 = new Map<String,boolean>{
        'Field_1__c' => true,
        'Field_2__c' => false,
        'Field_3__c' => true
    }
    public Map<String,boolean> Criteria_2 = new Map<String,boolean>{
        'Field_1__c' => false,
        'Field_2__c' => false,
        'Field_3__c' => true
    }
    public boolean visible(string a){
        if(Criteria_1.get(a) == true && Criteria_2.get(a) == true){
            return true;
        }
        else{
            return false;
        }
    }

//Here are the getter methods for each field    
    public boolean getField_1(){
        return visible('Field_1__c');
    }
    public boolean getField_2(){
        return visible('Field_2__c');
    }
    public boolean getField_3(){
        return visible('Field_3__c');
    }


}

 

 

VF:

<apex:inputField value="{!MyObject__c.Field_1__c}" rendered="{!Field_1}"/><br />
<apex:inputField value="{!MyObject__c.Field_2__c}" rendered="{!Field_2}"/><br />
<apex:inputField value="{!MyObject__c.Field_3__c}" rendered="{!Field_3}"/><br />

 

Now this works just fine, but I have about 100 fields to work with and would prefer not to creat 100 additional methods. 

 

Does anyone have any recommendations for a better approach?

 

Thanks in advance!

 

Henry AkpalaHenry Akpala
theitdeptrockstheitdeptrocks

Thanks Henry,

 

I might be following you wrong, but I am thinking that field sets won't work because I would need a different field set for each possible layout.

 

I think my class more accurately would be:

    public Map<String,boolean> Criteria_1a = new Map<String,boolean>{
        'Field_1__c' => true,
        'Field_2__c' => false,
        'Field_3__c' => true
    }
    public Map<String,boolean> Criteria_1b = new Map<String,boolean>{
        'Field_1__c' => false,
        'Field_2__c' => false,
        'Field_3__c' => true
    }
    public Map<String,boolean> Criteria_2a = new Map<String,boolean>{
        'Field_1__c' => false,
        'Field_2__c' => false,
        'Field_3__c' => false
    }
    public Map<String,boolean> Criteria_2b = new Map<String,boolean>{
        'Field_1__c' => false,
        'Field_2__c' => false,
        'Field_3__c' => true
    }

 

In reality there is 1a through about 1f and 2a through 2d.  Criteria_1 is a specific picklist field on a parent record; maps for Criteria_1 a through f would be created for each of the field's picklist options.  Same is true for Criteria_2, a second picklist on the parent record.  Those two fields need to govern which fields are displayed.

 

Does that make sense?