+ Start a Discussion
NaishadhNaishadh 

Page Redirect Issue

Hi,

 

 I have two button on visual force page. One is apex command button and another is outputpanel with styleclass= btn.From apex command button I am calling execute method using action while in outputpanel I am calling execute method using actionFunction.In Execute, code create lead record and redirect to lead defualt list page.

 

It is working fine in case of apex command button but in case of outputpanel, code redirect the page on lead defualt page but it does not change url and also keeping page editor and component in page. Please guide.

 

Please help

 

 

<apex:page controller="VFJavaScriptDemo" >
<apex:form id="actionForm">
<apex:actionFunction id="executeId" name="executeData" action="{!execute}" reRender="dataForm"/>
</apex:form>
<apex:form id="dataForm" >
<apex:inputText id="value" value="{!name}"/>
<apex:commandButton id="Save" value="Submit" action="{!execute}"/>
<apex:outputPanel onclick="checkJavaScript()" styleClass="btn">
Click Me
</apex:outputPanel>
</apex:form>
<script>
function checkJavaScript() {
alert('inside');
executeData();
}

</script>
</apex:page>

 

public class VFJavaScriptDemo {
public String name { get; set;}

public PageReference execute() {
Lead l = new Lead(
lastname = 'VFJavaScript Testing',
company = 'sungard'
);

insert l;

PageReference pg = new PageReference('/00Q/o');
pg.setRedirect(true);

return pg;
}
}

 


 

Message Edited by Naishadh on 05-12-2009 05:43 AM
Best Answer chosen by Admin (Salesforce Developers) 
Ron HessRon Hess

no, really.

if you turn off developer mode,

 

both the edit window goes away and the redirect occurs correctly, nothing to do with the code.

All Answers

NaishadhNaishadh
Please help!
Ron HessRon Hess
turn off Developer mode in your personal setup and it works fine.
UmapenUmapen

I think you are calling Visualforce method from Javascript.  You might have to use actionFunction

 

Look at this example from docs: http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionFunction.htm

I have not used it but try somethink like

<apex:actionFunction action:"{!execute}"
ryan_marplesryan_marples
It could be that you have setup a reRender attribute for the actionFunction which could be preventing the redirect. Try removing that attribute.

Ryan
Ron HessRon Hess

no, really.

if you turn off developer mode,

 

both the edit window goes away and the redirect occurs correctly, nothing to do with the code.

This was selected as the best answer
NaishadhNaishadh
Thanks Ron!
Ron HessRon Hess

As a follow up i would like to point out that this page is best written with one apex : form tag

 

each form tag carries a seperate viewstate and this can make your page larger and slower, for no gain.

UmapenUmapen

I think this is related to page redirect

I have a custom controller, and 2 visual force pages.

My page1 is  Inside account page layout. Page 1 has a button that post page2 

Page 2 posts inside the section of account. How do I post my page 2 to new page.

 

When I test with the following URL it works - page 2 is posted properly

https://cs2.salesforce.com/apex/MytestPage1?id=066Q000000001ZM

 

When I test with following URL after adding to account page layout Page 2 is inside the account section

 https://cs2.salesforce.com/066Q000000001ZM

Here my code:

 

Controller:


public with sharing class MytestController {

  private final Account stdAcct;

 

  public PageReference EditList(){

  //return page.MytestControllerPage2;

    PageReference editList = Page.MytestControllerPage2;

    editList.getParameters().put('id', stdAcct.id);

    editList.setRedirect(true);

    return editList;

  }

 

  public MytestController(ApexPages.StandardController stdcontroller){

    this.stdAcct =  [select id, name, BillingCity from Account   where id = :ApexPages.currentPage().getParameters().get('id')];

          }

}

 

 

 

Page1 - added to account page layout 

 

<apex:page standardcontroller="Account" extensions="MytestController" sidebar="false" showheader="false" standardStylesheets="true">

<apex:pageBlock ><b>Account Name: </b><apex:outputText value="{!account.Name}" rendered="true"/>

<b> City: </b><apex:outputText value="{!account.BillingCity}" rendered="true"/>

<b> Market Name: </b><apex:outputText value="{!account.Market_Name__r.Name}" rendered="true"/>



</apex:pageBlock>

<apex:form > <apex:pageBlock >

<apex:pageBlockButtons location="top">

<apex:commandButton action="{!EditList}" value="Post another page" status="status" />

</apex:pageBlockButtons>

</apex:pageBlock> </apex:form>

</apex:page>

 Page2 - post from with button click on page1

<apex:page standardcontroller="Account" extensions="MytestController" sidebar="true" showHeader="true" standardStylesheets="true">



<!-- Begin Default Content REMOVE THIS -->

<h1>Congratulations</h1>

This is your new Page

<!-- End Default Content REMOVE THIS -->

</apex:page>

 I tried using commandLink instead of Commandbutton and used target="_blank"  But the page does not display header and sidebar. 

NOTE: My page 1 has showHeader="false" Page 2 has showHeader="true"

 

I turned off DevelpmentMode in user setting.

 

Any suggestions?