2

Validation error message is not displaying when select list is none or blank.Also I need to hide the buttons Submit,MakeAnonymous and Cancel button when clicked on either Submit and MakeAnonymous

Apex Class:

  public class SeriesNewFundingEventController {

   public Id seriesId {get;set;}

    public list<Funding_Event__c> newfevenlist {get;set;}

     public list<Funding_Event__c> finalfevenlist {get;set;}

     public Funding_Event__c tempfevent = new  Funding_Event__c();

   public Funding_Event__c fevent {get;set;}

    String recType;

   String pListValue;

    public Funding_Event__c editEvent {get;set;} 

    Public Boolean showFields {get;set;} 

   Public set<Id>fIds = new set<Id>();

     public SeriesNewFundingEventController(){

    seriesId = ApexPages.currentPage().getParameters().get('id');
     system.debug('....'+seriesId); 
     fevent = new Funding_Event__c();
         showFields = false;
     }

   public String getFundingLevelSelected() {
     return pListValue;
     } 

    public void setFundingLevelSelected(String pListValue) {
      this.pListValue= pListValue;
      }

public List<SelectOption> getPickListValue()
{
  List<SelectOption> options = new List<SelectOption>();
  Schema.DescribeFieldResult fieldResult = Funding_Event__c.Funding_Level__c.getDescribe();
  List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
  options.add(new SelectOption('', '--None--'));
  for(Schema.PicklistEntry f : ple)
  {
    if(f.getValue() != 'Organization')
    {
      options.add(new SelectOption(f.getLabel(), f.getValue()));
     }
   } 
   return options;           
 }

public String getParam(String name) {
    return ApexPages.currentPage().getParameters().get(name);   
}


      public PageReference Save(){
   newfevenlist = new list<Funding_Event__c>();
    system.debug('.....'+fevent);
    fevent.Series__c = seriesId;
      if(fevent.Grantor__c == null) {
        fevent.Grantor__c.addError('Grantor is required.');
        return null;
      }
     else{ 
     showFields = true;
     Funding_Event_Controller__c fec = new Funding_Event_Controller__c(Amount__c =                fevent.Amount__c,Status__c = fevent.Status__c);
   insert fec;
  Id rectype=[SELECT ID, name FROM RecordType WHERE SObjectType = 'Funding_Event__c' and name='External'].Id;

 if(fevent.Number_of_years_of_the_Funding_Event__c == 1 ){
   system.debug('...pListValue...'+pListValue);
  if(pListValue== null){
     apexpages.addmessage(new apexpages.message(ApexPages.severity.ERROR,'Please select   Funding Level'));
    return null;       
  }
  else
  {
 fevent.Funding_Level__c = pListValue;
 }
  fevent.RecordTypeId= rectype;
  fevent.Funding_Event_Controller__c = fec.Id;
  newfevenlist.add(fevent);
  insert newfevenlist;
}
else
 {
   if(fevent.Number_of_years_of_the_Funding_Event__c>1){
     Integer totalYears = (fevent.Number_of_years_of_the_Funding_Event__c).intValue();
     for(integer i=0;i<totalYears;i++){
      tempfevent.RecordTypeId = rectype;
      tempfevent.Grantee__c = fevent.Grantee__c;
      tempfevent.Grantor__c = fevent.Grantor__c;
      tempfevent.Funding_Vehicle__c = fevent.Funding_Vehicle__c;
      tempfevent.Project__c = fevent.Project__c;
      tempfevent.Program__c = fevent.Program__c;
    system.debug('...pListValue...'+pListValue);
      if(pListValue== null){
       apexpages.addmessage(new apexpages.message(ApexPages.severity.ERROR,'Please select Funding Level'));
       return null;       
        }
      else
       {
       tempfevent.Funding_Level__c = pListValue;
       }
      tempfevent.Status__c = fevent.Status__c;
      tempfevent.Series__c = seriesId;
       tempfevent.Funding_Event_Controller__c = fec.Id;
      newfevenlist.add(tempfevent);
      tempfevent = new Funding_Event__c();
   }
   insert newfevenlist;
  } 
 } 
}

public PageReference Cancel(){
 return null;
}

public PageReference MakeAnonymous(){

 Account account = new Account(Name='Anon',Anonymous__c = true);
 insert account;

}

Visualforce Page:

    <apex:page Controller="SeriesNewFundingEventController">
    <apex:form >
    <apex:pageBlock title="New Funding Event" mode="edit">
    <apex:pageMessages />
    <apex:pageblockButtons location="top">
    <apex:commandButton value="Make Anonymous" action="{!MakeAnonymous}"/>  
    <apex:commandButton value="Submit" action="{!save}" reRender="fields">
    </apex:commandButton>
    <apex:commandButton value="Cancel" action="{!cancel}" immediate="true">
    </apex:commandButton>
    </apex:pageblockButtons>
      <apex:pageBlockSection id="fields">
          <apex:inputField value="{!fevent.Grantee__c}" rendered="{!showFields==false}"/>
            <apex:inputField value="{!fevent.Grantor__c}" rendered="{!showFields==false}"/>
            <apex:pageBlockSectionItem >
        <apex:outputLabel value="Funding Level" /> 
       <apex:outputPanel styleClass="requiredInput" layout="block">
       <apex:outputPanel styleClass="requiredBlock" layout="block"/>
       <apex:selectList size="1" value="{!FundingLevelSelected}" styleClass="form-select" rendered="{!showFields==false}" required="true">
           <apex:selectOptions value="{!PickListValue}"/>
       </apex:selectList>
       </apex:outputPanel>
       </apex:pageBlockSectionItem>

      <apex:inputField value="{!fevent.Program__c}" rendered="{!showFields==false}"/>
      <apex:inputField value="{!fevent.Project__c}" rendered="{!showFields==false}"/>
      <apex:inputField value="{!fevent.Status__c}" rendered="{!showFields==false}" required="true"/>
      <apex:inputField value="{!fevent.Fiscal_Year__c}" rendered="{!showFields==false}" required="true"/>

      <apex:outputField value="{!fevent.Grantee__c}" rendered="{!showFields==true}"/>
      <apex:outputField value="{!fevent.Grantor__c}" rendered="{!showFields==true}"/>
           <apex:pageBlockSectionItem rendered="{!showFields==true}">
         <apex:outputLabel value="Funding Level" /> 
         <apex:outputText >{!fevent.Funding_Level__c}</apex:outputText>
      </apex:pageBlockSectionItem>
      <apex:outputField value="{!fevent.Program__c}" rendered="{!showFields==true}"/>
      <apex:outputField value="{!fevent.Project__c}" rendered="{!showFields==true}"/>
      <apex:outputField value="{!fevent.Status__c}" rendered="{!showFields==true}"/>
      <apex:outputField value="{!fevent.Fiscal_Year__c}" rendered="{!showFields==true}"/>
          </apex:pageBlockSection>
    </apex:pageBlock>
   </apex:form>
</apex:page>
2

Your rerender has only one target: fields. So only that piece of page will reflect the changes. Either remove the "rerender" completely (full page refresh) or provide a list of ids:

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_commandButton.htm

The ID of one or more components that are redrawn when the result of an AJAX update request returns to the client. This value can be a single ID, a comma-separated list of IDs, or a merge field expression for a list or collection of IDs.

<apex:pageMessages id="messages"/>
(...)
<apex:commandButton value="Submit" action="{!save}" reRender="messages,fields">

Similarly you'll have to target the container (parent tag) of all your buttons you want to hide.

P.S. Use <apex:pageBlockButtons location="top"> to hold the buttons - much nicer result, similar to native SF pages.

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.