• Vijosh
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
Hi,

I am new to apex and visualforce.I have written a simple code and in this code the when i click on the button the associated method is not called.
The code below is just a sample code with static assigments, the main problem is whenever I add a selectoption in my code the methods in the controllers do not work and I am unable to submit/commit the record.


<apex:page controller="test_controller">
    <apex:form >
        <apex:selectList value="{!countries}" multiselect="false" size="1">
           <apex:selectOptions value="{!Items}"></apex:selectOptions> 
        </apex:selectList><p/>
        <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
        
    </apex:form>
</apex:page>
public class test_controller
{
        public String[] countries = new String[]{};
                    
        public PageReference test() 
       {
             test__c t=new test__c();
             t.textfield__c='string';
             insert t;
        }
      
        public List<SelectOption> getItems() {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('US','US'));
            options.add(new SelectOption('CANADA','Canada'));
            options.add(new SelectOption('MEXICO','Mexico'));
            return options;
        }
            
        public String[] getCountries() {
            return countries;
        }

}




Any suggestions would be helpful.

Regards,
Vijosh
Hi all,

I have created a visualforce  page and wanted to pass current values from feilds of this page to the controller.
The scenario is like, on the screen we have three fields and the user puts in some value to those fields. Now this values entered in the fields should be passed to the variable in the controller. These fields are not binded to any object. 
Now I able to pass the Static value to the controller for eg. <apex:param name="two" value="Vijosh" />. But how to pass Dynamic values from  to the controller.


<apex:page controller="TestFieldPopulationController" id="pg">
    <script type="text/javascript">
        function userInput(){
            var UInput=document.getElementById("{!$Component.pg.frm.in}").value;
            return UInput;
        }
       
    </script>
   
    <apex:form id="frm">
        <apex:actionFunction name="hitMe" action="{!iWantMyJSValues}" rerender="jsvalues">
            <apex:param name="one" value="" />
            <apex:param name="two" value="Vijosh" />
            <apex:param name="three" value="Keyboard" />
           
        </apex:actionFunction>
       
        <apex:outputPanel id="jsvalues">
            <apex:panelGrid columns="2">
                Value One:<apex:inputText id="in" value="{!valueOne}"/>
                Value Two:<apex:inputText value="{!valueTwo}" />  
                Value Three:<apex:inputText value="{!valueThree}" />
               
<apex:commandButton value="Submit" onclick="hitMe(userInput())"/>
         </apex:panelGrid>       
        </apex:outputPanel>
   </apex:form>
</apex:page>

Regards,
Vijosh
  • April 04, 2014
  • Like
  • 0
Hi,

I am new to apex and visualforce.I have written a simple code and in this code the when i click on the button the associated method is not called.
The code below is just a sample code with static assigments, the main problem is whenever I add a selectoption in my code the methods in the controllers do not work and I am unable to submit/commit the record.


<apex:page controller="test_controller">
    <apex:form >
        <apex:selectList value="{!countries}" multiselect="false" size="1">
           <apex:selectOptions value="{!Items}"></apex:selectOptions> 
        </apex:selectList><p/>
        <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
        
    </apex:form>
</apex:page>
public class test_controller
{
        public String[] countries = new String[]{};
                    
        public PageReference test() 
       {
             test__c t=new test__c();
             t.textfield__c='string';
             insert t;
        }
      
        public List<SelectOption> getItems() {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('US','US'));
            options.add(new SelectOption('CANADA','Canada'));
            options.add(new SelectOption('MEXICO','Mexico'));
            return options;
        }
            
        public String[] getCountries() {
            return countries;
        }

}




Any suggestions would be helpful.

Regards,
Vijosh
public Component.Apex.InputCheckbox createchkbox()
{
Component.Apex.InputCheckbox chk=new Component.Apex.InputCheckbox();

Component.Apex.InputCheckbox test=new Component.Apex.InputCheckbox();
        
            String str=NULL;
      String type= 'FieldObject__c';  // Say,this is my object
      Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
      Schema.SObjectType leadSchema = schemaMap.get(type);
      Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();
          
      


  
        for (String fieldName: fieldMap.keySet())
       
             { 
                  String mylabel;
                      //It provides to get the object fields label.
                  mylabel = fieldMap.get(fieldName).getDescribe().getLabel();
                  
                 Schema.DisplayType myType=fieldMap.get(fieldName).getDescribe().getType();
                  
                   
       
       
                             if (myType == Schema.DisplayType.BOOLEAN)
                                
                             {
                           
                                
                                             if(fieldName.endsWith('__c'))
                                             {
                                              
                                          str='\'{!'+type+'.'+fieldName+'}\'';
                                           
                                             }
                            }
  
  
                    }
   
       
       
        chk.expressions.value=str;
        return chk;
       
       
      

}

Above is my code in which I am trying to the string str as a expression value to checkbox. As I am trying to do this, I am getting the error 
"System.VisualforceException: Value assigned to expression field is not valid for <apex:inputCheckbox value>"

Kindly help me out.
Hi all,

I have created a visualforce  page and wanted to pass current values from feilds of this page to the controller.
The scenario is like, on the screen we have three fields and the user puts in some value to those fields. Now this values entered in the fields should be passed to the variable in the controller. These fields are not binded to any object. 
Now I able to pass the Static value to the controller for eg. <apex:param name="two" value="Vijosh" />. But how to pass Dynamic values from  to the controller.


<apex:page controller="TestFieldPopulationController" id="pg">
    <script type="text/javascript">
        function userInput(){
            var UInput=document.getElementById("{!$Component.pg.frm.in}").value;
            return UInput;
        }
       
    </script>
   
    <apex:form id="frm">
        <apex:actionFunction name="hitMe" action="{!iWantMyJSValues}" rerender="jsvalues">
            <apex:param name="one" value="" />
            <apex:param name="two" value="Vijosh" />
            <apex:param name="three" value="Keyboard" />
           
        </apex:actionFunction>
       
        <apex:outputPanel id="jsvalues">
            <apex:panelGrid columns="2">
                Value One:<apex:inputText id="in" value="{!valueOne}"/>
                Value Two:<apex:inputText value="{!valueTwo}" />  
                Value Three:<apex:inputText value="{!valueThree}" />
               
<apex:commandButton value="Submit" onclick="hitMe(userInput())"/>
         </apex:panelGrid>       
        </apex:outputPanel>
   </apex:form>
</apex:page>

Regards,
Vijosh
  • April 04, 2014
  • Like
  • 0