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>
2
  • 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
    Commented May 29, 2016 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
    Commented May 29, 2016 at 11:24

1 Answer 1

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

>

4
  • What changed? not sure I'm spotting the difference here Commented May 29, 2016 at 7:10
  • check out the way Contact object is used now. Commented May 29, 2016 at 7:11
  • Oh you fixed my typo?... it is already public Contact contact { get; set; } Commented May 29, 2016 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? Commented May 30, 2016 at 5:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .