function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
raghu0446raghu0446 

Re-render based on multiselect Picklist Value

I need to rerender based on the multiselct picklist values. It is working fine if only one value is selected, but if more than one value is selected in the multi-picklist field, only the first value is being getting the response. Please Help.

 

*****************Visualforce page part ************************ 

<apex:pageBlockSection columns="1" >
<apex:pageBlockSectionItem >
<apex:outputLabel value="Programs user needs access to" for="apps" />
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:inputField value="{!Case.Citrix_Applications__c}" onselect="populateRoles()" onChange="populateRoles()" id="apps" onkeypress="return disableEnterKey(event)"/>
<apex:actionFunction immediate="true" name="populateRoles" action="{!getAppRoles}" rerender="Rolesr" status="reqstatus" focus="name"/>
<script> var rname = document.getElementById("{!$Component.apps}"); </script>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:actionRegion >
<apex:pageBlockSection columns="1" id="Rolesr" >
<apex:pageBlockSectionItem >
<apex:outputLabel value="Security Role" for="RolesA" />
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock" layout="block"/>
<apex:inputField value="{!Case.Role__c}" id="RolesA" />
<script> var rem = document.getElementById("{!$Component.RolesA}"); </script>
<apex:actionStatus id="reqstatus" startText="fetching the relevant info.." />
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageblocksection>
</apex:actionRegion>

 

 

********************** Controller method **********************************

public void getAppRoles() {
String autoroles='';
// String id=ApexPages.currentPage().getParameters().get('j_id0:_form:j_id32:j_id45:j_id58:j_id59:ISTEmail');
String[] id=ApexPages.currentPage().getParameters().get('pg:_form:j_id31:j_id57:j_id64:j_id65:apps').split(';');
System.debug('======32323200000000000000===>'+id);
for (String i : id){
System.debug('======iiiiiiiiiiiiiiii===>'+id);
if(i == 'ADAPT') {
autoroles= autoroles +' PRS Update, ADAPT Update';
}if(i == 'ARTS1') {
autoroles= autoroles +' PRS Update';
}if(i == 'ARTS2') {
autoroles= autoroles +' PRS Update';
}if(i == 'MPS') {
autoroles= autoroles + ' MPS Update';
}if(i == 'PRS') {
autoroles= autoroles + ' PRS Update';
}
}
req.Role__c = autoroles;

}

 

 

 

 

Notes: Here "Citrix_Applications__c" is a multiselect Picklist field and "Role__c" is a text field which needs to auto-populate the text based on the Citrix_Applications__c values.

 

 

Thank You

jwetzlerjwetzler

That seems overly complicated. Why all the javascript? And you should be keeping your DOM ids out of your controller method or else your page will be impossible to maintain.

 

Look at this example. I added a multi-select picklist to Account called multi__c. The controller method updates the Account description based on what's selected:

<apex:page controller="MyController">
    <apex:form id="theForm">
        <apex:inputField value="{!acc.multi__c}">
            <apex:actionSupport action="{!populateDescription}" event="onchange" rerender="theForm" status="reqstatus"/>
        </apex:inputField>
        <apex:actionStatus id="reqstatus" startText="fetching the relevant info.." />
        <apex:inputField value="{!acc.description}"/>
    </apex:form>
</apex:page>

public with sharing class MyController {
    public Account acc {get; set;}
    
    public MyController() {
        acc = new Account();
    }
    
    public void populateDescription() {
        String[] values = acc.multi__c.split(';');
        String description = '';
        for(String s : values) {
            description += s += ' ';
        }
        acc.description = description;
    }
}

 

Every time the value for multi__c changes, it calls populate description and rerenders the form.

raghu0446raghu0446

Thank you jwetzler for the response.

 

The Multi-select picklist is not giving me all the options i select. I know that the values will be seperated by ";" for multiselect picklist. When i use system.debug and look for the value, it just shows me only the first option of the selected values. Can you help me how to get all the values of the multi-picklist.

 

Thanks,

Raghu

jwetzlerjwetzler

I don't know why you're not getting all of the selected values but like I said in my previous post, you should not be using DOM ids in your controller. That's not the supported way to read the values of your picklist.

 

My example works. I suggest you adapt it to your object.