Menu

How to create a data object?

Help
courtenayt
2006-11-21
2012-10-09
  • courtenayt

    courtenayt - 2006-11-21

    I can't believe the awful documentation on displaytag. Can someone PLEASE tell me how to put data into a map or a list or something so I can use it to store table data? I've heard that I should use the map keys as the column headers, but that would only allow me to have 1 row of data in my table. I find it completely INSANE that the only documentation on the site requires you to search around for samples and then hand replace parts of the code to get them to work. Sorry for my rant, but I am so fed up with poor documentation I feel like screaming! I would just like to be able to go to a website sometime, see a basic example and be able to use it without searching everywhere for how to get the examples to work and finding that other users had to use a convoluted way of getting them. Not even the documentation on what jar files are needed is consistent on all pages of this website! I'm really close to just writing my own code for this and giving up on using displaytag - it seems like it's more work to figure out how to use it than to write my own!

    Thanks in advance,
    Courtenay

     
    • Ed Webb

      Ed Webb - 2006-11-21

      Take a deep breath. Now another one. Better? Good.

      Start with a List.

      Each entry in the List will be a row in your table.

      If you've got a class that represents your data put object of this class into the List. If you're making something up create a Map for each thing and put the properties of the thing into the Map; key=property name, value=property value.

      Inside the <display:table> tag write some <display:column> tags. The property attribute will match that column to the property of the object or the key of the Map.

      Example:

      <display:column property="name"/>

      If your data is in a Map DisplayTag will use Map.get("name") to retrieve the value of the cell.
      If your data is in an object DisplayTag will use object.getName() to retrieve the value of the cell.

      This is all explained in the documentation (although it is a bit vague about the Map thing) but you can always experiment with the library - after all you've already saved hours using DisplayTag instead of writing your own.

       
    • Rick Herrick

      Rick Herrick - 2006-11-21

      You get what you pay for. You're free to return displaytag and get all of your hard-earned money back.

      Plus, I had no issues with the documentation. I was able to to get both lists and maps working with minimal hassle.

       
    • courtenayt

      courtenayt - 2006-11-21

      Hi,

      Thanks for your help! I used the following setup and it seems to have worked:

                              &lt;%
                                  List testTable = new LinkedList();
                                  HashMap tableRow1 = new HashMap();
                                  tableRow1.put(&quot;col1&quot;, new Integer(1));
                                  tableRow1.put(&quot;col2&quot;, &quot;c&quot;);
      
                                  HashMap tableRow2 = new HashMap();
                                  tableRow2.put(&quot;col1&quot;, new Integer(2));
                                  tableRow2.put(&quot;col2&quot;,&quot;a&quot;);
      
                                  HashMap tableRow3 = new HashMap();
                                  tableRow3.put(&quot;col1&quot;, new Integer(3));
                                  tableRow3.put(&quot;col2&quot;, &quot;b&quot;);
      
                                  testTable.add(tableRow1);
                                  testTable.add(tableRow2);
                                  testTable.add(tableRow3);
      
                           %&gt;       
                                  &lt;% request.setAttribute(&quot;table&quot;, testTable); %&gt;
      
                                    &lt;display:table name=&quot;table&quot; id=&quot;test_table&quot;&gt;
                                        &lt;display:column property=&quot;col1&quot; title=&quot;Column 1&quot; sortable=&quot;true&quot;/&gt;
                                        &lt;display:column property=&quot;col2&quot; title=&quot;Column 2&quot; sortable=&quot;true&quot;/&gt;                                  
                                    &lt;/display:table&gt;
      
       

Log in to post a comment.