+ Start a Discussion
LakshmanLakshman 

Apex page messages are not shown when I use action status in my Visualforce page

Hi All,

 

I have a pop-up page which sends email to end user, I have done validation on server side and want to show Apexpagemessages on VFP through server side validations but unfortunately I am not able to show page messages when I use actionstatus and command button action.

Below is my Visualforce page code snippet to this:

 

<apex:pageMessages id="errors"/>
<apex:pageBlockButtons rendered="{!showButtons}" id="buttons"> <apex:commandButton action="{!Send}" value="Send" rerender="buttons" status="closer"/> <apex:commandButton value="Cancel" onclick="javascript&colon;closeWindow()"/> <apex:actionStatus startText="(Sending...)" stopText="" onStop="window.close();" id="closer"/> </apex:pageBlockButtons>

Please let me know your thoughts/suggestions on this.

Thank you!

 

Regards,

Lakshman

SrikanthKuruvaSrikanthKuruva

are you able to show the apex messages if are not using the actionstatus?

LakshmanLakshman

Yes I am able to show.

 

Regards,

Lakshman

SrikanthKuruvaSrikanthKuruva

i think the problem is with the onStop="window.close()" in the action status tag. remove that and check if the page messages are being shown. if thats working then you will have to find an alternative to close the window.

LakshmanLakshman

I have done that and it works but I need that window.close() as I want to close the pop-up window after email has been sent and if there are errors it should show on the page.

Let me know if you have any workaround to this.

Thank you!

 

Regards,

Lakshman

SrikanthKuruvaSrikanthKuruva

ok lets do this.

First you remove the onStop tag from the actionstatus tag and use the onComplete attribute on the send command buttonwrite a javascript function and call this function in the oncomplete attribute of send commandbutton. now if the window is being closed or not when the action completes.

 

Now probably you are at the same point as when you used the onStop attribute. Now create a public variable in the apex class and set the varible to some value in the apex class if there are no errors

public string str;
//in the send action method 

str = 'no errors';//if there are no errors 

else

str = 'errors';//if there are errors 
now come back to the javascript function which we have written to close the window and do the following.

var str = {!str};

if (str == 'no errors')

{

//close the window

}

else

{

//do nothing

}
please try this and let me know if it works or else we shall try some other solution.

dcarmen66dcarmen66

The problem is that you're only refreshing the "buttons" section. The pageMessages are outside of that section so are not going to be refreshed/displayed.

SrikanthKuruvaSrikanthKuruva

why are you rerendering buttons section and why not page messages?

LakshmanLakshman

I am rerendering this because status doesnt works if there is no rerender present, well if I put rerender="buttons,errors"

still it doesnt works. I have tried this earlier.

 

Regards,

Lakshman

LakshmanLakshman

SrikanthKuruva wrote:

ok lets do this.

First you remove the onStop tag from the actionstatus tag and use the onComplete attribute on the send command buttonwrite a javascript function and call this function in the oncomplete attribute of send commandbutton. now if the window is being closed or not when the action completes.

 

Now probably you are at the same point as when you used the onStop attribute. Now create a public variable in the apex class and set the varible to some value in the apex class if there are no errors

public string str;
//in the send action method 

str = 'no errors';//if there are no errors 

else

str = 'errors';//if there are errors 
now come back to the javascript function which we have written to close the window and do the following.

var str = {!str};

if (str == 'no errors')

{

//close the window

}

else

{

//do nothing

}
please try this and let me know if it works or else we shall try some other solution.


Srikanth,

oncomplete doesnt works, I have tried this earlier, it requires only onstop -> actionstatus for this job.

Let me know your further thoughts.

Thank you!

 

Regards,

Lakshman

LakshmanLakshman

Was wondering if anybody can help me onto this. Its very much urgent.

 

Regards,

Lakshman

SrikanthKuruvaSrikanthKuruva

what is the problem you are facing when using the onComplete attrbute

LakshmanLakshman

The window doesnt closes. Can you please try out this in you org, it will be a great help to me.

 

Here is my sample send method code

//this is test variable change it accordingly to show/hide error on page

public String error1 = 'Error'

public void Send()

{

if(error1 == 'Error')

 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'An error occurred!!!!')); 

}

 

In VFP I have the same which which I earlier posted.

 

Let me know if you get success to this. Thanks in advance.

 

Regards,

Lakshman

OhadiosOhadios

I know this is a very old post, but I have been struggling with the same issue, which led met to this page...
I figured I'd provide my solution for anyone else who is trying to do the same and gets here in the future.

I wasn't able to achieve this using the action status, because if I used "reRender" on the button, then the page is not refreshed, and the error messages are not displayed.

If you remove the reRender, the page will refresh, but then I cannot close the window as a result of the onStop

What I decided to do was as follows:

  1. As suggested above, use a public variable to denote whether there are errors or not (I called mine closeWindow to denote if the window should be closed or now)
  2. I removed the reRender value from the button, to ensure that the page refreshes after pressing it.
  3. Used the ApexPages.addmessage in the controller to add the error to the page.
  4. The magic is in a java script code I added at the top of the VF Page, which runs at page load. It checks if the "closeWindow" variable is true, and if so - closes the window. if it is not, then it will do nothing, thus showing the error message:
<script type="text/javascript">
        // When we load the page, check if it needs to be closed as a result of activity completion, otherwise do nothing.
        window.onload = checkClose
        function checkClose() {
             var str = {!closeWindow};
                if (str == true) {
                    window.close()
                }
                else { 
                    // do nothing
                }
            }

Hope this helps someone...