+ Start a Discussion

is it possible to create a tag in visualforce using APEX code?


I want know if is possible to create a tag using apex code.

for example

List<String> accounts


When the code is executed in the visualforce will appear
//TR and TD created by apex
<td>Account Value</td>

is it possible to do?

Best Regards
Shruti SShruti S
Yes, it is possible to create tags in Visualforce using Apex code. For that, you can define your tag in a String variable in Apex and then render that variable in an Output Text tag in the Visualforce page.
Here is an example - 

Apex Code
public class SampleController {
    public String userName { get; set; }
    public SampleController() {
        userName =  '<table border="1"><tr><td>' + UserInfo.getFirstName() + '</td></tr></table>';
<apex:page controller="SampleController">
    <apex:outputText value="{!userName}" escape="false">
Also please note that you will have to do an escape=false , then only the text will be rendered as HTML tags.
Hi Shruti
is it work if I use a variable of type list?
The point is I must print each register separated by tags
Shruti SShruti S
I am not sure if I understood you well. Could you please tell me what you meant by each register seperated by tags?
I need display a list in visualforce.
But when I display the list, all the data fo account for example, are displayed all in only one cell.
So I need separate each data with TR and TD.

When I use your example with a simple variable String name, it works, but when I use the variable like LIST<String> name it occurs the follow error:
Failure Message: "System.NullPointerException: Attempt to de-reference a null object.