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
Uves RavatUves Ravat 

Assignto param

<apex:page showheader="false" sidebar="false" controller="searchFlightsController" standardstylesheets="false">
<apex:form style="font-size:13pt">
<h1 style="text-align:center;color:black;"> Search for Flights </h1>
<apex:pageBlock title="Search for Flights">
<apex:pageblockSection >
<apex:inputField value="{!flight.departureCountry__c}" /><br/>
<apex:inputField value="{!flight.Departure__c}" />
<apex:inputField value="{!flight.destinationCountry__c}" /><br/>
<apex:inputField value="{!flight.Destination__c}" />
<apex:inputField value="{!flight.dayOfDeparture__c}"/><br/>
<apex:inputField value="{!flight.timeOfDeparture__c}" />
<apex:inputField value="{!flight.dayOfArrival__c}" /><br/>
<apex:inputField value="{!flight.timeOfArrival__c}" /><br/>
<apex:commandButton rerender="FlightsDetail" action="{!searchFlights}" value="Search for Flights">
<apex:param value="{!flight.dayOfDeparture__c}" assignTo="{!dayOfDep}"/>
</apex:commandButton>
</apex:pageblockSection>
<apex:pageblockSection >
<apex:outputPanel id="FlightsDetail">
<apex:repeat value="{!flightsResult}" var="flightres">
<p>{!flightres.timeOfArrival__c} </p>
</apex:repeat>
</apex:outputPanel>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Hi, i am having an error assigning the day the user selects (from a list) from a visualforce page. Whatever the day the user selects i want to use it in my controller. the problem is the value is always null. Any helps what i am doing wrong. (higlighted red whats not working) If i make the value monday it works. so i am not getting the value what the user selects i think

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
tukmoltukmol

hi, just a thought. instead of going thru the param thingy...

 

since the value of select list (<apex:inputField value="{!flight.dayOfDeparture__c}"/>) is supposed to be posted back to the conroller, can't you just use the value of flight.dayOfDeparture__c directly in your controller?

 

i.e.

...WHERE dayOfDeparture__c = :this.flight.dayOfDeparture__c];

 

All Answers

SeAlVaSeAlVa

Try replacing 

<apex:param value="{!flight.dayOfDeparture__c}" assignTo="{!dayOfDep}"/>

 by

<apex:param name="x" value="{!flight.dayOfDeparture__c}" assignTo="{!dayOfDep}"/>
Uves RavatUves Ravat

I tried the solution above and still had the same error

SeAlVaSeAlVa

is 

<apex:inputField value="{!flight.dayOfDeparture__c}"/>

 returning/displaying anything? (on controller-side, using System.debug or View State, etc)

Uves RavatUves Ravat

i am selecting a day from picklist (monday, tuesday......sunday) from object class.

Devendra@SFDCDevendra@SFDC

Hi,

 

There is some problem involved into the <apex:commandButton> when you use <apex:param>

 

You will have to reRender the hiddenBlock to solve this issue.

 

Here is the blog from Jeff Douglas to solve this issue.

 

Please refer the above blog.

 

Hope this helps :)

 

Thanks,

Devendra

Uves RavatUves Ravat

i cant use rerender because i am already using that...do u need to see my class to help me out

Devendra@SFDCDevendra@SFDC

 

Can you please post your VF and Apex code?

 

Thanks,

Devendra

Uves RavatUves Ravat

This is my VF page below. The VF page is used to search for flights. The user has so has to input data on the visualforce page and based on that it will do a search. For now i am doing the search based on the dayOfDeparture which a picklist the user has to choose from (monday to sunday). the problem is i think i am correctly getting the information from the inputfield dayOfDeparture, therefore dayOfDep returns nothing, Here is the VF page

 

