I have a <apex:pageblocktable> whose columns need to be created dynamically, and I've done this before using an <apex:repeat> as demonstrated in a different answer.

However, here's the catch: I need to determine the type of form element for each column (<apex:outputfield>, <apex:inputfield>, <apex:outputtext>, <apex:inputtext>, or <apex:selectlist>) at run time (after a button is clicked).

I thought I could use Dynamic Components to create the <apex:pageblocktable> and all of its columns and fields, but this is proving difficult. All examples (1, 2, and 3) I've seen define Dynamic Components using a get property, but I'd like to create the Dynamic Component once a button is clicked (after I get data based on User input). Is there a way to do this?

Does anyone have any other suggestions to accomplish what I'm looking for?

  • sorry answering from mobile i will pretify it once i come near my laptop – Mohith Shrivastava Apr 26 '13 at 15:44

If you wanted to avoid dynamic visualforce you just need to pass some data structure with enough information to render your column and repeat over that.

Data Structure

public class YourController {
    public List<Column> cols { get; private set; }

    public class Column {
        public String fieldAPIName { get; set; }
        public String myDisplayType { get; set; }
        // .. other attributes that are important to your display 


<apex:pageBlockTable value="{!records}" var="record"> 
    <apex:repeat value="{!columns}" var="column">
            <apex:outputField value="{record[column.fieldAPIName]}" 
                    rendered="{!column.myDisplayType <> 'outputField'}"/>
            <apex:outputText value="{record[column.fieldAPIName]}" 
                    rendered="{!column.myDisplayType <> 'outputText'}"/>
            <!-- Repeat for other datatypes -->

In the getter only check various conditions and form elememts.

public apex.component.pageblock getpgblk
  if(value = b) 
    //form pageblk b
    return pglkb;
  else if(value = c) 
    //form pageblk and components
    return pageblkc;
    return null;
  • Being a getter and not a setter, where does the value variable come from? – Matt K Apr 26 '13 at 15:55
  • The inputtext can still be get set property .On action the setter of input will be set.All expression is also supported .First time you can render according to your choice on action check the value of input text and form elements – Mohith Shrivastava Apr 26 '13 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.