0

I want know if is possible to create a tag html in visualforce using APEX. for example:

<table>
    <!--TR and TD will be generated by APEX-->
</table>
1

Sure, just make sure your text is not being escaped:

Apex:

public string myTable
{
    get
    {
        return '<tr><td>Test</td></tr>';
    }
}

Visualforce:

<table>
    <apex:outputText escape="false" value="{!myTable}" />
</table>

However, I would generally recommend using an apex:datatable Visualforce element instead, since it will generate the table for you based on a list, which will likely be easier to build and maintain. Note that this will also generate a <tbody> element (and <thead> if appropriate), which may not fit your requirements:

Apex:

public List<String> myTable
{
    get
    {
        return new List<String>{'Test'};
    }
}

Visualforce:

<apex:dataTable value="{!myTable}" var="element">
    <apex:column>
        <apex:outputText value="{!element}" />
    </apex:column>
</apex:dataTable>

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.