<apex:page showheader="false" sidebar="false" controller="searchFlightsController" standardstylesheets="false">
    <apex:form style="font-size:13pt">
        <h1 style="text-align:center;color:black;">  Search for Flights </h1>
            <apex:pageBlock title="Search for Flights"> 
                <apex:pageblockSection >
                
                    <apex:inputField value="{!flight.departureCountry__c}" /><br/>
                    <apex:inputField value="{!flight.Departure__c}" />
                    <apex:inputField value="{!flight.destinationCountry__c}" /><br/>
                    <apex:inputField value="{!flight.Destination__c}" />
                    <apex:inputField value="{!flight.dayOfDeparture__c}"/><br/>
                    <apex:inputField value="{!flight.timeOfDeparture__c}" />
                    <apex:inputField value="{!flight.dayOfArrival__c}" /><br/>
                    <apex:inputField value="{!flight.timeOfArrival__c}" /><br/>
                    <apex:commandButton action="{!searchFlights}"  rerender="FlightsDetail" value="Search for Flights">
                        <apex:param name="dayOfDep" value="{!flight.dayOfDeparture__c}" assignTo="{!dayOfDep}"/>
                    </apex:commandButton>    
                </apex:pageblockSection>
                <apex:pageblockSection >
                    <apex:outputPanel id="FlightsDetail">
                        <apex:repeat value="{!flightsResult}" var="flightres">
                            <p>{!flightres.timeOfArrival__c} </p>
                        </apex:repeat>
                    </apex:outputPanel>
                </apex:pageblockSection>
            </apex:pageBlock>
            <apex:pageBlock id="hiddenBlock" rendered="false"></apex:pageBlock>
    </apex:form>
</apex:page>
public class searchFlightsController{
    
    private ApexPages.StandardController controller {get; set;}
    public Flights__c flight {get; set;}
    public searchFlightsController() {
        this.flight = new Flights__c();   
    }
    
    public String dayOfDep { get; set; }
    
    //public String timeOfDep { get; set; }
    public List<Flights__c> flightsResult { get; set; }
    
    public void searchFlights()
    {
        System.debug(dayOfDep);
        //String dayOfDep = 'Monday';
        flightsResult = [SELECT Departure__c, Destination__c, dayOfDeparture__c, timeOfDeparture__c, departureCountry__c,
                dayOfArrival__c, timeOfArrival__c, destinationCountry__c FROM Flights__c 
                WHERE dayOfDeparture__c = :dayOfDep];
        //return null;
    }
}
Devendra@SFDCDevendra@SFDC

Hi,

 

Try this:

 

<apex:page showheader="false" sidebar="false" controller="searchFlightsController" standardstylesheets="false">
    <head>
	<script type="text/javascript">
		function doSearch() {
        searchServer(
          	 document.getElementById("deptId").options[document.getElementById("deptId").selectedIndex].value
	  );
	}
	</script>
    </head>	
	<apex:form style="font-size:13pt">
		<apex:actionFunction name="searchServer" action="{!runSearch}" rerender="FlightsDetail">
			<apex:param name="deptId" value=""/>
		<apex:actionFunction>
        <h1 style="text-align:center;color:black;">  Search for Flights </h1>
            <apex:pageBlock title="Search for Flights"> 
                <apex:pageblockSection >
                
                    <apex:inputField value="{!flight.departureCountry__c}" /><br/>
                    <apex:inputField value="{!flight.Departure__c}" />
                    <apex:inputField value="{!flight.destinationCountry__c}" /><br/>
                    <apex:inputField value="{!flight.Destination__c}" />
                    <apex:inputField value="{!flight.dayOfDeparture__c}" id="deptId"/><br/>
                    <apex:inputField value="{!flight.timeOfDeparture__c}" />
                    <apex:inputField value="{!flight.dayOfArrival__c}" /><br/>
                    <apex:inputField value="{!flight.timeOfArrival__c}" /><br/>
                   
                   <apex:commandButton onClick="if(!doSearch()) return false;" reRender="FlightsDetail" value="Search for Flights" /> 
            
                </apex:pageblockSection>
                <apex:pageblockSection >
                    <apex:outputPanel id="FlightsDetail">
                        <apex:repeat value="{!flightsResult}" var="flightres">
                            <p>{!flightres.timeOfArrival__c} </p>
                        </apex:repeat>
                    </apex:outputPanel>
                </apex:pageblockSection>
            </apex:pageBlock>
            <apex:pageBlock id="hiddenBlock" rendered="false"></apex:pageBlock>
    </apex:form>
</apex:page>

 

public String strDept;

strDept = ApexPages.CurrentPage().getParameters().get('deptId');

 Now use strDept in the query.

 

Thanks,

Devendra

Uves RavatUves Ravat

Hi,

 

I did what you requested me to do, but this time the button didnt do anything at all. here is the code i used

 

<apex:page showheader="false" sidebar="false" controller="searchFlightsController" standardstylesheets="false">
    <head>
    <script type="text/javascript">
        function doSearch() {
        searchServer(
             document.getElementById("deptId").options[document.getElementById("deptId").selectedIndex].value
      );
    }
    </script>
    </head>
    <apex:form style="font-size:13pt">
        <apex:actionFunction name="searchServer" action="{!searchFlights}" rerender="FlightsDetail">
            <apex:param name="deptId" value=""/>
        </apex:actionFunction>
        <h1 style="text-align:center;color:black;">  Search for Flights </h1>
            <apex:pageBlock title="Search for Flights">
                <apex:pageblockSection >
                
                    <apex:inputField value="{!flight.departureCountry__c}" /><br/>
                    <apex:inputField value="{!flight.Departure__c}" />
                    <apex:inputField value="{!flight.destinationCountry__c}" /><br/>
                    <apex:inputField value="{!flight.Destination__c}" />
                    <apex:inputField value="{!flight.dayOfDeparture__c}" id="deptId"/><br/>
                    <apex:inputField value="{!flight.timeOfDeparture__c}" />
                    <apex:inputField value="{!flight.dayOfArrival__c}" /><br/>
                    <apex:inputField value="{!flight.timeOfArrival__c}" /><br/>
                   
                   <apex:commandButton onClick="if(!doSearch()) return false;" reRender="FlightsDetail" value="Search for Flights" />
            
                </apex:pageblockSection>
                <apex:pageblockSection >
                    <apex:outputPanel id="FlightsDetail">
                        <apex:repeat value="{!flightsResult}" var="flightres">
                            <p>{!flightres.timeOfArrival__c} </p>
                        </apex:repeat>
                    </apex:outputPanel>
                </apex:pageblockSection>
            </apex:pageBlock>
            <apex:pageBlock id="hiddenBlock" rendered="false"></apex:pageBlock>
    </apex:form>
</apex:page>

 and the apex class

public class searchFlightsController{
    
    private ApexPages.StandardController controller {get; set;}
    public Flights__c flight {get; set;}
    public searchFlightsController() {
        this.flight = new Flights__c();   
    }
    
    public String dayOfDep {get; set;}
    
    
    //public String timeOfDep { get; set; }
    public List<Flights__c> flightsResult { get; set; }
    
    public void searchFlights()
    {
        dayOfDep = ApexPages.CurrentPage().getParameters().get('deptId');
        System.debug(dayOfDep);
        //String dayOfDep = 'Monday';
        flightsResult = [SELECT Departure__c, Destination__c, dayOfDeparture__c, timeOfDeparture__c, departureCountry__c,
                dayOfArrival__c, timeOfArrival__c, destinationCountry__c FROM Flights__c 
                WHERE dayOfDeparture__c = :dayOfDep];
        //return null;
    }
}

 

Thanks again for you help

tukmoltukmol

hi, just a thought. instead of going thru the param thingy...

 

since the value of select list (<apex:inputField value="{!flight.dayOfDeparture__c}"/>) is supposed to be posted back to the conroller, can't you just use the value of flight.dayOfDeparture__c directly in your controller?

 

i.e.

...WHERE dayOfDeparture__c = :this.flight.dayOfDeparture__c];

 

This was selected as the best answer