You need to sign in to do that
Don't have an account?
Br1
Dynamic APEX form
I don't know it is possible , but here we goes:
I want to build a form to edit a Standard Object, into a custom visualforce page.
To do that , i get the description of every field (with the getDescribe() and things like this), and i put it on a list.
The apex code:
And try to generate the form at at the visualforce page:
When i try to save the page, the error are:
Save error: Could not resolve the entity from <apex:inputField> value binding '{!field.value}'. inputField can only be used with SObject fields
I know that the code at the apex controller can be simplified but i keep it in that way to make it easy to understand.
Anybody knows a workaround for that problem ?
Another way to build a dynamic form ?
Thanks in advance ;)
Message Edited by Br1 on 11-05-2008 12:15 PM
I want to build a form to edit a Standard Object, into a custom visualforce page.
To do that , i get the description of every field (with the getDescribe() and things like this), and i put it on a list.
The apex code:
Code:
The class: public class AccountEditableField { public String label { get; set;} public Schema.SObjectField value { get; set; } } The Parser: public void accountDescribe(){ Set <String> fieldKeys = new Set<String>(); fieldKeys = AccountFieldsDescribe.keySet(); List <String> editableFieldKeys = new List<String>(); String queryFields = ''; for(String elem:fieldKeys){ // Get the fields Schema.DescribeFieldResult field = (AccountFieldsDescribe.get(elem)).getDescribe(); //Schema.DescribeFieldResult f = Schema.sObjectType.Account.fields.elem; if(field.isAccessible() && field.isUpdateable()){ editableFieldKeys.add(elem); queryFields += field.getSObjectField()+', '; } System.Debug(' ** \n'+AccountFieldsDescribe.get(elem)+'\n ** \n The field is visible (accesible)—:'+field.isAccessible()+' \n ** \n The field is Updateable–:'+field.isUpdateable()); } queryFields = queryFields.substring(0,queryFields.length() - 2); for(String f:editableFieldKeys){ AccountEditableField fieldEditable = new AccountEditableField(); Schema.DescribeFieldResult fieldDescribed = (AccountFieldsDescribe.get(f)).getDescribe(); fieldEditable.label = fieldDescribed.getLabel(); fieldEditable.value = fieldDescribed.getSObjectField(); listOfFields.add(fieldEditable); } }
And try to generate the form at at the visualforce page:
Code:
<apex:form id="accountEdition"> <apex:repeat value="{!listOfFields}" var="field"> <apex:outputText value="{!field.label}" /> <apex:inputField value="{!field.value}" /> </apex:repeat> </apex:form>
When i try to save the page, the error are:
Save error: Could not resolve the entity from <apex:inputField> value binding '{!field.value}'. inputField can only be used with SObject fields
I know that the code at the apex controller can be simplified but i keep it in that way to make it easy to understand.
Anybody knows a workaround for that problem ?
Another way to build a dynamic form ?
Thanks in advance ;)
Message Edited by Br1 on 11-05-2008 12:15 PM
If you are just creating a form with limited fields to edit an account, there is a way easier way of doing this.
Please state your business case you are trying to solve here, it will help frame a response.
The reason why i need a dynamic form, is because i'm trying to re-create a standard edition ( the one that works with '{RecordId}/e' ) into a visualforce page.
I have to reproduce the same edition form, but in a visualforce page without headers, sidebars or force styles, to make the form fit into a smaller screen.
I already have done the 'Customization' of the object detail view, parsing the result of the tag <apex:detail /> , but i dont have a tag that leaves a edition pageblock alone into a custom visualforce page.
Sorry about my english im not a native speaker, i hope you can understand what i'm trying to do.
Brx.
Try this.
Now for the binding issue.
You have the wrapper class but there is no sobject in the class to bind to the page.
Something like this.
I am not sure it will work, but it's a start.
Message Edited by mikef on 11-05-2008 09:47 AM
stay tuned! :)
this is what i have done at the moment, based on the help that mikef give to me about the sobject methods.
The page:
The Controller:
Its a little bit different from the code proposed , and the steps are commented , to make it easy .
The binding problems still there, i need another point of view...
Thanks
Br1
Hi Br1,
Did you get rid of the error. I have same error information to get object.field on the page. Can you give me some idea about your dynamic form. Thanks
That will be great for my dynamic stuff.
Sue
Hi Sue, bad news on that, i have't found a solution :(.
Now i'm thinking about it and a solution that comes to my mind is build a simple html form , with a method that based on the type of field creates the needed form tag and adds it to a list of strings, that can be placed with a repeater at the visualforce page.
This post is from a time ago and i doesn't remember clearly what i can get from a field, but i will give it a try.
Try to reproduce my code and i give you some help with the other part of the idea , what do you think?
Br1
Hi Bri,
Thanks for your response. I know the 'field' actually got from the code above not fieldobject -- that is the record field value.(there is no way to dynamically generate fieldojbect in force.com). So my final desicion on that may be the javascript in scontrol but which is quite hard to get the same look with salesforce like the date picker, even I can have dropdown/checkbox whatever I need.
Thanks
Sue
I thought it and the other fields (like lookups) are hard to reproduce like you said.
We are in the same point, doing a lot of stuff to get the form that don't cover all the possibilities...
If you want the datepicker you can copy the js of a working datepicker field, and include library.js at the page to use the js methods of the calendar.
Br1
Thank you so much for your information.
good luck
Hi,
Now this problem could be solved. This is just for a mark because it really takes a lot of time to figure it out.
<apex:inputField value="{!Account[apiname of the field]}" styleClass="required website_required"/>