Search code examples
salesforceapex-codevisualforce

apex:inputField Binding Value not updated


I am working with Apex controller and Visual Force page. Inside of the vf page I had a data table and each row of that table binds to a value from a list that generated from the controller example code:

<apex:dataTable value="{!List}" var="item"  styleClass="class1" >
...
<apex:column headerValue="Header1">     
    <apex:outputpanel rendered="{!NOT((a=='true'))}">
    <div class='estimate-name-column'>                          
        <apex:inputField value="{!item.Name}" required='true' rendered="{!(a=='false')}"/>
         </div>          
    </apex:outputpanel>     
</apex:column>  
...
</apex:datatable>

As you can see, I was trying to hide some inputFields base on some conditions.

However, there was a problem. If I do the above, those inputFields who get rendered were not binded correctly. After submited the form with this data table, inside my controller all the records' in list Name are null. Even though I saw the 'Name' was posted in http request.

I am guessing is render interfere with the binding? because if I remove the rerendered conditions and display all InputField I can get the values inside the controller after submitting form

any ideas what happened?


Solution

  • If I recall correctly an apex tag must be present on the page in order to be rerendered.

    In other words - something (maybe as simple as <span id="long:generated:salesforce:id"></span>) must be in HTML in order for later AJAX updates to inject new content into the placeholder. If it's not rendered, it will stay not rendered.(1)

    Instead of rendered try to move your condition to styleor styleclass attributes. Something like

    <apex:inputField value="{!item.Name}" 
        required="{!a=='false'}" 
        style="display:{!IF(a=='false','inline', 'none')}"/>
    

    visibility:hidden (if you want them to occupy their space but not be seen) or display:none (to have them appear to be completely not there. See also What is the difference between visibility:hidden and display:none?


    Footnote:

    (1) unless of course you'll rerender a tag that contains "this" tag (something higher in the XML).