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
Javier MaldonadoJavier Maldonado 

Help with my code - transfer information between Visualforce and Controller

Hello everyone...

I'm working now in a complex part of my developing app, which is a full custom code, so that I will try to do is:
- Compare 2 variable; 1 from a pick list field (Width), and the other one from a field (Max_Width)
- Get 3 types of result:
  * Width > Max_Width; pop up a message to avoid create the record "Please pick width less than Max_Width"
  * Width = Max_Width; show a section with two fields Long_Imperial(number) and Length_Units(picklist field)
  * Width < Max_Width; show a section with standard pick list length

I've developed this code below, but I have no idea how transfer data in between them... Can somebody show me some light or help me with this code?, I don't know, whether it is possible that I'm trying to do, or not...

Thanks in advance, any advice it will be welcome

----VISUALFORCE---
<apex:pageBlockSection title="Imperial System" columns="1" 
                                rendered="{!Customer_s_Price_List__c.System_Of_Measurement__c == 'Imperial System'
                                && ( Customer_s_Price_List__c.Product_Type__c == 'Fabric' || Customer_s_Price_List__c.Product_Type__c == 'Tape') }">
     <apex:pageBlockSectionItem >
        <apex:outputLabel >Width(inches)</apex:outputLabel>
        <apex:inputField value="{!Customer_s_Price_List__c.Wide_Imperial__c}"> 
           <apex:actionSupport event="onchange" reRender="check_width"/>
        </apex:inputField>                          
     </apex:pageBlockSectionItem> 
     
     <apex:outputPanel id="check_width">
        <apex:pageBlock rendered="{!Tape_Fabric}">
  
        </apex:pageBlock>
     </apex:outputPanel>
</apex:pageBlockSection>

--------APEX------------
<public boolean Compare_width{get;set;}
public decimal var_Max_Width {get; set;}

public PageReference Tape_Fabric(){
    var_Max_Width = cpl.Max_Width__c;
    
    //Convert String in Decimal
    String temp = var_width;
    Decimal var_width_dec = Decimal.valueOf(temp);
   
    if(var_width_dec > var_Max_Width ){
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select width '));
    }
    if(var_width_dec == var_Max_Width ){
        
    }
    if(var_width_dec < var_Max_Width ){
        List<SelectOption> options = new List<SelectOption>();
        var_width = cpl.Wide_Imperial__c;
        var_Max_Width = cpl.Max_Width__c;
        if(var_width <> null  || Test.isRunningtest() )
        {
            if((var_Product_Type =='Tape' || var_Product_Type =='Fabric') && (var_width =='1/4' || 
                                             var_width =='3/8' ) || Test.isRunningtest()){
                options.add(new SelectOption('18','18'));
                options.add(new SelectOption('3','3'));
                }
            if((var_Product_Type =='Tape' || var_Product_Type =='Fabric') && !(var_width =='1/4' || 
                                             var_width =='3/8' ) || Test.isRunningtest()){
                options.add(new SelectOption('36','36'));
                options.add(new SelectOption('3','3'));
                }
        }
        return option;
    }
}>

 
William TranWilliam Tran
You need to grab the record from the page in the controller in the constructor method.


