Tell me more ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I am getting the nickname from an inputField and updating a list of strings and displaying the list of strings on a table. The outputField displays the newly entered value, but the controller variable seems to store the previous value even when I use the same {!Object.nickName} as the value attribute in both cases.

Test:

1) when I enter "1": Output box: 1, List retrieved from controller: (nothing)

2) Enter "2": Output box: 2, List retrieved from controller: 1

What is the issue here? Why is the same {!Object.nickName} retrieving two different values when it is an outputField vs controller variable(system debug/pageblocktable)

Vf Page:

<script>
    function checkName() {
        updateNicknameList( $('input[id$=Name]').val());
        }     
    }
</script>

<apex:form >

    <apex:actionFunction name="UpdateNicknameList" action="{!updateNicknameList}" immediate="true" rerender="nicknameDisplay">
        <apex:param name="Name" value=""/>
    </apex:actionFunction>        
    <apex:inputField id="Name" value="{!Object.nickName}" onblur="checkName()"/>    
    <apex:outputField value="{!Object.nickName}"/>
    <apex:commandLink value="Add nickname" action="{!processLinkClick}">
        <apex:param name="nickName" value="{!Object.nickName}" assignTo="{!nickName}"/>
    </apex:commandLink>
    <Code Displaying the nicknames as a table>
</apex:form >

Controller:

//Defining standard controllers

//Constructor initializes data members

public void updateNicknameList() {
        String Name = '';
        if (ApexPages.currentPage().getParameters().get('Name') != null) {
            Name = ApexPages.currentPage().getParameters().get('Name');
            this.Object.nickName = Name;
            this.nickNameList.add(Name);
        }
public PageReference processLinkClick() {
        this.nickNames.add(nickName);
        return null;
    }
share|improve this question

3 Answers

up vote 1 down vote accepted

add a debug statement and check what your controller receives.

in addition see this Post in the DeveloperForce forum http://boards.developerforce.com/t5/Apex-Code-Development/How-do-I-pass-value-of-apex-inputField-to-Custom-Controller/td-p/532905

share|improve this answer
Yes I was checking values with debug statements, the issue seems to be with the way I was passing the input field in the script: updateNicknameList( $('input[id$=Name]').val()); – srdev_salesforce May 14 at 15:16

I was checking values with debug statements and alerts, the issue seems to be with the way I was passing the input field in the script:

updateNicknameList( $('input[id$=Name]').val());
<apex:inputField id="Name" value="{!Object.nickName}" onblur="checkName()"/> 

When I tried the method used in the above link from Seb__Wagner, the issue is resolved:

updateNicknameList( document.getElementById(name).value );
<apex:inputField id="check" value="{!Object.nickName}" onchange="checkName('{!$Component.check}');"/>

Thanks Seb__Wagner, this issue had been eating my head yesterday.

share|improve this answer

I don't understand why you're using ActionFunction to post Object.nickName to controller, then in controller set the Object.nickName again. As you're using a bind variable for inputField, the controller will automatically update with a new value once you click on your commandLink.

Essentially your page will function with the following page code (with no additional javascript):

<apex:inputField id="Name" value="{!Object.nickName}" />    
<apex:outputField value="{!Object.nickName}"/>
<apex:commandLink value="Add nickname" action="{!processLinkClick}" reRender="nicknameTable" />
<Code Displaying the nicknames as a table>

and controller:

public PageReference processLinkClick() {

    this.nickNames.add(this.object.nickName);
    return null;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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