+ Start a Discussion

CommandLink target top redirect on Page Reference return null

Quick question about commandLink and if anyone is facing the same problem.  


In an embedded VF page I use commandLink to apply logic and redirect to a newly created object if the User clicks on the button.  


I also have error checking in place on the logic applied so that the controller will add an Apex Page Message for errorsand return null for a Page Reference.


Since this is an embedded VF page.  I have the target on the commandLink set to _top because I want to redirect the parent page.  


The problem I'm running into is that on cases of return null the page will move the embedded page to top and then display the error message.  


Is there a way to only have the commandLink target top on cases of a PageReference return and not on cases of return null?




Really tricky question !

I guess the only solution I can think of is, on Page Load decide whether this will return null or pagereference or null. And adjust the VF page accordingly something like


Lets assume if the case status = 'open' it will return null


so VF code should be 


<apex:commandLink target="{!IF(Case.Status == 'Open','','_top')}"> .......

 In the above example we added a condition to check whether it needs a _top or not


Thanks for the response.   This is what I ended up doing though for anyone else running into this.




Using this page

I used an output panel that is only rendered if a value is set on the controller.  This output text redirects to the desired page.  I also added the pageMessages to the rerender on the button as the pageMessages wouldn't reload without that.