0

I want to read in a CSV file and display the data as a table in a VF page. So for example my file might look like this:

Name, category, description, Priority, Type, Status, Number, 
Issue11, Decision Required, Bad data, High, System, txt,100,
Issue15, Decision Required, Some data, Low, System, tyxt,200,
Issue13, Decision Required, Some data, Low, System, texta,300,

After the text is displayed the user will be able to insert into an object but initially i just want to display the file values (7 columns, 3 data rows) before any object associations are made. The problem i am having is how do i reference the separate column names in the VF page so each value display in a column.
If i were association with an object (eg Account) i could use for example the code: <apex:column value="{!val.name}" /> to display the 1st column But how do i reference the value when the data is just from the file itself. I've tried list of list, a list of maps but i can't get this to work.

The code i am using is of this form:

<apex:repeat value="{!alist}" var="l">
    <apex:dataList value="{!l}" var="c">
          {!c}
    </apex:dataList>
</apex:repeat>

So an example i have tried is this

<apex:repeat value="{!myList}" var="myMap">
   <apex:pageblocktable value="{!myMap}" var="c">
        <apex:column value="{!c.name}" />
        <apex:column value="{!c.category}" />
   </apex:pageblocktable>         
</apex:repeat>

This does not work though. What does the variable c have to be so i can reference the distinct values?

Any help will be appreciated.

3
  • THe code did not come through so i'll try again The code i am using is of this form: <apex:repeat value="{!alist}" var="l"> <apex:dataList value="{!l}" var="c"> {!c} </apex:dataList> </apex:repeat> So an example i have tried is this <apex:repeat value="{!myList}" var="myMap"> <apex:pageblocktable value="{!myMap}" var="c"> <apex:column value="{!c.name}" /> <apex:column value="{!c.category}" /> </apex:pageblocktable> </apex:repeat>
    – user10669
    Jul 28, 2014 at 2:42
  • Apologies for the lack of fromatting, i pasted formatted but the formatting does not come through.
    – user10669
    Jul 28, 2014 at 2:46
  • Can you please post your back-end code where the lists/maps are defined and populated? Jul 28, 2014 at 3:05

1 Answer 1

1
  1. Use a method to parse the CSV like listed here:

http://developer.financialforce.com/customizations/importing-large-csv-files-via-batch-apex/

  1. Parse the first row into a String[] for the headers
  2. Parse the remaining rows into a Map with the key being the row number

  3. On your page something like this

enter image description here

Just something quick off the top of my head.

3
  • Eric I need each of the file values to appear separately not as one string. I need to be able to refer to each value individually. Jul 28, 2014 at 4:04
  • Which it what I am doing
    – Eric
    Jul 28, 2014 at 4:15
  • I worked it out, my Vf code just had to have the pageblock & repeat statements swapped around so the repeat is inside the pageblock, then readjusted the variables and it works. Jul 28, 2014 at 6:24

You must log in to answer this question.