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
Karthik ManoKarthik Mano 

Unable to get the set value

Hi , I am using a single controller for 2 vf pages .What i am doing is the user will enter values in first page and once they click search , only the matching trains will be available in the data table with check box in another page.

The problem is the values aren't getting set in the instance pass. **  getting null values in pass.from__c , pass.to__c and pass.Journey_Date__c in the if loop of controller. Please help !

 

1st page :

<apex:page standardController="Train_Details__c" extensions="RailwayReserveNew">
 <apex:sectionHeader title="Passenger Details Edit" subtitle="New Passenger Details"/>
 <apex:form >
 <apex:pageBlock title="Passenger Details Edit">
 <apex:pageBlockSection columns="1" >   
 <apex:inputField value="{!pass.Booker_Name__c}"  />
 <apex:inputField value="{!pass.Total_Senior_Citizens__c}"  />
<apex:inputField value="{!pass.Total_Children_Age_below_6__c}"  />
<apex:inputField value="{!pass.Total_Passengers__c}"  />
<apex:inputField value="{!pass.From__c}"  />
<apex:inputField value="{!pass.To__c}"  />
<apex:inputField value="{!pass.Journey_Date__c}"  />
<apex:inputField value="{!pass.Fare__c}"  />

</apex:pageBlockSection>
<apex:pageBlockButtons >
 <apex:commandButton value="search" action="{!dosearch}"/>
 <apex:commandButton value="save" action="{!save}"/>
 </apex:pageBlockButtons>
  </apex:pageBlock>
  </apex:form>
</apex:page>

Controller :

 

public  class RailwayReserveNew {

List<trainwrapper> wrapperList=new List<trainwrapper>();
List<Passenger_Details__c> passList=new List<Passenger_Details__c>([SELECT From__c,To__c,Journey_Date__c FROM Passenger_Details__c]);
List<Train_Details__c> selectedTrains=new List<Train_Details__c>();
List<Train_Details__c> trainDetails=new List<Train_Details__c>([select Name,Starting_Point__c,Destination__c,EveryDay__c,Monday__c,Tuesday__c,Wednesday__c,Thursday__c,Friday__c,Saturday__c,Sunday__c FROM Train_Details__c]);
private final Train_Details__c acct;


public Passenger_Details__c pass{
get;
private set;}


public RailwayReserveNew(ApexPages.StandardController stdController) {
        this.acct = (Train_Details__c)stdController.getRecord();
            Passenger_Details__c pass=new Passenger_Details__c();

            }

 public  List<trainwrapper> getavailabletrains() {


for(Train_Details__c t: trainDetails) {

if(t.Starting_Point__c==pass.from__c && t.Destination__c==pass.to__c) {

if(t.EveryDay__c==true) {

 

wrapperList.add(new trainwrapper(t));
}

 

else if(t.EveryDay__c==false) {

String journeyDay = Datetime.newInstance(pass.Journey_Date__c, Time.newInstance(0, 0, 0, 0)).format('E').substring(0, 2);
system.debug('**************************' + journeyDay);

if(journeyDay=='Mo' && t.Monday__c==true) {
system.debug('**************************' + journeyDay);
wrapperList.add(new trainwrapper(t));
}
if(journeyDay=='Tu' && t.Tuesday__c==true) {
wrapperList.add(new trainwrapper(t));
}
if(journeyDay=='We' && t.Wednesday__c==true) {
wrapperList.add(new trainwrapper(t));
}
if(journeyDay=='Th' && t.Thursday__c==true) {
wrapperList.add(new trainwrapper(t));
}
if(journeyDay=='Fr' && t.Friday__c==true) {
wrapperList.add(new trainwrapper(t));
}
if(journeyDay=='Sa' && t.Saturday__c==true) {
wrapperList.add(new trainwrapper(t));
}
if(journeyDay=='Su' && t.Sunday__c==true) {
wrapperList.add(new trainwrapper(t));
}

}
}

}
return wrapperList;

}

public pagereference GetSelected() {
selectedTrains.clear();
for(trainwrapper trainwrapper:wrapperList)
if(trainwrapper.selected==true) {
selectedTrains.add(trainwrapper.trainwrap);
}
return null;

}

public List<Train_Details__c> GetSelectedTrains()
    {
        if(selectedTrains.size()>0)
        return selectedTrains;
        else
        return null;
    }

 

 

public class trainwrapper  {

public Train_Details__c trainwrap{get;set;}
public boolean selected {get;set;}

public trainwrapper(Train_Details__c tr)
{

trainwrap=tr;
selected=false;
}

}

public pagereference dosearch(){
return page.railwayreserve;
}

public pagereference save() {
upsert (pass);
return null;
}

}

2nd page :

 <apex:page standardController="Train_Details__c" extensions="RailwayReserveNew">

<apex:form >
<apex:pageBlock title="Available Trains"> 
<apex:dataTable value="{!availabletrains}" var="trains" columns="3" border="2" cellpadding="2">

<apex:column >
<apex:inputCheckbox value="{!trains.selected}" id="checkedone">
<apex:actionSupport event="onclick" action="{!GetSelected}" rerender="Selected_Train"/>
</apex:inputCheckbox></apex:column>

<apex:column headerValue="Name" value="{!trains.trainwrap.Name}"/>
<apex:column headerValue="From" value="{!trains.trainwrap.Starting_Point__c}"/>
<apex:column headerValue="To" value="{!trains.trainwrap.Destination__c}"/>

</apex:dataTable>


<apex:pageBlock Title="Selected Train" id="Selected_Train">
<apex:dataTable value="{!SelectedTrains}" var="s" columnswidth="50px,50px" cellpadding="4" border="1">
<apex:column headervalue="Name" value="{!s.Name}" />
<apex:column headervalue="From" value="{!s.Starting_Point__c}" />
<apex:column headervalue="To" value="{!s.Destination__c}" />
</apex:dataTable>
</apex:pageBlock>

 


</apex:pageBlock>

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

mohimohi

Its Problem of Initialization,

when you go to another Page again Constructer will execute and Pass=new will became null so when you try to access it it will contain null Value, remove pass =new line from constructor.

 

If this is solution for you Please mark as accepted