+ Start a Discussion
Mikron AdminMikron Admin 

Problems with ReRender attribute

Hello.

 

i am a beginner with VisualForce programming.

 

I am trying to change some control status (chooseOperation and aquoteNumber) after changing the values of the controlling picklists.

 

However the ReRender attribute seems never working.

 

Can someone help me understand what I am doing wrong?

 

 

Visualforce code:

 

 

<apex:page standardController="Opportunity" extensions="QuoteToolRequestController">
<apex:sectionHeader title="New Quote Request"/>

<apex:form >
<apex:pageBlock mode="edit">
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>
<apex:outputText value="{!opportunity.OPPORTUNITYCODE_MK__c}" rendered="false"/>


<apex:pageBlockSection title="Quote Request Information" columns="2">

<apex:outputLabel value="Choose Operation " for="chooseOperation"/>
<apex:selectList id="chooseOperation" value="{!selectedOperation}" size="1">
<apex:selectOptions value="{!operationList}"/>
<apex:actionSupport event="onchange" reRender="quoteNumber,chooseCode" />
</apex:selectList>


<apex:outputLabel value="Choose Code to revision" for="chooseCode"/>
<apex:selectList id="chooseCode" value="{!selectedCode}" size="1" disabled="{!codeSelectionDisabled}">
<apex:selectOptions value="{!codeList}"/>
<apex:actionSupport event="onchange" reRender="quoteNumber" />
</apex:selectList>

<apex:outputLabel value="Quote Number" for="quoteNumber"/>
<apex:outputText id="quoteNumber" value="{!quotationName}" />
</apex:pageBlockSection>

<apex:pageBlockSection title="Quote Information" columns="1">

<apex:pageBlockSectionItem >
<apex:outputLabel value="Assignee" for="assignee"/>
<apex:inputField id="assignee" value="{!quotation.assignee__c}"/>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:outputLabel value="Due date" for="dueDate"/>
<apex:inputField id="dueDate" value="{!quotation.due_date__c}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>

<apex:pageBlockSection title="Technical Information" columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Requirements" for="requirements"/>
<apex:inputField id="requirements" value="{!quotation.requirements__c}" required="true"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:pageMessages showDetail="true"></apex:pageMessages>
</apex:pageBlock>

</apex:form>
</apex:page>

 

 Controller:

 

 

public class QuoteToolRequestController {

// FIELDS
private Opportunity parentOpportunity;
private Quotation__c quotation = new Quotation__c();
private List<SelectOption> operationList = new List<SelectOption>();
private List<SelectOption> codeList = new List<SelectOption>();
private Map<Integer,Integer> codeMap = new Map<Integer,Integer>(); // MAPPA DEI CODICI (Key = Quotation__c.code__c, Value = Quotation__c.version__c)
private Integer selectedOperation = 0; // selected Operation type for Quote Revision
private Integer selectedCode = 1; // selected Code for Quote Revision
private Integer maxCode = 0; // highest Code in all existing Quotes
// FIELDS


// PROPERTIES
public void setSelectedOperation(Integer value) {
this.selectedOperation = value;
}
public Integer getSelectedOperation() {
return this.selectedOperation;
}

public void setSelectedCode(Integer value) {
this.selectedCode = value;
}
public Integer getSelectedCode() {
return this.selectedCode;
}

public Quotation__c getQuotation() {
return this.quotation;
}

public List<SelectOption> getOperationList() {
return this.operationList;
}

public List<SelectOption> getCodeList() {
return this.codeList;
}

public boolean getCodeSelectionDisabled() {
return (this.selectedOperation <> 1);
}

public Integer getCode() {
if (this.selectedOperation == 0) {
return this.maxCode+1;
} else {
return this.selectedCode;
}
}

public Integer getVersion() {
if (this.selectedOperation == 0) {
return 1;
} else {
return (this.codeMap.get(selectedCode)+1);
}
}

public String getQuotationName() {
String quotationName = this.parentOpportunity.OPPORTUNITYCODE_MK__c;
Integer code = this.getCode();
Integer version = this.getVersion();

if (code < 10) {
quotationName = quotationName + '.0' + code;
} else {
quotationName = quotationName + '.' + code;
}
if (version < 10) {
quotationName = quotationName + '.0' + version;
} else {
quotationName = quotationName + '.' + version;
}
return quotationName;
}
// PROPERTIES


// CONSTRUCTOR
public QuoteToolRequestController(ApexPages.StandardController myController) {
parentOpportunity=(Opportunity)myController.getrecord();
operationList.add(new SelectOption('0','New Quote Code'));

initialize();

if (!codeList.isEmpty()) {
operationList.add(new SelectOption('1','New Quote Revision'));
//selectedCode = Integer.valueof(codeList.get(0).getValue());
}
}
// CONSTRUCTOR


public void initialize()
{
// VETTORE DELLE QUOTE DELL'OPPORTUNITÀ
List<Quotation__c> quoteVector = new List<Quotation__c>();
quoteVector = [select code__c, version__c
from Quotation__c
where Opportunity__r.ID = :parentOpportunity.ID];

for(Quotation__c quote: quoteVector) {
Integer quoteCode = quote.CODE__C.intValue();
Integer quoteVersion = quote.VERSION__C.intValue();

if (quoteCode > maxCode) {
maxCode = quoteCode;
}

if (codeMap.containsKey(quoteCode)) {
if (quoteVersion > codeMap.get(quoteCode))
codeMap.put(quoteCode,quoteVersion);
} else {
codeMap.put(quoteCode,quoteVersion);
codeList.add(new SelectOption(quoteCode.format(),quoteCode.format()));
}
}

// A QUESTO PUNTO SONO VALORIZZATE LE SEGUENTI VARIABILI:
// maxCode = MAX(code)
// codeMap = MAP(Code,MAX(version))
}

public PageReference save() {
quotation.name = getQuotationName();
quotation.opportunity__c = parentOpportunity.ID;
quotation.recordTypeID = '012200000000yEaAAI'; // Tool
quotation.status__c = 'Requested';
quotation.code__c = getCode();
quotation.version__c = getVersion();
insert(quotation);

// Redirect to Opportunity Page
PageReference opportunityPage = new PageReference('/'+parentOpportunity.ID);
opportunityPage.setRedirect(true);
return opportunityPage;
}
}

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
jwetzlerjwetzler

Not a bug.  Your actionSupport component is going to a do a form submit of your entire form, so it's going to do field validation, including requiredness, and not let you continue if you have validation errors.

 

The way to fix this is to limit the scope of what gets posted back by using the actionRegion component.  There is information about this component in the documentation, and many posts about it on the forums. 

All Answers

Mikron AdminMikron Admin

I have found the problem. It is caused by the required attribute of the following tag:

 

<apex:inputField id="requirements" value="{!quotation.requirements__c}" required="true" /> 

 

If I remove it, the reRender works correctly.

 

However I cannot understandthis behaviour: It seems a bug ti me.

jwetzlerjwetzler

Not a bug.  Your actionSupport component is going to a do a form submit of your entire form, so it's going to do field validation, including requiredness, and not let you continue if you have validation errors.

 

The way to fix this is to limit the scope of what gets posted back by using the actionRegion component.  There is information about this component in the documentation, and many posts about it on the forums. 

This was selected as the best answer
Mikron AdminMikron Admin

Yes, the activeRegion fixed it.

 

Many thanks

abhinavgupta19abhinavgupta19

I am having the similar problem and I have no required attributes the controlling picklist is able to rerender a text label but not the dependent pick list 

 

Here is the code

 

<apex:page controller="RerenderController">
 

  
  <h1>Select a Category</h1>
  <apex:form id="theForm">
      <apex:actionFunction name="onCategoryChange" action="{!onCategoryChange}" reRender="theForm" />

      <apex:selectList value="{!category}" size="1" onchange="onCategoryChange()">
          <apex:selectoptions value="{!categories}"/>

      </apex:selectList>
      &nbsp;      &nbsp;      &nbsp;
      <apex:selectList value="{!categoryValue}" size="1">
          <apex:selectoptions value="{!categoryValues}"/>
      </apex:selectList>
           
      &nbsp;      &nbsp;      &nbsp;     
      <apex:outputText value="{!categoryValuesAsCSV}" />
      <script>
          alert('I am rendered');
      </script>         

  </apex:form>
 
</apex:page>

 

 

 

 

public class RerenderController {
  private static Map<String, List<SelectOption>> catValueMap = new Map<String, List<SelectOption>> ();
 
  static {
   List <Selectoption> fruits = new List<SelectOption>();
   fruits.add(new SelectOption('Apple','Apple'));
   fruits.add(new SelectOption('Grape', 'Grape'));
   fruits.add(new SelectOption('Banana','Banana'));  
   fruits.add(new SelectOption('Orange','Orange'));     
   catValueMap.put('Fruits', fruits);  
  
   List <Selectoption> animals = new List<SelectOption>();
   animals.add(new SelectOption('Dog','Dog'));
   animals.add(new SelectOption('Cat', 'Cat'));
   animals.add(new SelectOption('Monkey','Monkey'));  
   animals.add(new SelectOption('Donkey','Donkey'));     
   catValueMap.put('Animals', animals);     
  
   List <Selectoption> computers = new List<SelectOption>();
   computers.add(new SelectOption('Dell','Dell'));
   computers.add(new SelectOption('Compaq', 'Compaq'));
   computers.add(new SelectOption('Acer','Acer'));  
   computers.add(new SelectOption('Apple','Apple'));     
   catValueMap.put('Computers', computers);  
  }

  public List<SelectOption> categories {get ; set;}
  public String category {get ; set;}
  public List<SelectOption> categoryValues {get ; set;}
  public String categoryValue {get ; set;} 
 
  {
      categories = new List<Selectoption>();
      categories.add(new Selectoption('Fruits', 'Fruits'));
      categories.add(new Selectoption('Animals', 'Animals'));
      categories.add(new Selectoption('Computers','Computers'));

     
  }

   public String getCategoryValuesAsCSV () {
       String csv = '';
       if (categoryValues != null) {
           for (Selectoption so: categoryValues ){
               csv += so.getValue() + ' , ';
           }
       }
       return csv;
   }
  
   public void onCategoryChange() {
       categoryValues = catValueMap.get(category); 
   } 
}