You need to sign in to do that
Don't have an account?

Rerender a component outside apex:form
I have an apex:pageMessage component outside apex:form which I would like to rerender based on the action of a commandlink and commandbutton inside apex:form. I have placed the pagemessage inside an outputpanel an rerendered the panel using the id, but its not displaying the error message. I can see the error message in the logs. But its not displaying in the page. First of all, i am doing the right thin? Is it even possible to rerender this way?
If not how do i get to rerender the pagemessage component? I cannot put the component inside the form, because currently the form itself is rerendered based on the action of the commandlink and commandbutton.
Hi Aneesha,
This was a very nice question, most of us are doing a small mistake by not handling the code with exception handling. But the best practices shows that there should be always a try catch exception in a function wherever you do a set of operations.
In your case, you don't get the error message in the <apex:pageMessages> , eventhough you can see it in a debug log, because you need to have a Try Catch Exception handling in your controller for the function you are using in the command link action="{!<your function>}".
Try the following example,
VF page:
<apex:page controller="Demo">
<apex:pagemessages /> //Here you don't want to specify any of the rendering function. If you need to add you can
<apex:form>
<apex:commandlink value="SampleLink" action="{!show1}"/>
</apex:form>
</apex:page>
Controller:
public class Demo{
public void show1(){
try{
// Write your functionality code
}
catch(Exception e){
Apexpages.addMessages(e);
}
}
}
Hope so this helps you...!
Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.
Hi KamatchiDeviR,
Thanks for your quick response. Okay so your solution sounds pretty straightforward, however the error message that i am trying to show is generated inside the constructor. The messages that are generated inside methods as you have mentioned in your response are displayed correctly. But the message generated inside constructor is not shown on the page.
I am using a try-catch and the error is added to page in the catch. But it is not displayed in the page.
You have to put your conditionally rendered panel inside another outputpanel that is always rendered. I've described this in detail at:
http://bobbuzzard.blogspot.co.uk/2011/02/visualforce-re-rendering-woes.html
Hi Bob,
I am currently using more-or-less the same approach. I do not have a boolean to re-render though.
Please see my code snippet below
as you can see I have two apex:pagemessage components, 1 inside and outside the form. The error message is not shown in both places. Even if I comment out one of them, the message is still not shown.
Ok Aneesha,
Tthen do one thing, use action support for the commandlink to reRender the ids'.
Try the following,
<apex:commandLink action="{!abc}" value="{!b.Label}" title="{!b.Name}" >
<apex:actionSupport event="onclick" reRender="error,CForm">
<apex:param name="clicked" value="{!b.Id}" />
</apex:actionSupport>
</apex:commandLink>
Hope so this helps you...!
Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.
So, in the actionSupport you are rerendering only error,CForm right?
You need to include the input's ids also to rerender, that you are passing in the getParameters().put() . Then try again.
Hope so this helps you...!
Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.
No i meant i am passing actual record ids through the url.
So my url is something like
http://<instance>.salesforce.com/apex/<pagename>?accId=<someID>
now while using actionshupport my url turn out to just http://<instance>.salesforce.com/apex/<pagename>
Also the parameter is not being passed.
Yeah I can understand,
Try the following method for using Action region,
<apex:actionRegion>
<apex:commandLink action="{!abc}" value="{!b.Label}" title="{!b.Name}" >
<apex:actionSupport event="onclick" reRender="error,CForm">
<apex:param name="clicked" value="{!b.Id}" />
</apex:actionSupport>
</apex:commandLink>
</apex:actionRegion>
So that when you are using the actionRegion, the actions are reflected at that particular region alone.
Hope so this helps you...!
Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.
That too didn't help.
I tried something like this
I am setting the boolean isError inside catch block for a try-catch. I believe since the AJAX call was not completed the page is not rendered and so the message is not getting displayed. Any help?
Hi Aneesha,
Try this
<apex:pagemessage summary="Page not loaded completely. Please refresh the page"
severity="error" strength="3" rendered = "{!isError == true}"/>
Hope so this helps you...!
Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.
Trying to make this work via JS now.
This is so nagging now!