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
aegirthaegirth 

Controller values net set from VF Page

Hi

I have a controller that exposes a custom class, and a VF page that accepts input from the user, saves those values in a controller variable and uses them to call an external webservice, retrieve a list of responses in JSON format and parses them to class objects, and uses a data table to display them on the page.  So far, so good. The parse code works, but the part where I set values in the controller from user input fails.  When I say fails, it means the values are always empty and return null.  

The controller values are 
public String mobileNumber {get;set;}
public String month {get;set;}

I have tried quite a few things, moved the constructor around, tried an empty contructor, tried to set immediate=false on the command button, moved the button to it's own actionRegion.  To it's own <apex:form>.  All to no avail.

VF Page:

<apex:page showHeader="false" sidebar="false" controller="VF_WS_SMSNotification">
	<apex:sectionHeader title="SMS List" subtitle="List" />
	<apex:pageBlock>
	<apex:form>
	Phonenumber  <apex:inputText id="phoneno" value="{!mobileNumber}" label="number"/>
	Months: <apex:selectList size="1" id="months" value="{!month}">
	  	<apex:selectOption itemValue="1" itemDescription="1"/>
	  	<apex:selectOption itemValue="2" itemDescription="2"/>
	  	<apex:selectOption itemValue="3" itemDescription="3"/>
	  	<apex:selectOption itemValue="4" itemDescription="4"/>
	  	<apex:selectOption itemValue="5" itemDescription="5"/>
	  	<apex:selectOption itemValue="6" itemDescription="6"/>	
	  	</apex:selectList>
	  	</apex:form>
	  	</apex:pageBlock>
	  <apex:pageBlock>
	  <!--apex:outputPanel-->
	  <apex:form>
	  <apex:commandButton immediate="false" value="Press this" id="theButton" action="{!getList}" />
	  </apex:form>
	  
             <!--/apex:outputPanel-->                    
	</apex:pageBlock>

	<apex:pageBlock id="table" title="Notifications">
	
	<apex:dataTable value="{!smsList}" var="i" id="theTable" rowClasses="odd,even"

                       /* data table markup omitted  */
	</apex:dataTable>
	</apex:pageBlock>
</apex:page>

Controller code:

public with sharing class VF_WS_SMSNotification {

    //getters / setters 
     VF_WS_SMSNotification wnot {get;set;}
     public String mobileNumber {get;set;}   // this var is never set
     public String month {get;set;}               // this var is never set
     public List<SMS> smsList {get;set;}
     public String descr {get; set;}

     public VF_WS_SMSNotification()
      {
      mobileNumber='';
      month='';
      smsList=new List<SMS>();
      } 

 
      public class Output {
          public String xmlns_ns0 {get;set;}
          public List<SMS> SMS {get;set;}
     }
     
     public Output output;
 
     public class SMS {
          public String Text{get;set;}
          public String Status {get;set;}
          public String Type {get;set;}
          public String CreationDate {get;set;}
     } 

      //public SMS sms(){}

     

     
     /*  Parse function to generate instances of the output class, which contains 1 or more instances of the inner SMS class  */

     public static VF_WS_SMSNotification parse(String json) {
               String json2 = json.replace('ns0:', '');
               system.debug(json2);
               return (VF_WS_SMSNotification)System.JSON.deserialize(json2, VF_WS_SMSNotification.class);
     }       
     
    

    

      public List<VF_WS_SMSNotification.SMS> getSmslist(String phoneno, String months){

        phoneno =mobileNumber;
        months = month;
        system.debug('numer is:'+mobileNumber);
        system.debug('month is: '+month);
 
   
  /* Callout code omitted , not relevant  */
     
     String jsonResponse = res.getBody();
 
     

 
    
 
   VF_WS_SMSNotification wnot = new VF_WS_SMSNotification();
   wnot = parse(jsonResponse);

         List<VF_WS_SMSNotification.SMS> ist = new List<VF_WS_SMSNotification.SMS>();
       
           system.debug('________________Parsing SMS List: ');
        
           for(VF_WS_SMSNotification.SMS o: wnot.output.SMS){
              ist.add(o);
              system.debug('Text is: '+o.Text);
              system.debug('Status is: '+o.Status);
              system.debug('Type is: '+o.Type);
              system.debug('Creation date is: '+o.CreationDate); 
              system.debug('______________________________List size is NOW: '+ist.size());
           
         }

         for(integer i = 0;i<ist.size();i++){

            system.debug('Here is the data: Text is:'+ist[i].Text+' and status is '+ist[i].Status+' and Type is '+ist[i].Type+' and date is '+ist[i].CreationDate);
         }
 
 
     return ist;
 
      }   


      public PageReference getList(){


        system.debug('INSIDE VF BUTTON CALL___ :numer is:'+mobileNumber);
        system.debug('INSIDE VF BUTTON CALL___ :month is: '+month);
        smsList = getSmslist(mobileNumber,month);
        return null;

        

      }
}
Is there some fundamental n00b mistake going on here or am I misunderstanding how controller variables get set from a VF page?
kevin lamkevin lam
Have you tried moving the commandButton to the form with those input fields?
aegirthaegirth
That was exactly what was wrong. Thanks for that tip , works fine now. Must be some security issue, inputs within a tag are hidden from actions that are encapsulated within another tag