public with sharing class testme {
private final account vfRecord ;
public testme(ApexPages.StandardController stdController) {
this.vfRecord = (account)stdController.getRecord();
}


If you still have issue, post the whole code.

thx
Javier MaldonadoJavier Maldonado
Hi William,

Thank you so much for your reply... Please see below the full code... THANKS...
 
<apex:page cache="true" expires="600" standardController="Customer_s_Price_List__c" extensions="Plasma_controller_SFDC" showHeader="false" tabStyle="account">
    <apex:sectionheader title="Customer Price"/>
    <chatter:feedwithfollowers entityId="{!Customer_s_Price_List__c.Id}"/>  
    <apex:form >   
        <apex:pageBlock id="OppPageBlock" mode="edit">
            <apex:pageMessages />                 
                <apex:pageBlockButtons >                 
                    <apex:commandButton value="Save" action="{!save}"/>
                    <apex:commandButton value="Cancel" action="{!cancel}"/>                        
                </apex:pageBlockButtons> 
            <apex:actionRegion >                                                                                                   
                <apex:pageBlockSection title="Basic Information" columns="1">                  
                   <apex:inputField value="{!Customer_s_Price_List__c.Account__c}" label="Account"/>                                            
                    <apex:pageBlockSectionItem >
                      <apex:outputLabel >Product Type</apex:outputLabel>
                      <apex:selectList size="1" multiselect="false" value="{!var_Product_Type}" required="true" style="width:140px;">
                         <apex:actionSupport reRender="test" event="onchange" action="{!test}"/>
                         <apex:selectOptions value="{!ListGroups}"/>
                      </apex:selectList>    
                    </apex:pageBlockSectionItem>
                    
                    <apex:pageBlockSectionItem > 
                    <apex:outputText value="Product Description" styleClass="labelCol vfLabelColTextWrap" />                    
                    <apex:outputPanel id="test" layout="block"> 
                        <apex:selectList size="1" multiselect="false" value="{!Customer_s_Price_List__c.Product_Description__c}" style="width:300px;auto">
                          <apex:selectOptions value="{!ListProducts}"/>
                        </apex:selectList> 
                    </apex:outputPanel>
                    </apex:pageBlockSectionItem> 
                    
                    <!--Select Compound-->
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel value="Currency"/>                         
                        <apex:outputLabel >                             
                        <apex:inputField value="{!Customer_s_Price_List__c.Currency__c}" style="width:140px;">                                 
                          <apex:actionSupport event="onchange" rerender=" OppPageBlock " status="Product Type"/>                           
                        </apex:inputField>                             
                        <apex:actionStatus startText="applying value..." id="Currency__c"/>                          
                        </apex:outputLabel>                    
                    </apex:pageBlockSectionItem>
                    
                    <!--System of Measurements-->
                    <apex:pageBlockSectionItem >
                            <apex:outputLabel value="System Of Measurements"/>                         
                            <apex:outputLabel >                             
                            <apex:inputField value="{!Customer_s_Price_List__c.System_Of_Measurement__c}" style="width:140px;">                                 
                              <apex:actionSupport event="onchange" rerender=" OppPageBlock " status="Product Type"/>                           
                            </apex:inputField>                             
                            <apex:actionStatus startText="applying value..." id="System_Of_Measurement__c"/>                          
                            </apex:outputLabel>
                    </apex:pageBlockSectionItem>
                    
                    <apex:outputPanel style="display:none;visibility:hidden"> 
                        <apex:inputField value="{!Customer_s_Price_List__c.Product_Type__c}"/>
                    </apex:outputpanel>
                 
                 <!--If Select Compound-->
                 <apex:pageBlockSection title="Compound" columns="1" rendered="{!Customer_s_Price_List__c.Product_Type__c == 'Compound'}">   
                    <apex:pageBlockSectionItem >                                                            
                                <apex:outputLabel >Traverse Item ID</apex:outputLabel>
                                <apex:inputField value="{!Customer_s_Price_List__c.Traverse_Item_ID__c}"/>                          
                    </apex:pageBlockSectionItem>
                    <apex:pageBlockSectionItem >                                                            
                                <apex:outputLabel >Current Price</apex:outputLabel>
                                <apex:inputField value="{!Customer_s_Price_List__c.Current_Price__c}"/>                         
                    </apex:pageBlockSectionItem> 
                    <apex:pageBlockSectionItem >                                                            
                                <apex:outputLabel >Comments</apex:outputLabel>    
                               <apex:inputField value="{!Customer_s_Price_List__c.Comments__c}"/>                           
                    </apex:pageBlockSectionItem>
                 </apex:pageBlockSection>
                     
                 <!--Imperial System + Plasma & Laminated-->            
                 <apex:pageBlockSection title="Imperial System" columns="1" rendered="{!Customer_s_Price_List__c.System_Of_Measurement__c == 'Imperial System'
                 && ( Customer_s_Price_List__c.Product_Type__c == 'Plasma' || Customer_s_Price_List__c.Product_Type__c == 'Laminated / + 10')}">   
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel >Width(inches)</apex:outputLabel>
                        <apex:inputField value="{!Customer_s_Price_List__c.Wide_Imperial__c}"> 
                           <apex:actionSupport event="onchange" reRender="size"/>
                        </apex:inputField>                          
                    </apex:pageBlockSectionItem>
                    
                    <apex:pageBlockSectionItem >
                        <apex:outputText value="Length (Yards)" styleClass="labelCol vfLabelColTextWrap" /> 
                        <apex:outputPanel id="size">                                                    
                                <apex:selectList size="1" value="{!Customer_s_Price_List__c.Long_Imperial__c}">
                                   <apex:selectOptions value="{!length}"/>
                                </apex:selectList>
                        </apex:outputPanel> 
                    </apex:pageBlockSectionItem>
                    <apex:pageBlockSectionItem >                                                            
                                <apex:outputLabel >Traverse Item ID</apex:outputLabel>
                                <apex:inputField value="{!Customer_s_Price_List__c.Traverse_Item_ID__c}"/>                          
                    </apex:pageBlockSectionItem>
                    <apex:pageBlockSectionItem >                                                            
                                <apex:outputLabel >Current Price</apex:outputLabel>
                                <apex:inputField value="{!Customer_s_Price_List__c.Current_Price__c}"/>                         
                    </apex:pageBlockSectionItem> 
                    <apex:pageBlockSectionItem >                                                            
                                <apex:outputLabel >Comments</apex:outputLabel>    
                               <apex:inputField value="{!Customer_s_Price_List__c.Comments__c}"/>                           
                    </apex:pageBlockSectionItem> 
                 </apex:pageBlockSection>
                 
                 <!--Imperial System + FABRIC || TAPE-->            
                 <apex:pageBlockSection title="Imperial System" columns="1" rendered="{!Customer_s_Price_List__c.System_Of_Measurement__c == 'Imperial System'
                                               && ( Customer_s_Price_List__c.Product_Type__c == 'Fabric' || Customer_s_Price_List__c.Product_Type__c == 'Tape') }">
                     <apex:pageBlockSectionItem >
                            <apex:outputLabel >Width(inches)</apex:outputLabel>
                            <apex:inputField value="{!Customer_s_Price_List__c.Wide_Imperial__c}"> 
                               <apex:actionSupport event="onchange" reRender="check_width"/>
                            </apex:inputField>                          
                     </apex:pageBlockSectionItem> 
                     <apex:outputPanel id="check_width">
                         <!--<apex:pageBlock rendered="{!Tape_Fabric}">
                 
                 
                 
                  
                         </apex:pageBlock>--> 
                     </apex:outputPanel>
                 </apex:pageBlockSection> 
                 <!----------------------------->  
                 
                 
                 <!--Metric System-->        
                 <apex:pageBlockSection title="Metric System" columns="1" rendered="{!Customer_s_Price_List__c.System_Of_Measurement__c == 'Metric System'}">
                    <apex:pageBlockSectionItem >
                       <apex:outputLabel >Width(mm)</apex:outputLabel>
                       <apex:inputField value="{!Customer_s_Price_List__c.Wide_Metric__c}"> 
                       <apex:actionSupport event="onchange" reRender="size1"/>
                       </apex:inputField>  
                    </apex:pageBlockSectionItem>
                    
                    <apex:pageBlockSectionItem >
                        <apex:outputText value="Length (Meters)" styleClass="labelCol vfLabelColTextWrap" />    
                        <apex:outputPanel id="size1">                                                   
                                <apex:selectList size="1" value="{!Customer_s_Price_List__c.Long_Metric__c}">
                                 <apex:selectOptions value="{!length_m}" />
                                 </apex:selectList>
                        </apex:outputPanel> 
                    </apex:pageBlockSectionItem>
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel >Traverse Item ID</apex:outputLabel>
                        <apex:inputField value="{!Customer_s_Price_List__c.Traverse_Item_ID__c}"/>
                    </apex:pageBlockSectionItem>
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel >Current Price</apex:outputLabel>
                        <apex:inputField value="{!Customer_s_Price_List__c.Current_Price__c}"/>
                    </apex:pageBlockSectionItem>                    
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel >Comments</apex:outputLabel>    
                        <apex:inputField value="{!Customer_s_Price_List__c.Comments__c}"/>
                    </apex:pageBlockSectionItem>
                 </apex:pageBlockSection>
                </apex:pageBlockSection>
            </apex:actionRegion>            
        </apex:pageBlock>
    </apex:form>      
