You need to sign in to do that
Don't have an account?
Binding Field Sets to Input fields in VisualForce Page/Site Page
Hi, I'm trying to create a page that my users can insert/update a record. I want to use fieldsets so we can dynamically change the order and fields easily.
Here's my page:
<apex:pageBlockTable value="{!$ObjectType.CustomObject__c.FieldSets.fsName}" var="f" width="50%" columnsWidth="100px, 100px"> <apex:column value="{!f.Label}" > <apex:facet name="header">Header Text</apex:facet> </apex:column> <apex:column > <apex:inputfield value="{!a[f]} "/> <apex:facet name="header">Value</apex:facet> </apex:column> </apex:pageBlockTable>
Here's my controller:
Public class MyController { public CustomObject__c a {get; private set;} public MyController () { a = new CustomObject__c(); }
This was to create a new record and simply insert it, but I then changed to this:
public class MyController { public customobject__c a {get; private set;} public string theId {get {return ApexPages.currentPage().getParameters().get('aid');}} public MyController() { a = [select firstname__c, lastname__c phone__c,email__c from customobject__c where id = :theId limit 1]; } public pagereference mySave(){ PageReference pageRef = ApexPages.currentPage(); update a; system.debug('### calling pageref...--'+pageRef); return pageRef; } }
The fields in my field set are contained in the soql select statement...Not sure if I can dynamically create this one...or if I use the standardcontroller with an extention would it not require me to specify all the fields in the field set?
Anyway...
Neither is working...It sort of seems that the input fields are not actually bound to the sobject fields. I don't think I should have to do any setters or getters...but I've been wrong once or twice before.
Anyone...anyone?
Thanks.
Hm, well if you are generating the soql it is up to you to make sure it includes all the required fields. That is kind of hard to do right now since there is no way to process the fieldset in apex code. I guess you could read all the fields just in case.
If you use standard controller and leave it to load the record, it should autoatically include all the fields from the fieldset.
Oh, just realized you say the fields from the fieldset ARE in the soql. Not sure what could be wrong in that case. It looks like it should work ok.
More strange behaviour....
If I add:
Where...I can suddenly update the record by modifing the inputfield associated with the fieldset (but only this one).
I'm at a loss and think I'm off to do it the hard/non-dynamic way. Oh well.