0

I'm struggling to understand how to pass the values from component to page controller and I have posted the question here and got the pointers so I started creating this test pages to understand the logic behind.

I'm stuck in the following lines of code and needs few clearfication if possible:

if I have this line of code in the component it works and shows the value on the vf page, since its directly binding to the class property.

<apex:inputText value="{!stringVal.value2}" /> 

But why this line of code does not show the value on the the vf page, this is what i'm after findings, what I'm doing wrong here?

<apex:inputText value="{!stringVal3}" />

I have created sample pages/classes to mimic the problem.

Class:

public class StringCarrier {
    public string value3 {get; set;}
}

VF Component:

<apex:component controller="CompController">

    <apex:attribute type="StringCarrier" name="theString" description="The string to update" assignTo="{!stringVal}"/>

        <apex:pageblockSection title="Enter Text Section 3"  >
            <apex:inputText value="{!stringVal3}"   />  
        </apex:pageblockSection> 

    </apex:pageBlock>

</apex:component>

VF Component Controller:

public class CompController 
{
    public StringCarrier stringVal {get; set;}

    public string stringVal3 {
        get {
            system.debug('get stringVal3:'+  stringVal3);
            return stringVal.value3;
        }
        set {
            stringVal.value3 =  stringVal3;
            system.debug('set stringVal3//' + stringVal.value3);
        }
    }  
}

VF Page:

<apex:page controller="pageController">
    <apex:form >
        <apex:pageBlock title="entered: {!enteredString.value3}" id="pb1">
            <apex:pageMessages />
            <apex:pageBlockSection columns="1">
                <c:testComponent theString="{!enteredString}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>  
        <apex:commandButton value="Update" /> 
    </apex:form>
</apex:page>

VF Page Controller:

public class pageController {
    public StringCarrier enteredString {get; set;}

    public pageController()
    {
        enteredString=new StringCarrier();
        enteredString.value3 ='This is the default from the controller';
    }
}
0

1 Answer 1

0

The "set" method is incorrect. The magic parameter will always be called "value":

set {
        stringVal.value3 =  value;  // Value entered by user
        system.debug('set stringVal3//' + stringVal.value3);
    }
1
  • I see the value in the debug but i do not see the value that being pass to vf page, my updated prop public string stringVal3 { get; set { stringVal.value3 = 'some extra++: ' + value; system.debug('stringVal3//' + value); } }
    – Nick
    Dec 8, 2016 at 16:40

You must log in to answer this question.

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