+ Start a Discussion
karthic sankar 9karthic sankar 9 

how to pass value from controller to visual force page?

Hi Experts,

I have a controller like below.

public class paramtest {
    public string value { get; set;}
    public string Availability_Mon { get; set;}
    public string Availability_Tue { get; set;}
    public string Availability_Wed { get; set;}
    public string Availability_Thur { get; set;}
    public string Availability_Fri { get; set;}
    
    public map<String,String> AvailabilityMap = new map<String, String>();
    
public void loadValues()
    {
    AvailabilityMap.put('Monday', 'Karthic1');
    AvailabilityMap.put('Tuesday', 'Karthic2');
    AvailabilityMap.put('Wednesday', 'Karthic3');
    AvailabilityMap.put('Thursday', 'Karthic4');
    AvailabilityMap.put('Friday', 'Karthic5');
    assignValues();
    }
    
    public void assignValues()
    {
    Availability_Mon = AvailabilityMap.get('Monday');
    Availability_Tue = AvailabilityMap.get('Tuesday');
    Availability_Wed = AvailabilityMap.get('Wednesday');
    Availability_Thur = AvailabilityMap.get('Thursday');
    Availability_Fri = AvailabilityMap.get('Friday');
    }
}

My VF is like below.

<apex:page controller="paramtest" docType="html-5.0">
<apex:form >
<apex:pageBlock title="Core Categories" id="pgCoreCategories">
           <table border="0.3px" width="100%" height="80%" style="page-break-inside:auto; text-align: center;">
                   <tr style="text-align: center;">
                       <th style="font-size:125%;"></th>
                       <th style="font-size:125%; text-align: center;">Standard Timing</th>
                       <th style="font-size:125%; text-align: center;">Monday</th>
                       <th style="font-size:125%; text-align: center;">Tuesday</th>
                       <th style="font-size:125%; text-align: center;">Wednesday</th>
                       <th style="font-size:125%; text-align: center;">Thursday</th>
                       <th style="font-size:125%; text-align: center;">Friday</th>
                       <th style="font-size:125%; text-align: center;">During Week</th>
                   </tr>
                  <tr>
                       <th style="font-size:125%;">Pre-Vet Reviews</th>
                       <th style="font-size:125%; text-align: center;">180 Mins</th>
                       <td><apex:inputText value="{!Availability_Mon}" id="inputPrevetReviewMon" html-class="CoreMonday" onkeyup="testMethod()"  style="text-align: center;" html-placeholder="Enter # of files"/></td>
                       <td><apex:inputText value="{!Availability_Tue}" id="inputPrevetReviewTue" html-class="CoreTuesday" onkeyup="testMethod()"  style="text-align: center;" html-placeholder="Enter # of files"/></td>
                       <td><apex:inputText value="{!Availability_Wed}" id="inputPrevetReviewWed" html-class="CoreWednesday" onkeyup="testMethod()" style="text-align: center;" html-placeholder="Enter # of files"/></td>
                       <td><apex:inputText value="{!Availability_Thur}" id="inputPrevetReviewThur" html-class="CoreThursday" onkeyup="testMethod()" style="text-align: center;"  html-placeholder="Enter # of files"/></td>
                       <td><apex:inputText value="{!Availability_Fri}" id="inputPrevetReviewFri" html-class="CoreFriday" onkeyup="testMethod()"  style="text-align: center;" html-placeholder="Enter # of files"/></td>
                       <td><apex:inputText value="{!Availability_Fri}" id="inputPrevetReviewDummy" html-class="CoreDummy" onkeyup="testMethod()" style="text-align: center;" html-placeholder="Enter # of files"/></td>
                       
                   </tr>
                </table>
                </apex:pageBlock>   
                


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

I wanted the assign the values from my map to all the input feilds available on my visualforce page on pageload.

Kindly help me on how to achieve this.

Regards
Karthic Sankar V P
Dushyant SonwarDushyant Sonwar
I think you forget to add the constructor that might be causing the issue.
 
public paramtest(){
		AvailabilityMap = new map<String, String>();
		loadValues();
}
Final code output be like this
 
public class paramtest {
    public string value { get; set;}
    public string Availability_Mon { get; set;}
    public string Availability_Tue { get; set;}
    public string Availability_Wed { get; set;}
    public string Availability_Thur { get; set;}
    public string Availability_Fri { get; set;}
    
    public map<String,String> AvailabilityMap;
	
	public paramtest(){
		AvailabilityMap = new map<String, String>();
		loadValues();
	}

public void loadValues()
    {
    AvailabilityMap.put('Monday', 'Karthic1');
    AvailabilityMap.put('Tuesday', 'Karthic2');
    AvailabilityMap.put('Wednesday', 'Karthic3');
    AvailabilityMap.put('Thursday', 'Karthic4');
    AvailabilityMap.put('Friday', 'Karthic5');
    assignValues();
    }
    
    public void assignValues()
    {
    Availability_Mon = AvailabilityMap.get('Monday');
    Availability_Tue = AvailabilityMap.get('Tuesday');
    Availability_Wed = AvailabilityMap.get('Wednesday');
    Availability_Thur = AvailabilityMap.get('Thursday');
    Availability_Fri = AvailabilityMap.get('Friday');
    }
}

 
Dushyant SonwarDushyant Sonwar
Karthik,

Did you try out with the solution I gave you? Does it solve your purpose?