function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NaoNao 

Pitfall in dynamic InputField in repeat

Hi all,

 

I was faced some problem in dynamic InputField in repeat.

I found folution so I am going to share it in this discussion board.

 

To simplify, issue is like this.

 

-----in APeX:---

public myLead{set;get;}                                         //Lead record to be insert/update
public LIST<String> fieldNames{set;get;}          //List of field name 

 

//Constructor

public myPageControllerClass(){
    myLead = new Lead();
   

    fieldNames = new LIST<String>();
    fieldNames.add('firstName'); //dinamically show filed on VF page
    fieldNames.add('lastName');
}

 

---in VFpage Case A----(BAD)

<apex:repeat value="{!fieldNames}" var="fname">
    <apex:variable var="flabel" value="{!fname}"/>
    <apex:InputField value="{!myLead[flabel]}" />
</apex:repeat>

 

---in VFpage Case B----(GOOD)

<apex:repeat value="{!fieldNames}" var="fname">

    <apex:InputField value="{!myLead[fname]}" />
</apex:repeat>

 

Case A use VF value to store field name onece, then use it.

Case B don't use value

 

Both CAN display field value dynamically. It is fine.

 

However, in case A, editing in InputField CAN NOT change myLead record in APEX.

So if you put Action, then try to update myLead record in APEX function, no change will be saved :(

It is like onw way.

 

If you need to syncronize VF InputField and corresponding variable in APEX, use case B above.

 

I spend three days to solve this:(

Hope this helps someone, someday :)

 

Naoki Ueda @ Samurai System, Japan