Just thought I'd pass on my problem/solution in case anyone needs it in the future.

Problem:  I'm building a struts application that includes ad-hoc querying.  In and of itself, this was not a difficult piece of functionality to implement.  RowSetDynaClass, DynaBeans, and DisplayTag were all I needed.

However, since this is ad-hoc, I obviously can't configure the DisplayTag columns at build-time.  What I discovered is that DisplayTag uses Beanutils to determine the columns and Beanutils models these as a simple Map.  As a result, the columns were NOT being displayed in the same order as they were in the ResultSet.  As a result, I extended RowSetDynaClass and DynaBean and modified them to use LinkedHashMaps.  With this change, I was able to iterate over the column headers in the proper order thusly:

--
request.setAttribute("rows", rows);
request.setAttribute("rowHeaders", properties);

  <table>
    <bean:define id="resultSetRowHeaders" name="rowHeaders" scope="request"/>
    <!-- NOTE: The order of the output is EXACTLY that of the order of the columns in the resultSet -->
    <display:table name="rows">
      <logic:iterate id="header" name="resultSetRowHeaders">
        <bean:define id='myColumnHeader' name='header' property='name' type="java.lang.String"/>
        <display:column property="<%=myColumnHeader%>" />
      </logic:iterate>
    </display:table>
  </table>

I hope this helps someone in the future.

Dennis




Dennis Graham/CMG/WACH

05/17/2004 03:36 PM

To
[EMAIL PROTECTED]
cc
Subject
What determines the Column order if columns aren't specificed?  (WAS: dynabean datasource question)




OK, looks like the page giving an example of using a Dynabean is missing one step (List rows = resultSet.getRows()).

Now, my question is what determines the column order, or rather, how can I guarantee the display order of the columns?

The context is that I am trying to use displaytag to display the results of a user-supplied ad-hoc query.  I assumed that the the column order would be the same as the order specified in the query, but that is NOT happening.  In fact, I can't discern any ordering on the columns, they are not query order, they are not sorted, they aren't inverse sorted...On the fact of it, it seems random.

Thanks,
Dennis
[EMAIL PROTECTED]

Reply via email to