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>