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
SalesRedSalesRed 

How To Determine And Display Correct Field Type In Dynamically Rendering A Form?

Hello,  I have a visualforce page and custom controller which I will be using to render a form to a user using XML as an input to my class and in it the fields are contained.  I wish to dynamically render my form to the user but the type of field will be contained in the xml data and subsequently parsed in my class.  I wondered how I could determine the correct field type to display to my user.  For example the following

 

                <apex:repeat value="{!FieldsList}" var="f">
                        <apex:outputField value="{!r[f]}" />
                </apex:repeat>

 

 

I don't know whether I should be putting <apex:inputText>   <apex:selectList>  etc when I'm coding my visualforce page. The type of field will come in with the XML and this type does not match selectList for example it would be called something else relating to a List.

 

Does anyone know if I can do something in my <apex:  tag to set different field types based on values received from the Controller?   Any help on this would be appreciated.

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
alibzafaralibzafar

Hi, 

 

You can try this , if you want to renrenderd based on different types 

 

     <apex:repeat value="{!FieldsList}" var="f">
                        <apex:outputField rerendered="{!r[f].typeName == 'TEXT'}" />
       </apex:repeat>

 

 

For Displaying type Name to user 

<apex:outputText label="{!r[f].type}" />

 

Make this change in your class, 

 

public yourFormType type {get; set;}

 

public string typeName{

get {

return this.type();

}

}

}

 

Cheers 

 

Ali 

 


All Answers

alibzafaralibzafar

Hi, 

 

You can try this , if you want to renrenderd based on different types 

 

     <apex:repeat value="{!FieldsList}" var="f">
                        <apex:outputField rerendered="{!r[f].typeName == 'TEXT'}" />
       </apex:repeat>

 

 

For Displaying type Name to user 

<apex:outputText label="{!r[f].type}" />

 

Make this change in your class, 

 

public yourFormType type {get; set;}

 

public string typeName{

get {

return this.type();

}

}

}

 

Cheers 

 

Ali 

 


This was selected as the best answer
SalesRedSalesRed

Hi Ali,

 

Thanks for your help. I was not familar with the rendered attribute. I guess similar to your examples I can use rendered and perform checks within my tags if they are true. If true the field will display but if not it will not display.  I can therefore add different form types and they will only be displayed if they are of the correct type matching my if statement in "rendered".

 

Thanks