</apex:page>
 
public class Plasma_controller_SFDC{

    public Customer_s_Price_List__c cpl ;
    public Plasma_controller_SFDC(ApexPages.StandardController controller) {
        cpl = (Customer_s_Price_List__c)controller.getRecord();
        System.debug('!!!----!!!' + cpl);
        System.debug('!!!----!!!get accid-' + ApexPages.currentPage().getParameters().get('accid'));
        cpl.Account__c = ApexPages.currentPage().getParameters().get('accid');
    }
            
    public List<SelectOption> getListGroups() {
        List<SelectOption> options = new List<SelectOption> { new SelectOption('','-- Type --') };
        for(Schema.PicklistEntry gr:Customer_s_Price_List__c.Product_Type__c.getDescribe().getPicklistValues()) {
            options.add(new SelectOption(gr.getValue(),gr.getLabel()));
        }
        return options;
    }
    
    public string var_Product_Type { get; set; }
    public List<SelectOption> getListProducts() {
        cpl.Product_Type__c = var_Product_Type;
        System.debug('!!!' + ApexPages.currentPage().getParameters());
        List<SelectOption> options = new List<SelectOption>();
            if(var_Product_Type == null || var_Product_Type == ''){        
                if(!Test.isrunningTest()) {return options;}
            }
        options.add(new SelectOption('','-- Product --'));
        for(Product2 pr:[select id, Product_Name_Width__c from product2 where family = :var_Product_Type]) {
            options.add(new SelectOption(pr.id,pr.Product_Name_Width__c));            
        }
        return options;
    }      
    
