You need to sign in to do that
Don't have an account?
robert webber 8
Display errors from openlink VF page on save and stay open
I have a VF page that opens from an output link:
<apex:column headervalue="Title" width="50%">
<apex:outputLink value="/apex/WorkRequestVF?ID={!w.WorkItemID}">
{!w.WorkItemName}
</apex:outputLink>
</apex:column>
Within the WorkRequestVF child page I want to save and refresh the parent page.
<apex:commandButton value="Save" action="{!MySave}" oncomplete="closeWin();" style="width:150px"/>
MySave in the controller does error checks and then does an update on the record, then returns null.
Here is the VF javascript function:
function closeWin(){
if(window.parent){
window.parent.opener.location.href = window.parent.opener.location.href;
window.parent.close();
}
else{
window.opener.location.href = window.opener.location.href;
window.close();
}
}
This all works fine except for the case where there are ApexPages:message error messages added. The window closes before any of the error messages can be seen.
My requirement is that I want to be able to open the linked record from the parent page. When there are no errors I want to update the record, close the child page and refresh the parent page. If there are error messages, I want to stay on the page and show the error messages. How can I do this? Any help greatly appreciated.
<apex:column headervalue="Title" width="50%">
<apex:outputLink value="/apex/WorkRequestVF?ID={!w.WorkItemID}">
{!w.WorkItemName}
</apex:outputLink>
</apex:column>
Within the WorkRequestVF child page I want to save and refresh the parent page.
<apex:commandButton value="Save" action="{!MySave}" oncomplete="closeWin();" style="width:150px"/>
MySave in the controller does error checks and then does an update on the record, then returns null.
Here is the VF javascript function:
function closeWin(){
if(window.parent){
window.parent.opener.location.href = window.parent.opener.location.href;
window.parent.close();
}
else{
window.opener.location.href = window.opener.location.href;
window.close();
}
}
This all works fine except for the case where there are ApexPages:message error messages added. The window closes before any of the error messages can be seen.
My requirement is that I want to be able to open the linked record from the parent page. When there are no errors I want to update the record, close the child page and refresh the parent page. If there are error messages, I want to stay on the page and show the error messages. How can I do this? Any help greatly appreciated.
You will need to declare boolean variable that will let the vf page know if error has occured or not.
isError= true; // make this variable true just before the ApexPages:message line
<apex:commandButton value="Save" action="{!MySave}" oncomplete="closeWin();" style="width:150px" rerender="scriptPanel"/>
This will stay on the page and will not close when error occurs.
<apex:outputPanel id="idScriptPanel">
<script>
function closeWin(){
if({!ErrorMessages} == false) {
if(window.parent){
window.parent.opener.location.href = window.parent.opener.location.href;
window.parent.close();
}
else{
window.opener.location.href = window.opener.location.href;
window.close();
}
}
}
</script>
</apex:outputPanel>
ErrorMessage is defined in the controller as Boolean and set to true if the error checks fail. I also changed the commandbutton as you suggested:
<apex:commandButton value="Save" action="{!MySave}" oncomplete="closeWin();" style="width:150px" rerender="idScriptPanel"/>
<apex:commandButton value="Delete" action="{!MyDelete}" oncomplete="closeWin();" style="width:150px"/>
<apex:commandButton value="Cancel" action="{!MyCancel}" oncomplete="closeWin();" style="width:150px"/>
Now the page does not close whether there is an error or not, and does not close with Delete or Cancel.
<apex:commandButton value="Delete" action="{!MyDelete}" oncomplete="closeWin();" style="width:150px" rerender="idScriptPanel"/>
<apex:commandButton value="Cancel" action="{!MyCancel}" oncomplete="closeWin();" style="width:150px" rerender="idScriptPanel"/>
Could you please post you whole vf page / apex code ? This will be easier to identify bug.