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
JessSunJessSun 

apex:actionSupport not executing action?

I have a input feild in visualforce page which is a picklist and I want to rerender certain part of the page after changes happens on that input feild
Here is the code

<apex:inputField value="{!a__c.c__c}" >
                <apex:actionSupport event="onchange" action="{!changeHappenedOnC}" rerender="aSection" />
 </apex:inputField>

Before rerendering "aSection", Function "changeHappenedOnC" inside of my controller should be executed.

Function "changeHappenedOnC" is executed almost everytimes except when one of the required field for "a__c" is empty.

Have anybody entered this kind of problem and resolved their issue??
Your help will be appreciated..
 
p.s. looking into the logs when the issue happens this are the lines I got:


20:20:18.118 (118316000)|VF_PAGE_MESSAGE|You must enter a value
20:20:18.120 (120297000)|VF_PAGE_MESSAGE|You must enter a value

 


cheers
JS
Best Answer chosen by Admin (Salesforce Developers) 
izayizay

There are two things that you can try.

  1. Try setting the immediate attibute for the apex:actionSupport to true. Ex. <apex:actionSupport immediate="true"/>
  2. Try setting the required attribute for the field on the page to false.

Hope this helps!

All Answers

izayizay

There are two things that you can try.

  1. Try setting the immediate attibute for the apex:actionSupport to true. Ex. <apex:actionSupport immediate="true"/>
  2. Try setting the required attribute for the field on the page to false.

Hope this helps!

This was selected as the best answer
JessSunJessSun
Thank you for your reply.
I tried your 1st suggestion. However there was another challenge: in function "changeHappenedOnC", I refreshed a object, which is used for "aSection" display. if I set "immediate" to true, my object will not get refreshed correctly. :(

for 2. if I set it is required to false, will there be validation on those fields when user click on save?
izayizay

Yes, even if you set the field required="false" in the vfpage the server side validation will still be enforced.

 

You can also write your own validation in the controller. You can use the <apex:pageMessage> tag to display the error message. Ex:

 

<apex:page>
<apex:pageMessages id="Messages" escape="false" /><!-- Page messages section -->

Controller...

public PageReference save(){
if(a.field__c == null || a.field__c == ''){
a.field__c.addError('You must enter a value');//Will display on field
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, 'Please, enter a value for a.field__c'));//Will display on pageMessage element
return null;
}else{
insert a;//insert or update the record here
//Redirect to the record detail view page
PageReference pr = new PageReference('/' + a.Id);
pr.setRedirect(true);
return pr;
}
}
JessSunJessSun
Thank you! this solves my problem. I manually implemented the validation. Although I still need to figure a way to show required fields on the form, it is not styling work left! :}
izayizay

Here is a quick way you can get the same look for required fields:

 

<!-- CSS -->
<style type="text/css">
.requiredField{
    border-right:3px solid #B00000;
    padding:0px 16px 5px 0px;
    margin:0px -18px 0px 0px;
}
</style>

<!-- Page Block -->
<apex:pageBlockSection title="Information" collapsible="false" id="Information" columns="2">
    <!-- Section Item -->
    <apex:pageBlockSectionItem >
        <apex:outputLabel value="Name" styleClass="requiredField"></apex:outputLabel>
        <apex:inputField value="{!a.Name}" required="false"/>
    </apex:pageBlockSectionItem>
</apex:pageBlockSection>