Your list in Apex doesn't contain the literal variable a
. It contains the contains the same Account
that is stored in a
.
Just like in Apex, when you have a list, you need to loop over the elements one at a time. In Apex, you'd use a for
or while
loop. With Visualforce, you use <apex:repeat>
(or some other component that can handle multiple items, like <apex:pageBlockTable>
). The <apex:repeat>
documentation is what you should use for guidance here.
The example given is pretty clear and straightforward, but in the interest of not relying on links, I'll reproduce the example here (with added comments)
<!-- Page: -->
<apex:page controller="repeatCon" id="thePage">
<!-- The "value" takes a collection (list, string, or set), and the merge
notation ({!thing}) either references a property (a class variable
that has something like {get; set;} after it) or a getter.
In this example, they're using an explicit getter (getStrings()).
Getters start with "get", but we don't include that part in the Visualforce.-->
<apex:repeat value="{!strings}" var="string" id="theRepeat">
<!-- Inside the repeat, we can use the "var" of the repeat like it
were a property.
If we were iterating over accounts, and you used var="acc", then you
could access account fields using normal dot notation (e.g.
{!acc.Name} -->
<apex:outputText value="{!string}" id="theValue"/><br/>
</apex:repeat>
</apex:page>
/*** Controller: ***/
public class repeatCon {
// This is how a property would be defined (but it's not present
// in this particular example
//public String myString {get; set;}
// This is an explicitly defined getter
public String[] getStrings() {
return new String[]{'ONE','TWO','THREE'};
}
}