0
public with sharing class RentedBike {
    public cust_Ride__c custRide {get;set;}  
    public map<string,Object> inputMap {get;set;}
    public RentedBike() {
        custRide = new cust_Ride__c();
    }

    
    
    public void Savevalue() {
        Map<string,Object> inputMap =new Map<string,Object>();
        inputMap.put('customer__c',custRide.customer__c);
        inputMap.put('Starting_KM__c',custRide.Starting_KM__c);
        inputMap.put('Ending_KM__c',custRide.Ending_KM__c);
        inputMap.put('Ride_Starting_Date__c',custRide.Ride_Starting_Date__c);
        inputMap.put('Ride_Ending_Date__c',custRide.Ride_Ending_Date__c);
        inputMap.put('Active_Price__c',80);
        inputMap.put('Previous_Price__c',75);
        inputMap.put('Current_Price__c',84);
        system.debug(inputMap);
        next(inputMap);
    }
    
    public PageReference next( Map<string,Object> inputMap) {
        system.debug('inputMap--'+inputMap);
        PageReference p = new PageReference('/apex/RentedVP2');
        p.setRedirect(false);
        return p;
        
    }
    
}

PAGE 1

<apex:page controller="RentedBike">
    <apex:form >
        


        
        <apex:pageblock title="RentedBikeBilling">
            
            <apex:pageblocksection columns="1" title="RentedBikeBilling" collapsible="false" >
                
                
                
                <apex:pageblocksectionitem >
                    <apex:outputLabel >customer name</apex:outputLabel>
                    <apex:inputField value="{!custRide.customer__c}" />
                </apex:pageblocksectionitem>
                
                
                <apex:pageblocksectionitem >
                    <apex:outputLabel >Starting KM</apex:outputLabel>
                    <apex:inputField value="{!custRide.Starting_KM__c}" />
                </apex:pageblocksectionitem>
                
                <apex:pageblockSectionItem >
                    <apex:outputLabel >Ending KM</apex:outputLabel>
                    <apex:inputField value="{!custRide.Ending_KM__c}" />
                </apex:pageblockSectionItem>
                
                <apex:pageblockSectionItem >
                    <apex:outputLabel >RideSatrtingDate</apex:outputLabel>
                    <apex:inputField value="{!custRide.Ride_Starting_Date__c}" />
                </apex:pageblockSectionItem>
                
                <apex:pageblockSectionItem >
                    <apex:outputLabel >RideEndingDate</apex:outputLabel>
                    <apex:inputField value="{!custRide.Ride_Ending_Date__c}" />
                </apex:pageblockSectionItem>

                 <apex:commandButton action="{!Savevalue}" value="Save"  /> 
                <!--<apex:commandButton action="{!next}" value="next"/>-->
                
                
                
            </apex:pageblocksection>
        </apex:pageblock>
    </apex:form>
</apex:page>

page 2

<apex:page Controller="RentedBike">
    <apex:form >
        <apex:pageBlock >

           <apex:repeat value="{!inputMap}" var="inputMapKey">
        <apex:outputText value="{!inputMapKey}" />
        <apex:outputText value="{!inputMap[inputMapKey]}" /><br/>
      </apex:repeat>
          
            

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

1 Answer 1

1

You need to store inputMap inside the controller; since both pages share the same controller, the second page will automatically remember the values from the first. Note that you "shadowed" the variable in your Savevalue method, which was the primary problem. In addition, your next method, being called from Savevalue, didn't return a PageReference to the Visualforce runtime, so no redirect occurred. Here's a fixed version of your code:

public with sharing class RentedBike {
    public cust_Ride__c custRide {get;set;}  
    public map<string,Object> inputMap {get;set;}
    public RentedBike() {
        custRide = new cust_Ride__c();
        inputMap = new map<string,Object>();
    }
    public PageReference Savevalue() {
        inputMap.put('customer__c',custRide.customer__c);
        inputMap.put('Starting_KM__c',custRide.Starting_KM__c);
        inputMap.put('Ending_KM__c',custRide.Ending_KM__c);
        inputMap.put('Ride_Starting_Date__c',custRide.Ride_Starting_Date__c);
        inputMap.put('Ride_Ending_Date__c',custRide.Ride_Ending_Date__c);
        inputMap.put('Active_Price__c',80);
        inputMap.put('Previous_Price__c',75);
        inputMap.put('Current_Price__c',84);
        PageReference p = new Page.RentedVP2;
        p.setRedirect(false);
        return p;
    }
    
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .