1

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 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>
  • What this line means public Contact { get; set; } ? can't see a variable name. Also try replacing AccountId with Account` in VF page. i.e. <apex:inputField value="{!field.contact.Account}" /> – highfive May 29 '16 at 7:02
  • Ae you sure that myWrapperList is only initialised once and is kept in the view state by being a non-transient and non-static field? – Keith C May 29 '16 at 11:24
1

Below are some corrections that should make it work

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

    public Contact conObj { get; set;}


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

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

and on VF side

<apex:form >
    <apex:PageBlock>

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

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

        </apex:repeat>

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

    </apex:PageBlock>
</apex:form

>

| improve this answer | |
  • What changed? not sure I'm spotting the difference here – Xtremefaith May 29 '16 at 7:10
  • check out the way Contact object is used now. – Mukesh Verma May 29 '16 at 7:11
  • Oh you fixed my typo?... it is already public Contact contact { get; set; } – Xtremefaith May 29 '16 at 7:17
  • So another look at my code and I think that things were actually working just fine but that I was checking the wrong values in my action method. Is there a way to setup custom setter so that when the Contact.AccountId gets set I can use that value to set the WrapperObj.value? – Xtremefaith May 30 '16 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.