Skip to main content
fixed typo on contact var declaration
Source Link
Xtremefaith
  • 4.6k
  • 5
  • 44
  • 96
public class WrapperObj{

        public String label { get; set; }
        public String type  { get; set; }
        public String param { get; set; }
        public String value { get; set; }

        /* Register Lookup field types */
        public Contact contact { get; set; }

        /* ALSO tried setting the value with a private setter */
        // public Contact contact { get; 
           // set{ System.debug('::CONTACT:: '+value); }
        // }

        public WrapperObj(String expression){
            List<String> parts = expression.Split('\\.');
            this.label = parts[0];
            this.type  = parts[1];
            this.param = parts[2];

            /* Account Lookup */
            this.contact = new Contact(); 
        }
}
public class WrapperObj{

        public String label { get; set; }
        public String type  { get; set; }
        public String param { get; set; }
        public String value { get; set; }

        /* Register Lookup field types */
        public Contact { get; set; }

        /* ALSO tried setting the value with a private setter */
        public Contact contact { get; 
            set{ System.debug('::CONTACT:: '+value); }
        }

        public WrapperObj(String expression){
            List<String> parts = expression.Split('\\.');
            this.label = parts[0];
            this.type  = parts[1];
            this.param = parts[2];

            /* Account Lookup */
            this.contact = new Contact(); 
        }
}
public class WrapperObj{

        public String label { get; set; }
        public String type  { get; set; }
        public String param { get; set; }
        public String value { get; set; }

        /* Register Lookup field types */
        public Contact contact { get; set; }

        /* ALSO tried setting the value with a private setter */
        // public Contact contact { get; 
           // set{ System.debug('::CONTACT:: '+value); }
        // }

        public WrapperObj(String expression){
            List<String> parts = expression.Split('\\.');
            this.label = parts[0];
            this.type  = parts[1];
            this.param = parts[2];

            /* Account Lookup */
            this.contact = new Contact(); 
        }
}
Source Link
Xtremefaith
  • 4.6k
  • 5
  • 44
  • 96

Visualforce Wrapper Object bound Lookup Input:Field Not Setting

I currently have a wrapper object that contains a Contact that will be bound to an input:Field in order to create a lookup for an Account. Currently the lookup field functions just fine, BUT then when I submit the form (with the value from the lookup page), the PageReference method doesn't recognize the value, it is as if it is never set

List of wrapper objects used on page:

List<WrapperObj> myWrapperList = new List<WrapperObj>();

Controller Wrapper

public class WrapperObj{

        public String label { get; set; }
        public String type  { get; set; }
        public String param { get; set; }
        public String value { get; set; }

        /* Register Lookup field types */
        public Contact { get; set; }

        /* ALSO tried setting the value with a private setter */
        public Contact contact { get; 
            set{ System.debug('::CONTACT:: '+value); }
        }

        public WrapperObj(String expression){
            List<String> parts = expression.Split('\\.');
            this.label = parts[0];
            this.type  = parts[1];
            this.param = parts[2];

            /* Account Lookup */
            this.contact = new Contact(); 
        }
}

Page Reference Method:

public PageReference formAction(){
    System.debug(myWrapperList);
}

So again the question is why does my wrapper class not have a value stored for the Contact object when I submit the page. Also here is the Visualforce markup in case it matters:

VF Page:

<apex:form >
    <apex:PageBlock>

        <apex:repeat value="{!myWrapperList}" var="field">

            <apex:outputPanel layout="inline">{!field.label}:</apex:outputPanel>
                <apex:inputField value="{!field.contact.AccountId}" />
            </apex:outputPanel>

        </apex:repeat>

        <!-- Form Submission -->
        <apex:pageBlockButtons >
            <apex:commandButton value="{!search}" action="{!formAction}" />
        </apex:pageBlockButtons>

    </apex:PageBlock>
</apex:form>