0

Object Structure Property Existing custom object Each property will have a Location (new custom object linked) New Custom field called “Rating” - Picklist 1 2 3 Other New Custom field called “Other Rating” - Text Location - New custom object linked Fields Location Number Location Name (Picklist) Hitech City Madhapur Requirements 1) Need to display all Properties on a visualforce page accessible from Web Tab 2) So Properties where the Location attached has Picklist Value as “Hitech City”, should display additional fields in grid for that property. 3) Also if the Rating is “Other” then Other Rating field should be mandatory when saving the records.

I have tried but I could not able to do 3 point

VF page:

<apex:page standardController="Property__c" extensions="PropertyLocationController">
    <apex:form>
        <apex:pageBlock title="Property & Location" id="Properties_list">
           <!-- Property List -->
            Property and Location Details:
            <apex:pageBlockTable value="{! Properties }" var="ct">
                <apex:column value="{! ct.Name }"/>
                <apex:column value="{! ct.Area__c }"/>
                <apex:column value="{! ct.Area_Location__c }"/>      
              <apex:column headerValue="Rating">
                <apex:selectList id="ratings"  value="{!ct.Rating__c}" rendered="{! ct.Area_Location__c == 'Hitech City' }" multiselect="false" size="1" >
                        <apex:selectOptions value="{!Ratings}"/>  
                 </apex:selectList>   
                </apex:column>
              <apex:column headerValue="Other Rating">
                <apex:inputField value="{!ct.Other_Rating__c}" rendered="{! ct.Area_Location__c == 'Hitech City' }" />                
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
        <apex:commandButton action="{! save }" value="Save" />
    </apex:form>
</apex:page>

Controller:

public class PropertyLocationController {

    List<Property__c> propsList{get;set;}
   public PropertyLocationController(ApexPages.standardController controller){  
        getProperties();
    }
    public List<Property__c> getProperties() {    
       propsList = Database.query(
            'SELECT Name,Area__c,Area_Location__c,Rating__c,Other_Rating__c FROM Property__c');
    return propsList;
 }
 public List<SelectOption> getRatings()
    {
       List<SelectOption> options = new List<SelectOption>(); 
        Schema.DescribeFieldResult fieldResult = Property__c.Rating__c.getDescribe();
        List<Schema.PicklistEntry> Picklist = fieldResult.getPicklistValues();
        for(Schema.PicklistEntry p : Picklist)
        options.add(new SelectOption(p.getValue(), p.getValue()));         
        return options;
    }

}
0

Though I didn't compile the code, but the approach will be like this.

You need to use actionSupport inside apex:selectList to render otherSection.

Be sure to wrap inside apex:actionRegion for partial refresh.

<apex:column headerValue="Rating">
    <apex:actionRegion >
    <apex:selectList id="ratings"  value="{!ct.Rating__c}" rendered="{! ct.Area_Location__c == 'Hitech City' }" multiselect="false" size="1" >             
        <apex:actionSupport reRender="otherSection" event="onchange" action="{!yourActionMethod}"/>
        <apex:selectOptions value="{!Ratings}"/>
    </apex:selectList>
    </apex:actionRegion> 
</apex:column>

<apex:column headerValue="Other Rating" id="otherSection">
    <apex:actionRegion>
        <apex:inputField value="{!ct.Other_Rating__c}" rendered="{! ct.Area_Location__c == 'Hitech City' && ct.Rating__c <> 'Other'}" required="false"/>  
        <apex:inputField value="{!ct.Other_Rating__c}" rendered="{! ct.Area_Location__c == 'Hitech City' && ct.Rating__c == 'Other'}" required="true"/>
    </apex:actionRegion>
</apex:column>
| improve this answer | |

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.