You need to sign in to do that
Don't have an account?
Dynamic Form Creation Problem.
I'm looking to have an object store a list of fields to be made into a form, with "type" being text, textarea, file, hidden, checkbox, etc. I'm not sure how to best accomplish this. I can think of two ways, but both have notable problems.
Option one:
define a set of boolean variables and then
<apex:inputFile rendered="{!isFile}" value="{!blahblahblah}" /> <apex:inputText rendered="{!isText}" value="{!blahblahblah}" /> <apex:inputHidden rendered="{!isHidden}" value="{!blahblahblah}" />
etc. (there are seven options, I believe, so you're looking at 7 boolean tests PER field, so when making a 50 field form, that's 350 boolean tests.. page loads too slow)
Option two:
Where the booleans above are defined, just have it actually make a string with the HTML input command, and the VF page just have something like:
<apex:repeat value="{!fieldOutputs}" var="output" id="theRepeat"> <apex:outputText escape="false" value="{!output}" /><br /> </apex:repeat>
That worked fine for making the page, and ran fast (because you can "else If" in apex) but now I don't have a way to get the data back to the controller when I click the save button.
I would greatly appreciate any help that can be offered, thanks!
ScriptMonkey
I assume that you've called support to enable the dynamic visualforce components pilot? Also that you're on the latest API version?
All Answers
You may want to try an approach using dynamic visualforce components. See the dev guide for more info.
I looked into that and while I was ecstatic, thinking it was the right answer, sadly it's not.
Dynamic components don't give you any functionality that we didn't already have, it just moves them to Apex.
To use the Dynamic Visualforce Component, I need to do something like this:
The problem is that componentObj needs to either be defined with get/set functions, or just be the function getComponentObj().
this is the problem, because the definition of the variable, or function, must declare the type of value, IE:
or
The problem is, I don't know if I'm going to use an inputText or inputTextarea or inputHidden, etc..
I need to be able to change the TYPE of component, not just modify the attributes in apex, but the type has to be set in stone to use dynamic components, it's just set in stone in the variable type, rather than the component type.
If I'm missing a use case then please, let me know. Also, if you can think of another way, if I'm not, that I can do this, I'm open to ideas.
Ok, I did more research and found out that I can make a dynamic "outputPanel" and give it "child objects" which can be totally dynamic. sounds great, concept should work, even based on the examples
Here's the problem:
This is the sample exactly from the docs:
And I get the message:
Save error: Invalid type: Component.Apex.SectionHeader
So I can't even run the example they give me! It says that it's not valid...
Every time I take one step forward, I feel like I fall backwards a quarter mile.
I assume that you've called support to enable the dynamic visualforce components pilot? Also that you're on the latest API version?
Actually I hadn't realized I needed to until this past saturday night, after I posted this. I'm still waiting for it to be enabled, but thank you for replying!
I'd suggest calling support and specifically requesting that the request to enable it get escalated to "tier 3", who should be able to anble it for you.
Change the return type of the function to Component.Apex.SectionHeader currently it is Component.Apex.PageMessage. This will make it work.