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
davidjbbdavidjbb 

Get InputField and Apex Class

Hi Community,

 

I'm looking to get a Apex Input Field on a VF page called, ex Page1

<apex:inputFieldid="fromDate"value="{!Workorder__c.Start_Date__c}"required="true"/>


and use it for whatever I want in an Apex Class then output that Input field on Page 2

 

I'm not sure how to setup the Apex Class to grab the Input Field from Page one, manipulate the Input Field in the Apex Class, and then Display it on Page 2

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox
<apex:page title="Page 1" controller="MyController">
 <apex:form>
  <apex:inputText value="{!myValue}"/>
  <apex:commandButton action="{!page2}"/>
 </apex:form>
</apex:page>

 

<apex:page title="Page 2" controller="MyController">
 <apex:form>
  <apex:outputText value="{!myValue}"/>
 </apex:form>
</apex:page>

 

public class MyController {
  public String myValue { get; set; }

  public ApexPages.PageReference page2() {
    return Page.page2;
  }
}

 

All Answers

sfdcfoxsfdcfox

Use the same Controller and Extensions in both pages, and your data will automatically transport itself between pages when you use a PageReference. Check the manual for details.

 

Edit:

 

Example!

 

<apex:page standardController="MyObj__c" extensions="MyExt" title="Page 1">
  <apex:form>
    <apex:inputField value="{!MyObj__c.MyField__c}"/>
    <apex:commandButton action="{!page2}" value="Page 2"/>
  </apex:form>
</apex:page>
<apex:page standardController="MyObj__c" extensions="MyExt" title="Page 2">
  <apex:form>
    <apex:outputField value="{!MyObj__c.MyField__c}"/>
  </apex:form>
</apex:page>
public class MyExt {
   private ApexPages.StandardController controller;

   public MyExt(ApexPages.StandardController controller) {
      this.controller = controller;
   }

   public ApexPages.PageReference page2() {
      return Page.Page2;
   }
}

 

davidjbbdavidjbb

Hi Sfdcfox,

 

Thanks for your quick reply.

 

What if I want to store the Input Field in page1 in a variable that is declared in the Controller then print that variable (the controller variable) into another visualforce page.

sfdcfoxsfdcfox

Just use the same Controller for both pages, and the value will automatically transfer over. It's the same as I demonstrated, but the variable is held in the controller instead of a record.

davidjbbdavidjbb

Sorry, but i'm a bit new in development, do you mind providing example.

sfdcfoxsfdcfox
<apex:page title="Page 1" controller="MyController">
 <apex:form>
  <apex:inputText value="{!myValue}"/>
  <apex:commandButton action="{!page2}"/>
 </apex:form>
</apex:page>

 

<apex:page title="Page 2" controller="MyController">
 <apex:form>
  <apex:outputText value="{!myValue}"/>
 </apex:form>
</apex:page>

 

public class MyController {
  public String myValue { get; set; }

  public ApexPages.PageReference page2() {
    return Page.page2;
  }
}

 

This was selected as the best answer
davidjbbdavidjbb

I think I got you confused. 

 

in the first page i want myobj_value

 

and in the second page i want myValue