You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by George Christman <gc...@cardaddy.com> on 2013/10/21 03:52:57 UTC

How do I use select component to reload page?

Hello, I'm building my own PageRow component and I'm trying to figure out
how to reload the page after changing the select value from say 10 results
to 50. I need to set a query parameter during the refresh too, I thought I
could do this using the onChanged event, but that does not work. Any one
have any thoughts on how to do this?

-- 
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York

Re: How do I use select component to reload page?

Posted by George Christman <gc...@cardaddy.com>.
So I created a little mixin to handle this, I'm not sure if it's the best
way to go about this, so I was hoping you guys could give me some advise on
this. I'm still utilizing the select event handler "change", but very green
to requireJs.

select-reload.js

define(["t5/core/ajax", "./jquery"], function(ajax, $) {
    return function(spec) {
        $("#" + spec.id).change(function() {
            ajax(spec.url, {
                type: "POST",
                dataType: "json",
                data: {
                    "t:selectvalue": $(this).val()
                },
                contentType: "application/x-www-form-urlencoded",
                success: function(response) {
                    return response;
                }
            });
        });
    };
});

SelectReload mixin

public class SelectReload {

    public static final String CHANGE_EVENT = "change";
    @InjectContainer
    private Field field;
    @Inject
    private ComponentResources resources;
    @Environmental
    private JavaScriptSupport jsSupport;

    void afterRender() {
        Link link = resources.createEventLink(CHANGE_EVENT);
        JSONObject spec = new JSONObject("id", field.getClientId(), "url",
link.toURI());

        jsSupport.require("select-reload").with(spec);
    }

}

page.java

    Object onValueChangedFromRowsPerPage(Integer rowsPerPage) {
        this.rowsPerPage = rowsPerPage;
        return this;
    }




On Sun, Oct 20, 2013 at 9:52 PM, George Christman
<gc...@cardaddy.com>wrote:

> Hello, I'm building my own PageRow component and I'm trying to figure out
> how to reload the page after changing the select value from say 10 results
> to 50. I need to set a query parameter during the refresh too, I thought I
> could do this using the onChanged event, but that does not work. Any one
> have any thoughts on how to do this?
>
> --
> George Christman
> www.CarDaddy.com
> P.O. Box 735
> Johnstown, New York
>
>


-- 
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York