You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Clint Checketts <ch...@gmail.com> on 2011/08/08 04:00:49 UTC

Re: dynamic DataTable

Sorry for taking 2 weeks. Here is a quick and dirty implementation:
https://github.com/checketts/wicket-datasource-table

It needs a bit of cleanup. 2 points that I like to note is 1) the use of a
datasource instead of a java.sql.Connection will allow automatically opening
and closing connections (so the table provider will manage itself and 2) the
use of the ResultSetMetaData to grab the column names and count.

I'll try to get around to cleaning it up (patches are welcome!) but since I
hadn't improved it in the last 5 days I figured I should just get it out
there in it rough cut glory. Its using H2 right now for the JDBC backend,
but you'd be able to switch out any equivalent driver.

-Clint

On Sat, Jul 23, 2011 at 10:18 AM, davut uysal <da...@gmail.com> wrote:

> Thanks for the tip Bertrand, I understand SQLResultRow better now. I will
> try that
>
> Regards,
>
>
> On Saturday, 23 July 2011, Bertrand Guay-Paquet <be...@step.polymtl.ca>
> wrote:
> > Hi,
> >
> > SQLResultRow is a type I made up. I didn't know what type you received
> from your SQL query, so I used that. I assumed that your result set is
> composed of rows where each row can be used as a "map" with key=column name
> and value=column value.
> >
> > With that in hand, you could iterate over the keys to build the list of
> datatable columns. Each column would hold its key value and would use it to
> access the proper column value from a result row.
> >
> >
> > On 23/07/2011 10:12 AM, davut uysal wrote:
> >>
> >> Hi Bertrand,
> >>
> >> What is SQLResultRow, is it a Wicket Type? Or should I create a custom
> class
> >> named "SQLResultRow"?
> >>
> >> The problem is, I can't create a custom "SQLResultRow" because I can't
> be
> >> sure of its member fields.
> >>
> >> User can run any SQL, so the type must be compatible with any result.
> For
> >> example:
> >> 1) select firstname, lastname from employees;   =>  Returns<Employee>
> >> 2) select locationcode, locationname from locations; =>
>  Returns<Location>
> >> ... (any SQL can return any unpredictable object)
> >> So it is impossible to create a custom "SQLResultRow"
> >>
> >> Anyway, I have solved the problem in the complex, hard way which is
> about
> to
> >> use 2 nested repeaters (ListView). 1 for table column names loop, 1 for
> >> table rows loop.
> >>
> >> And, I got the answer: There is no easy way in wicket to do that kind of
> >> dynamic thing.
> >>
> >> Thanks,
> >>
> >>
> >> On 22 July 2011 18:03, Bertrand Guay-Paquet<be...@step.polymtl.ca>
>  wrote:
> >>
> >>> Hi,
> >>>
> >>> Here is the outline of a possible implementation :
> >>>
> >>> Execute SQL String
> >>> Create a List<IColumn<SQLResultRow>>
> >>> for each SQL result column:
> >>>    add a column to the list that displays one column of a SQLResultRow
> >>> Create a very simple ISortableDataProvider that returns the SQL result
> from
> >>> above
> >>> (make it more complex to implement sorting)
> >>> Create a DataTable using the column list and the data provider
> >>>
> >>>
> >>> On 22/07/2011 2:05 AM, davut uysal wrote:
> >>>
> >>>> Someone in another forum advised me this:
> >>>>
> >>>> ***
> >>>> Maybe in latest Wicket something changed but in 1.4.16 you can't
> change
> >>>> Columns in DataTable. So it's immutable in some sense.
> >>>>
> >>>> But you may replace whole DataTable component instead when your sql
> >>>> statement changes:
> >>>>
> >>>> form.add(new Button("sqlSubmit") {
> >>>>    void onSubmit() {
> >>>>      String sql = ...;
> >>>>      form.replace(createDataTable("**myDataTable", sql));
> >>>>    }
> >>>> })
> >>>> form.add(createDataTable("**myDataTable", null));
> >>>>
> >>>> Where createDataTable() creates DataTable using provided id and sql
> >>>> string.
> >>>> Also there is a convenient method Component.replaceWith(). Maybe it'll
> fit
> >>>> better to your coding style.
> >>>>
> >>>> ***
> >>>>
> >>>> I think this is what I need, but I dont know how to do. Can someone
> please
> >>>> help me to create below method?
> >>>>
> >>>> *createDataTable("wicketId", "SQL")*
> >>>>
> >>>> Thanks,
> >>>>
> >>>> On 21 July 2011 21:05, Andrew Fielden<andrew.fielden@power-**
> oasis.com<
> andrew.fielden@power-oasis.com>
> >>>>>
> >>>>> wrote:
> >>>>
> >>>>  I see your problem Davut, but I really don't think Wicket can solve
> it
> in
> >>>>>
> >>>>> the
> >>>>> way you want it to. As Martin said, you need an<entity>   to populate
> the
> >>>>> models used by the various Wicket components.
> >>>>> Could you somehow parse the SQL statement to extract the table name,
> and
> >>>>> find its meta data?
> >>>>>
> >>>>>
> >>>>> --
> >>>>> View this message in context:
> >>>>> http://apache-wicket.1842946. <http://apache-wicket.1842946.>**
> n4.nabble.com/dynamic-**
> >>>>> DataTable-tp3683514p3684513.**html<
>
> http://apache-wicket.1842946.n4.nabble.com/dynamic-DataTable-tp3683514p3684513.html
> >
> >>>>> Sent from the Users forum mailing list archive at Nabble.com.
> >>>>>
> >>>>> ------------------------------**------------------------------**
> >>>>> ---------
> >>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<
> users-unsubscribe@wicket.apache.org>
> >>>>> For additional commands, e-mail: users-help@wicket.apache.org
> >>>>>
> >>>>>
> >>>>>
> >>>
> ------------------------------**------------------------------**---------
> >>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<
> users-unsubscribe@wicket.apache.org>
> >>> For additional commands, e-mail: users-help@wicket.apache.org
> >>>
> >>>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>