0

Can anyone please help me how to display the list values using a VF page.
Below is my controller comparison logic:

for(obj__c Type : subType)
{
    for(obj__c gen : generalList)
    {
        if(Type.Sub_Type__c == gen.Sub_Type__c)
        {
            genValue = gen.sub_Type__c;
            System.debug ('genValue -----------'+genValue);
        }
    }
}

genValue is a string which stores the list of sub_Type field values. now I wanted to display all the list values for every iteration of for loop using a vf page. I tried displaying as : value="{!genValue}" but as it is a string the page is displaying only one value. Can anyone please help me display all the list values as long as the outer for loop iterates Thanks in advance.

1

You should be able to use the <apex:repeat> tag to display your list values. From the help docs here, here is an example:

For this example to render properly, you must associate the Visualforce page

with a valid account record in the URL.

For example, if 001D000000IRt53 is the account ID, the resulting URL should be:

https://Salesforce_instance/apex/myPage?id=001D000000IRt53

See the Visualforce Developer's Guide Quick Start Tutorial for more information.

<!-- Page: -->

<apex:page standardController="Account">

    <table border="0" >

        <tr>

            <th>Case Number</th><th>Origin</th>

            <th>Creator Email</th><th>Status</th>

        </tr>

        <apex:repeat var="cases" value="{!Account.Cases}">

        <tr>

            <td>{!cases.CaseNumber}</td>

            <td>{!cases.Origin}</td>

            <td>{!cases.Contact.email}</td>

            <td>{!cases.Status}</td>

        </tr>

        </apex:repeat> 

    </table>

</apex:page>

Update: Try swapping out the variables in the above example with your list and values. Something like this should work:

<!-- Page: -->

<apex:page standardController="Your standard or custom object here">

    <table border="0" >

        <tr>

            <th>Sub Type</th>

        </tr>

        <apex:repeat var="ten" value="{!generalList}">

        <tr>

            <td>{!gen.Sub_Type__c}</td>

        </tr>

        </apex:repeat> 

    </table>

</apex:page>
6
  • Thanks @Jenny, I tried above one and got error as : Error: Unknown property 'String.Type__c' <apex:repeat value="{!genValue}" var="typeset"> <tr> <td>{!typeset.Ques__c}</td> <td>{!typeset.Type__c}</td> </tr> </apex:repeat>
    – ammu ammu
    Sep 19 '15 at 14:29
  • Hi, I tried as below but I'm not getting anything displayed and I did not get any errors: <apex:pageBlockSection title="{!subTypeSet}"> <apex:repeat value="{!subTypeSet}" var="typeset"> <tr> <td>{!typeset}</td> <!-- <td>{!typeset.DSD_Sub_Type__c} </td>--> </tr> <apex:repeat value="{!genQuesValue}" var="ques"> <tr> <td>{!genQuesValue}</td> </tr> </apex:repeat> Please help me out.
    – ammu ammu
    Sep 19 '15 at 15:00
  • Hi, I tried as below: <apex:pageBlockSection title="{!subTypeSet}"> <apex:repeat value="{!subTypeSet}" var="typeset"> <tr> <td>{!typeset}</td> </tr> <apex:repeat value="{!genValue}" var="ques"> <tr> <td>{!genValue}</td> </tr> </apex:repeat> I did not get any errors and nothing is displayed in the page. Can you please explain me where I'm ging wrong. Thanks in advance Also, can tou please help me format this comment as i'm unable to format it.
    – ammu ammu
    Sep 19 '15 at 15:02
  • Sorry @ammuammu I was on a flight home, you cannot format the comment but instead can edit your question with an update and adding the new information for what you tried that didn't work. The repeat takes a list of items and then sets the variable and displays each item from the list. If you only want specific items in the list then create a list to be displayed and add just those items to the list, then use the repeat on that list.
    – Jenny B
    Sep 19 '15 at 19:33
  • Hi Jenny, Can you please explain it with an example. I want to display all the list values but I'm getting only one value displayed
    – ammu ammu
    Sep 20 '15 at 6:38
0

I think you use List rather than String

List<String> genValue = new List<String>();

In inner loop, rather than adding in String, add in List

genValue.add(gen.sub_Type__c);

In VF Page, display the list with

<apex:repeat value="genValue" var="item"
   {!item}
 </apex:repeat>

Hope it helps you

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.