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
mritzmritz 

display values from one vf page to another having common controller

public class getAcnt{
    public string AcNm{get;set;} //get value frm vf page
    public string AcPhn{get;set;} //get value frm vf page
    public string myStr{get;set;} // string having ID of  a particular Account
    public list<Account> Usr{get;set;} //holds values of an account retreived from database
    ................
    public void search(){
    ................
    }
}

vf page 1

<apex:page controller="getAcnt" sidebar="false">
<apex:form >
      <p>Enter Account Details.</p>
      <p>Name:<apex:inputText value="{!AcNm}"/></p>
      <p>Phone:<apex:inputText value="{!AcPhn}"/></p>
      <p><apex:commandButton value="Search" action="{!search}"/>
    <b> <a href="AcntPg">Go2Account</a></b>
........................
........................
<apex:pageBlock >
          <apex:pageblockTable value="{!Usr}" var="my">
              <apex:column value="{!my.id}"/>
              <apex:column value="{!my.name}"/>
              <apex:column value="{!myStr}"/>
          </apex:pageblockTable
 </apex:pageBlock>
</apex:form>


vf pg2

<apex:page controller="getAcnt">
  <apex:form >
      <apex:outputText value="ID: {!myStr}"></apex:outputText>
</apex:form>
</apex:page>


This code displays info correctly on vf pg1 ,
But when i click on the link to go on pg2 i cant see the ID stored in string myStr.

tried using pageReference but that was wroking on "Apex commandButton" but i want "link" and the url was also not changing.

I want that the url changes and the values also reflect on this page.

(I havent used pageReference in my Code)
Mudasir WaniMudasir Wani
Hello,

The reason may be you are doing operations in the constructor.
When new page of same controller is loaded it will run the constructor.

Just remove your logic from constructor if any and use the below code in second page to call the method if you need to call any method on page load.
 
//You can call the controller method using 

<apex:page controller="getAcnt" action="{!yourMethodName}">

Let me know if you have any question 

Please mark this as solution if this solves your problem, So that if anyone has this issue this can help.


 
mritzmritz
There isnt any logic in constructor.
Nor do i need to call any method.
I want the ID stored in myStr to be visible in pg2 when itc accessed from pg1.
sandeep sankhlasandeep sankhla
Hi mritzi,

You can simply pass this Id in as URL parameter of other page when you are redirecting and then in controller you can get the id from URL parameter and then you can proceed further...

P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.

Thanks,
Sandeep
Salesforce Certified Developer 
mritzmritz
@sandeep
I dont want to pass values in URL.
sandeep sankhlasandeep sankhla
Hi mritzi,

Then you can save that id in custom setting and in another page you can get the id from there..

 
Mudasir WaniMudasir Wani
Hello,

You can refer to this blog for command link.
http://blog.jeffdouglas.com/2010/03/03/passing-parameters-with-a-commandlink/

Please mark this as solution if this solves your problem, So that if anyone has this issue this can help.