    public string var_Product_Name { get; set; }
    public PageReference test(){
        System.debug('$$$' + var_Product_Type);
        return null;
    }
    
    public PageReference test2(){
        System.debug('$$$!!' + var_Product_Name);
        return null;
    }
    
    public string select_length {get; set;}  
    
    public List<SelectOption> getListWidth() {
        List<SelectOption> options = new List<SelectOption> { new SelectOption('','-- Width --') };
        for(Schema.PicklistEntry gr:Customer_s_Price_List__c.Wide_Imperial__c.getDescribe().getPicklistValues()) {
            options.add(new SelectOption(gr.getValue(),gr.getLabel()));
        }
        return options;
    }
    
    public string var_width {get; set;}
    
    public List<SelectOption> getlength(){
        List<SelectOption> options = new List<SelectOption>();
            var_width = cpl.Wide_Imperial__c;
            
            if(var_width <> null  || Test.isRunningtest() )
            {
                if(var_Product_Type =='Laminated / + 10' || Test.isRunningtest()){
                    options.add(new SelectOption('18','18'));
                    options.add(new SelectOption('9','9'));
                    }
                if(var_Product_Type =='Plasma' && (var_width =='1/4' || var_width =='3/8' ) || Test.isRunningtest()){
                    options.add(new SelectOption('18','18'));
                    options.add(new SelectOption('9','9'));
                    }
                if(var_Product_Type =='Plasma' && !(var_width =='1/4' || var_width =='3/8' ) || Test.isRunningtest()){
                    options.add(new SelectOption('36','36'));
                    options.add(new SelectOption('9','9'));
                    }
            }
            return options;
    }
    
    //Fabric - Tape Apex-----------------------------------------------
    /*public boolean Compare_width{get;set;}
    public decimal var_Max_Width {get; set;}
    
    public PageReference Tape_Fabric(){
        var_Max_Width = cpl.Max_Width__c;
        
        String temp = var_width;
        Decimal var_width_dec = Decimal.valueOf(temp);
        
        Compare_width = true;
        if(var_width_dec > var_Max_Width ){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please select width '));
        }
        if(var_width_dec == var_Max_Width ){
            
        }
        if(var_width_dec < var_Max_Width ){
            List<SelectOption> options = new List<SelectOption>();
            var_width = cpl.Wide_Imperial__c;
            var_Max_Width = cpl.Max_Width__c;
            if(var_width <> null  || Test.isRunningtest() )
            {
                if((var_Product_Type =='Tape' || var_Product_Type =='Fabric') && (var_width =='1/4' || 
                                                 var_width =='3/8' ) || Test.isRunningtest()){
                    options.add(new SelectOption('18','18'));
                    options.add(new SelectOption('3','3'));
                    }
                if((var_Product_Type =='Tape' || var_Product_Type =='Fabric') && !(var_width =='1/4' || 
                                                 var_width =='3/8' ) || Test.isRunningtest()){
                    options.add(new SelectOption('36','36'));
                    options.add(new SelectOption('3','3'));
                    }
            }
            return option;
        }
    }*/
    
    //------------------------------------------------   
    
    public string select_length_m {get; set;}   
    public string var_width_m {get; set;}
    public List<SelectOption> getListWidth_m() {
        List<SelectOption> options = new List<SelectOption> { new SelectOption('','-- Width --') };
        for(Schema.PicklistEntry grm:Customer_s_Price_List__c.Wide_Metric__c.getDescribe().getPicklistValues()) {
            options.add(new SelectOption(grm.getValue(),grm.getLabel()));
        }
            return options;
    }
    
    public List<SelectOption> getlength_m(){
        List<SelectOption> options = new List<SelectOption>();
            var_width_m = cpl.Wide_Metric__c;
            if(var_width_m <> null  || Test.isRunningtest() )
            {
                if(var_Product_Type =='Laminated / + 10' || Test.isRunningtest() ){
                    options.add(new SelectOption('16.5','16.5'));
                    options.add(new SelectOption('8','8'));
                    }
                if( var_Product_Type =='Plasma' && (var_width_m =='6' || var_width_m =='10' ) || Test.isRunningtest() ){
                    options.add(new SelectOption('16.5','16.5'));
                    options.add(new SelectOption('8','8'));
                    }
                if( var_Product_Type =='Plasma' && !(var_width_m =='6' || var_width_m =='10' )  || Test.isRunningtest()){
                    options.add(new SelectOption('33','33'));
                    options.add(new SelectOption('8','8'));
                    }
            }
            return options;
    }
    
                          

}