How to use condition_sql in jdbcJdbcPageListSource?

17 views
Skip to first unread message

Terry

unread,
Nov 5, 2012, 6:11:44 AM11/5/12
to scooter-...@googlegroups.com
Hi John,

My requirement is to have a search bar(form) in the top of the page , and jump to the paged_list to show the result after submitting the form.

I tried to use ActionController.jdbcPaginator(Class, String,String) to create a paginator with the "condition_sql", but I found it did not work.

I traced the scooter src code, found the key_conditions_sql only invoked by TableGateWay in  Map constructFindSQL(Map,Map), which was never touched by jdbcPaginator.

Is here a bug or anything I missed ?

Waiting for your reply, thanks.

John Chen

unread,
Nov 5, 2012, 12:10:15 PM11/5/12
to scooter-...@googlegroups.com
Terry,

Certainly jdbcPaginator misses conditions_sql. The reason is that using conditions_sql in jdbcPaginator() would mean that you expose SQL in your URL. This is not desired in most situations for security reasons. 

I would suggest that you use QueryBuilder. The following is a sample action method which uses QueryBuilder and hides the business logic of constructing a SQL where clause:
    public String index() {
        if ("true".equals(p(Constants.PAGED))) {
            //Paginator page = jdbcPaginator(Post.class, params());
            int page = Integer.parseInt(p("npage"));
            int limit = Integer.parseInt(p("limit"));
            String conditionsSQL = construct your where clause here with business secret logic.
            Paginator page = Post.page(page).limit(limit).where(conditionsSQL).getPaginator();
            setViewData("post_page", page);
            return renderView("paged_list");
        }
        setViewData("posts", Post.findAll());
        return null;
    }

Hope this helps.

John

Terry

unread,
Nov 5, 2012, 1:04:58 PM11/5/12
to scooter-...@googlegroups.com
Thanks very much John !

在 2012年11月6日星期二UTC+8上午1时10分16秒,Scooter Framework写道:
Reply all
Reply to author
Forward
0 new messages