here in above image error message is displaying. But the record is saving while getting error. I want the error message as well as the record in editable mode.
vf-
<apex:stylesheet value="{!$Resource.HRMSStyle}"/>
<script>
window.onload=function()
{
refreshTable();
};
</script>
<style>
.customTable{
margin-left:50px;
width: 82% !important;
}
.pushbtn{
margin-left:51px !important;
}
#menu{
float:none !important;
}
</style>
<apex:include pageName="HRMSHeader"/>
<apex:form >
<apex:actionFunction name="refreshTable" reRender="PanelID,PanelIDRej"/>
<apex:pageBlock >
<apex:commandButton value="Apply For Leave" styleClass="pushbtn" action="{!OpenPTORequest}" onclick="noRefresh()">
</apex:commandButton>
<table cellpadding="5px" class="customTable">
<tr class="headerTr">
<th>Days Allotted</th>
<th>Days Remaining</th>
<th>Days Taken</th>
</tr>
<apex:repeat value="{!LstAllotment}" var="PTOAllot" id="pbt3" >
<tr>
<td>{!PTOAllot.Days_Alloted__c}</td>
<td>{!PTOAllot.Days_Remaining__c}</td>
<td>{!PTOAllot.Days_Taken1__c }</td>
</tr>
</apex:repeat>
</table>
<apex:outputPanel rendered="{!ListPL.size>0}" id="PanelID">
<br></br>
<div class="pageHeaderHRMS" style="width: 80.3% !important;margin-left: 51px;">Submitted Leaves</div>
<br></br>
<apex:outputPanel id="Refresh" rendered="{!ListPL.size>0}">
<apex:pageMessages id="s"></apex:pageMessages>
<table cellpadding="5px" class="customTable" >
<tr class="headerTr">
<th>Start Date</th>
<th>End Date</th>
<th>Half Day</th>
<th>Requested Days</th>
<th>Comments</th>
<th style="width:121px !important;">Action</th>
</tr>
<!-- <apex:pageBlockTable value="{!listWrapper}" var="wrap">
<apex:column headerValue="StartDate">
<apex:outputField value="{!PTOR.Start_Date__c}" rendered="{!isEdit}"/>
<apex:inputField value="{!PTOR.Start_Date__c}" rendered="{!NOT(isEdit)}"/>
</apex:column>
<apex:column headerValue="EndDate">
</apex:column>
<apex:column headerValue="Half Day">
</apex:column>
</apex:pageBlockTable>-->
<apex:repeat value="{!listWrapper}" var="PTOR" id="tab">
<tr>
<td>
<apex:outputField value="{!PTOR.le.Start_Date__c}" rendered="{!!PTOR.isEditable}"/>
<apex:inputField value="{!PTOR.le.Start_Date__c}" rendered="{!PTOR.isEditable}"/>
</td>
<td>
<!--<apex:outputField value="{!PTOR.End_Date__c}" id="enddateid" rendered="{!isEdit}"/> -->
<apex:outputField value="{!PTOR.le.End_Date__c}" rendered="{!!PTOR.isEditable}"/>
<apex:inputField value="{!PTOR.le.End_Date__c}" rendered="{!PTOR.isEditable}"/>
</td>
<td>
<apex:outputField value="{!PTOR.le.Half_Day__c }" rendered="{!!PTOR.isEditable}"/>
<apex:inputField value="{!PTOR.le.Half_Day__c }" rendered="{!PTOR.isEditable}"/>
</td>
<td>
<apex:outputField value="{!PTOR.le.DaysCount__c}" rendered="{!isEditable}" />
<!--<apex:inputField value="{!PTOR.DaysCount__c}" rendered="{NOT(isEdit)}"/>-->
</td>
<td>
<apex:outputField value="{!PTOR.le.Comments__c}" rendered="{!!PTOR.isEditable}" />
<apex:inputField value="{!PTOR.le.Comments__c}" rendered="{!PTOR.isEditable}" />
</td>
<td>
<!--<apex:commandLink styleClass="btn" style="padding:5px 6px;text-decoration:none" action="{!SavePendingLeaveTwo}" value="Save" rendered="{!NOT(isEdit)}" reRender="Refresh" status="actStatusId" onclick="noRefresh()"/>
<apex:commandLink styleClass="btn" style="padding:5px 6px;text-decoration:none" action="{!CancelPendingLeave}" value="Cancel" rendered="{!NOT(isEdit)}" reRender="Refresh" status="actStatusId" onclick="noRefresh()"/>-->
<!-- <apex:commandLink styleClass="btn" style="padding:5px 6px;text-decoration:none" action="{!EditLeaveData}" value="Edit"/> -->
<apex:commandButton action="{!EditLeaves}" value="Edit" reRender="Refresh" >
<apex:param name="editId" assignTo="{!opget}" value="{!PTOR.index}"/>
</apex:commandButton>
<apex:outputText value=" | " rendered="{!PTOR.isEditable }"/>
<apex:commandButton action="{!SaveLeaves}" value="Save" reRender="s,Refresh">
<apex:param name="saveId" assignTo="{!opget}" value="{!PTOR.index}"/>
</apex:commandButton>
<!-- <apex:commandButton action="{!SaveLeaves}" value="Save" rendered="s">
<apex:param name="saveid" value="{!PTOR.index}" assignTo="{!opget}"/>
</apex:commandButton>-->
<!-- <apex:param name="recrdId" assignTo="{!recid}" value="{!PTOR.id}"/>-->
<apex:actionStatus id="actStatusId" >
<apex:facet name="start" >
<img src="/img/loading.gif" />
</apex:facet>
</apex:actionStatus>
</td>
<!--<apex:inlineEditSupport event="ondblClick" />-->
</tr>
</apex:repeat>
</table>
</apex:outputPanel>
</apex:outputPanel>
<apex:outputPanel id="Refresh2" rendered="{!ListApprovedLeave.size>0}">
<!--<apex:pageBlockSection title="Approved Leaves" collapsible="false" columns="1">-->
<br></br>
<div class="pageHeaderHRMS" style="width: 80.3% !important;margin-left: 51px;">Approved Leaves</div>
<br></br>
<apex:outputPanel id="refnewfresh" >
<table cellpadding="5px" class="customTable">
<tr class="headerTr">
<!-- <th style="width:110px !important;">Action</th> -->
<th>Start Date</th>
<th>End Date</th>
<th>Half Day</th>
<th>Requested Days</th>
<th>Comments</th>
</tr>
<apex:repeat value="{!ListApprovedLeave}" var="PTOR">
<tr style="display:{!IF(PTOR.Status__c='Approved','table-row','none')}">
<td>
<apex:outputField value="{!PTOR.Start_Date__c}" id="startid" rendered="{!isEditable}"/>
<apex:inputField value="{!PTOR.Start_Date__c}" rendered="{!NOT(isEditable)}"/>
</td>
<td>
<apex:outputField value="{!PTOR.End_Date__c}" id="enddateid" rendered="{!isEditable}"/>
<apex:inputField value="{!PTOR.End_Date__c}" rendered="{!NOT(isEditable)}"/>
</td>
<td>
<apex:outputField value="{!PTOR.Half_Day__c }" rendered="{!isEditable}"/>
<apex:inputField value="{!PTOR.Half_Day__c }" rendered="{!NOT(isEditable)}"/>
</td>
<td>
<apex:outputField value="{!PTOR.DaysCount__c}" rendered="{!isEditable}"/>
</td>
<td>
<apex:outputField value="{!PTOR.Comments__c}" rendered="{!isEditable}" />
<apex:inputField value="{!PTOR.Comments__c}" rendered="{!NOT(isEditable)}"/>
</td>
<!-- <apex:inlineEditSupport event="ondblClick"/>-->
</tr>
</apex:repeat>
</table>
</apex:outputPanel>
<!-- </apex:pageBlockSection> -->
</apex:outputPanel>
<apex:outputPanel id="Refresh5" rendered="{!ListApprovedLeave.size>0}">
<!--<apex:pageBlockSection title="Approved Leaves" collapsible="false" columns="1">-->
<br></br>
<div class="pageHeaderHRMS" style="width: 80.3% !important;margin-left: 51px;">Rejected Leaves</div>
<br></br>
<apex:outputPanel id="refnewfresh5" >
<table cellpadding="5px" class="customTable">
<tr class="headerTr">
<!-- <th style="width:110px !important;">Action</th> -->
<th>Start Date</th>
<th>End Date</th>
<th>Half Day</th>
<th>Requested Days</th>
<th>Comments</th>
</tr>
<apex:repeat value="{!ListApprovedLeave}" var="PTOR">
<tr style="display:{!IF(PTOR.Status__c='Rejected','table-row','none')}">
<td>
<apex:outputField value="{!PTOR.Start_Date__c}" id="startid" rendered="{!isEditable}"/>
<apex:inputField value="{!PTOR.Start_Date__c}" rendered="{!NOT(isEditable)}"/>
</td>
<td>
<apex:outputField value="{!PTOR.End_Date__c}" id="enddateid" rendered="{!isEditable}"/>
<apex:inputField value="{!PTOR.End_Date__c}" rendered="{!NOT(isEditable)}"/>
</td>
<td>
<apex:outputField value="{!PTOR.Half_Day__c }" rendered="{!isEditable}"/>
<apex:inputField value="{!PTOR.Half_Day__c }" rendered="{!NOT(isEditable)}"/>
</td>
<td>
<apex:outputField value="{!PTOR.DaysCount__c}" rendered="{!isEditable}"/>
</td>
<td>
<apex:outputField value="{!PTOR.Comments__c}" rendered="{!isEditable}" />
<apex:inputField value="{!PTOR.Comments__c}" rendered="{!NOT(isEditable)}"/>
</td>
<!-- <apex:inlineEditSupport event="ondblClick"/>-->
</tr>
</apex:repeat>
</table>
</apex:outputPanel>
<!-- </apex:pageBlockSection> -->
</apex:outputPanel>
</apex:pageBlock>
<center>
<div id="footer">
<center>
<div class="headerFooterBlack">
</div>
</center>
Copyright ©. All rights reserved. <a href="http://www.techilaservices.com/"
target="_blank" title="Portal">Techila</a>
</div>
</center>
</apex:form>
here is a saveleaves method... where i should done changes
public void SaveLeaves(){
integer counter=0;
for(WrapperClass w : listWrapper)
{
if(w.le.Start_Date__c >w.le.End_Date__c || w.le.End_Date__c<=system.TODAY() || w.le.Start_Date__c <=system.TODAY()){
listWrapper.get(opget).isEditable= false;}
if(w.le.Start_Date__c >w.le.End_Date__c){
counter++;
listWrapper.get(opget).isEditable= false;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'End Date should be greater than or equal to Start Date'));
}
if(w.le.End_Date__c<=system.TODAY()){
counter++;
listWrapper.get(opget).isEditable= false;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'End Date should be greater than or equal to Today'));
}
if(w.le.Start_Date__c <=system.TODAY()){
counter++;
listWrapper.get(opget).isEditable= false;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Start Date should be greater than or equal to Today'));
}
}
if(counter==0){
update listWrapper.get(opget).le;
}
// System.debug('Exception caught: ' + e.getMessage());
system.debug('listWrapper.get(opget).le'+listWrapper.get(opget).le);
listWrapper.get(opget).isSelected = false;
listWrapper.get(opget).isEditable= false;
}
SaveLeaves
method, add a condition to validate the start and end date before resetting isEditable flag.