You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Ivan Dudko <iv...@gmail.com> on 2010/01/08 13:23:00 UTC

Several entities and DataTable

Hello!

I am not using JPA and Spring. Write all with plain JDBC.
I am write page which displays data with DataTable using SortableDataProvider.
How i can display fields from another table (entity)?

Wicket says that no get method found.

Thank you!

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Several entities and DataTable

Posted by James Carman <jc...@carmanconsulting.com>.
Yes, so if you had a list of Milk objects, you could use a property
expression "honey.honeyName."  Nested property expressions work.

On Sun, Jan 10, 2010 at 10:31 AM, Ivan Dudko <iv...@gmail.com> wrote:
> James, You mean this?
>
> class Milk {
> int id;
> String milkName;
> Honey honey;
> // getters and setters
> }
>
> class Honey {
> int id;
> String honeyName;
> // getters and setters
> }
>
> 2010/1/10 James Carman <jc...@carmanconsulting.com>:
>> Can you "traverse" from Milk to Honey (or vise-versa)?  If so, then
>> just use a nested property expression (like "honey.hiveName" or
>> whatever).
>>
>> On Sun, Jan 10, 2010 at 9:51 AM, Ivan Dudko <iv...@gmail.com> wrote:
>>> I have two Pojo classes. For example, Milk and Honey.
>>> And also database tables with same structure. I am do not use ORM mapping.
>>>
>>> I write DAO class for class Milk that fetches data from the tables
>>> milk and honey at once.
>>> But i am in trouble how i can display this result set.
>>>
>>> I think that writing third Pojo MilkHoney for displaying this data is
>>> bad idea...
>>>
>>> Thank you!
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: 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
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 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


Re: Several entities and DataTable

Posted by Ivan Dudko <iv...@gmail.com>.
James, You mean this?

class Milk {
int id;
String milkName;
Honey honey;
// getters and setters
}

class Honey {
int id;
String honeyName;
// getters and setters
}

2010/1/10 James Carman <jc...@carmanconsulting.com>:
> Can you "traverse" from Milk to Honey (or vise-versa)?  If so, then
> just use a nested property expression (like "honey.hiveName" or
> whatever).
>
> On Sun, Jan 10, 2010 at 9:51 AM, Ivan Dudko <iv...@gmail.com> wrote:
>> I have two Pojo classes. For example, Milk and Honey.
>> And also database tables with same structure. I am do not use ORM mapping.
>>
>> I write DAO class for class Milk that fetches data from the tables
>> milk and honey at once.
>> But i am in trouble how i can display this result set.
>>
>> I think that writing third Pojo MilkHoney for displaying this data is
>> bad idea...
>>
>> Thank you!
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: 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
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Several entities and DataTable

Posted by James Carman <jc...@carmanconsulting.com>.
Can you "traverse" from Milk to Honey (or vise-versa)?  If so, then
just use a nested property expression (like "honey.hiveName" or
whatever).

On Sun, Jan 10, 2010 at 9:51 AM, Ivan Dudko <iv...@gmail.com> wrote:
> I have two Pojo classes. For example, Milk and Honey.
> And also database tables with same structure. I am do not use ORM mapping.
>
> I write DAO class for class Milk that fetches data from the tables
> milk and honey at once.
> But i am in trouble how i can display this result set.
>
> I think that writing third Pojo MilkHoney for displaying this data is
> bad idea...
>
> Thank you!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 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


Re: Several entities and DataTable

Posted by Ivan Dudko <iv...@gmail.com>.
I have two Pojo classes. For example, Milk and Honey.
And also database tables with same structure. I am do not use ORM mapping.

I write DAO class for class Milk that fetches data from the tables
milk and honey at once.
But i am in trouble how i can display this result set.

I think that writing third Pojo MilkHoney for displaying this data is
bad idea...

Thank you!

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Several entities and DataTable

Posted by Ivan Dudko <iv...@gmail.com>.
2010/1/10 Leo Erlandsson <Le...@tyringe.com>:
>
> I would use an SQL Join in the iterator(int first, int count) method to get
> data from the associated table and return the data in the returned Domain
> Objects.
>
> You could also do an SQL Query for each result in your iterator() method,
> but that would give you 1+n SQL Queries instead of just 1.
>
> Also, note that your code has several Security Vulnerabilities as it is
> susceptible to SQL Injection Attacks (!!!!!) if you let the user specify the
> Filter String:
>
> String tmp = filter.getName();
> sql = "where name like '%" + tmp + "%'";
>
>
>
>
>
> -----
> ---
> Leo Erlandsson, M. Sc.
> --
> View this message in context: http://old.nabble.com/Several-entities-and-DataTable-tp27075166p27097481.html
> Sent from the Wicket - User mailing list archive at Nabble.com.

Can you give me an example?

