You need to sign in to do that
Don't have an account?
DaveGraupner
How to Create Surrogate SObjects
In a previous post Doug Chasman wrote:
... and sometimes you want to combine the 2 concepts, leverage the cool automagic apex:inputField picklist (or date picker is another common request) behavior when you don't have an Sobject. For that you just create a surrogate or proxy, in memory only, SObject instance that you can bind to - basically using the SObject purely as a data transfer object.
How do I create a surrogate in memory only Sobject? I've looked through the Apex and VF documentation but can't see anything realted to this. I would think I need to define an object with the relavent fields I want to use in the VF page but I don't see how to associate the object as a SObject or specify the various field attributes (like required).
Thanks
Dave
I am sure if this will fulfill your requirements but i guess i am thinking loudly here.
first, Identify an object in the system that has such a field, say account.name
then you create an account (in memory) in your controller like this
public Account myVirtualObj { get; private set;} { myVirtualObj = new Account(); }
now you can use { ! myVirtualObj.name } in the Visualforce page, in an inputField tag
then access the value of this in your controller using
string required_string = myVirtualObj.name;
if i am correct it will also draw the required color ( it may need to be in a page block section for that)
<apex:selectList id="accountName" required="true" size="1" value="{!selectedAccountID}">
<apex:selectOptions value="{!leadAccountNames}"/>
</apex:selectList>