function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AneeshaAneesha 

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. 

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

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.

AneeshaAneesha

Hi KamatchiDeviR,

bob_buzzardbob_buzzard

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

AneeshaAneesha

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

 

<apex:outputPanel id="error">
     <apex:pagemessages/>
</apex:outputPanel> 

<apex:form id="CForm" >
<apex:outputPanel id="error1">
   <apex:pageMessages />
</apex:outputPanel> 
//other business logic here
//..
//..
<apex:commandLink action="{!abc}" value="{!b.Label}" title="{!b.Name}" reRender="error,CForm" >
<apex:param name="clicked" value="{!b.Id}" />
</apex:commandLink>

 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.

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

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.

AneeshaAneesha
That worked partially. I am adding some ids to the url using getParameter().put(). Those urls are lost when i use actionSupport
Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

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.

AneeshaAneesha

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.

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

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.

AneeshaAneesha

That too didn't help.

 

I tried something like this 

 

<apex:pagemessage summary="Page not loaded completely. Please refresh the page" severity="error" strength="3" rendered = "{!if(isError == true,true,false)}"/>

 

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?

Kamatchi Devi SargunanathanKamatchi Devi Sargunanathan

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.

AneeshaAneesha
That is not working as the AJAX request in not returned and value of isError is not reflecting in VF page although it is set in the apex class.
Trying to make this work via JS now.

This is so nagging now!