this is only for test:
 String tmp = filter.getName();
 sql = "where name like '%" + tmp + "%'";

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Several entities and DataTable

Posted by Leo Erlandsson <Le...@tyringe.com>.
I would use an SQL Join in the iterator(int first, int count) method to get
data from the associated table and return the data in the returned Domain
Objects.

You could also do an SQL Query for each result in your iterator() method,
but that would give you 1+n SQL Queries instead of just 1.

Also, note that your code has several Security Vulnerabilities as it is
susceptible to SQL Injection Attacks (!!!!!) if you let the user specify the
Filter String:

String tmp = filter.getName();
sql = "where name like '%" + tmp + "%'"; 





-----
---
Leo Erlandsson, M. Sc.
-- 
View this message in context: http://old.nabble.com/Several-entities-and-DataTable-tp27075166p27097481.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Several entities and DataTable

Posted by Ivan Dudko <iv...@gmail.com>.
This is DataProvider and ListPage.
All is fine where i work with only one entity.
My DAO returns data from table assotiated with this entity and another table.
How i can provide access to this data from my DataTable?


public class MyDomainDataProvider extends
SortableDataProvider<MyDomain> implements IFilterStateLocator {

    DataSource dataSource = QueryFactory.getDataSource();
    private final MyDomainDAOImpl dao = new MyDomainDAOImpl(dataSource);
    private MyDomain filter = new MyDomain();
    private String sql = new String();

    public MyDomainDataProvider() throws QueryException {
        // set default sort
        setSort("id", true);
        filter.setId(null);
    }

    public Iterator<? extends MyDomain> iterator(int first, int count) {
        SortParam sp = getSort();
        //String x = FilterCriterionFactory.getFilteredSQL(filter);
        String tmp = filter.getName();
        if (tmp != null) {
            sql = "where name like '%" + tmp + "%'";
        } else {
            sql = "where name like '%'";
        }
        Integer tmp2 = filter.getId();
        if (tmp2 != null) {
            sql += " and id like '%" + tmp2 + "%'";
        }

        return (Iterator<? extends MyDomain>)
dao.getDataAsEntity(MyDomain.class, first, count, sp.getProperty(),
sp.isAscending(), "select * from mydomain " + sql).iterator();
    }

    public IModel<MyDomain> model(MyDomain my) {
        return new Model<MyDomain>(my);
    }

    public int size() {
        String tmp = filter.getName();
        if (tmp != null) {
            //sql = "where name like '%" + tmp + "%'";
        } else {
            //sql = "where name like '%'";
        }
        Integer tmp2 = filter.getId();
        if (tmp2 != null) {
            sql += " and id like '%" + tmp2 + "%'";
        }
        return dao.getResultSetFullSize(MyDomainDAOImpl.SELECT_ALL_SQL + sql);
    }

    public Object getFilterState() {
        return filter;
    }

    public void setFilterState(Object state) {
        filter = (MyDomain) state;
    }
}


    public MyListPage(PageParameters params) throws QueryException {
        MyDataProvider provider = new MyDataProvider();

        IColumn[] columns = new IColumn[]{
            new PropertyColumn(new
Model<String>(getString("List.FieldName.Id")), "id", "id"),
            new TextFilteredPropertyColumn(new
Model<String>(getString("List.FieldName.Name")), "name", "name"),
            new TextFilteredPropertyColumn(new
Model<String>(getString("List.FieldName.Ip")), "ip", "ip"),
            new TextFilteredPropertyColumn(new
Model<String>(getString("List.FieldName.Port")), "port", "port"),
            new TextFilteredPropertyColumn(new
Model<String>(getString("List.FieldName.Description")), "description",
"description"),
            new PropertyColumn(new
Model<String>(getString("List.FieldName.NodeId")), "nodeid"),

            new FilteredAbstractColumn<Object>(new
Model<String>(getString("List.Actions"))) {

                public Component getFilter(String componentId,
FilterForm form) {
                    return new GoAndClearFilter(componentId, form, new
ResourceModel("List.Filter"), new ResourceModel("List.Clear"));
                }

                public void populateItem(Item cellItem, String
componentId, IModel rowModel) {
                    cellItem.add(new UserActionsPanel(componentId, rowModel));
                }
            }
        };

        AjaxDataTable dataTable = new AjaxDataTable("table", columns,
provider, 2);
        final FilterForm form = new FilterForm("filter-form", provider);
        dataTable.addTopToolbar(new FilterToolbar(dataTable, form, provider));
        form.add(dataTable);
        add(form);
    }

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Several entities and DataTable

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Show your code.

2010/1/8 Ivan Dudko <iv...@gmail.com>:
> Hello!
>
> I am not using JPA and Spring. Write all with plain JDBC.
> I am write page which displays data with DataTable using SortableDataProvider.
> How i can display fields from another table (entity)?
>
> Wicket says that no get method found.
>
> Thank you!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 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