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 2012/03/02 18:35:04 UTC

Reloading zone from custom event handler

Hello, I'm using Tapestry-Jquery and I'm trying to get the zone to reload.
I'm able to get the request parameter values without issue, just won't
reload the zone. 

I have the following method

    @OnEvent(value = "mySubmit")
    Object ajaxLink() {
           value = request.getParameter("value");
           System.out.println(value);
           return zone.getBody();
    }

    void afterRender() {

        Link link = resources.createEventLink("mySubmit");
        JSONObject json = new JSONObject();
        json.put("linkId", "ajaxLink");
        json.put("idInput", "contactName");
        json.put("zoneId", "vendorZone");
        json.put("url", link.toAbsoluteURI());

        js.addInitializerCall("mySubmit", json);
    }

I'm using the following script to handle the ajax

        function init(spec) {
            $("#" + spec.id).bind("click", function(){
                $.ajax({
                    url: spec.url, 
                    data: {value : $("#" + spec.idInput).val()}
                }); 
            });
        }

tml

<input t:type="textfield" t:id="contactName"/>
Test Link    

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Reloading-zone-from-custom-event-handler-tp5531638p5531638.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Resolved: Re: Reloading zone from custom event handler

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, 02 Mar 2012 15:29:21 -0300, George Christman  
<gc...@cardaddy.com> wrote:

> Would you mind elaborating a bit more on "It should be created inside the
> component itself. " Thanks Thiago.

You shouldn't worry at all about event URLs, just use  
ComponentResources.createEventLink() to create them. If you're creating a  
link to be used inside a component, the call to that method should be  
inside the component class, using the ComponentResources of that class.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Resolved: Re: Reloading zone from custom event handler

Posted by George Christman <gc...@cardaddy.com>.
Would you mind elaborating a bit more on "It should be created inside the
component itself. " Thanks Thiago. 

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Reloading-zone-from-custom-event-handler-tp5531638p5531787.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Resolved: Re: Reloading zone from custom event handler

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, 02 Mar 2012 15:08:37 -0300, George Christman  
<gc...@cardaddy.com> wrote:

> Thiago, is that a better solution than what I just recently posted as a
> solution?

I guess they're equivalent.

> Also, I can't figure out how to generate a url with the component in it.
>
> Link link = resources.createEventLink("mySubmit");
> link.toAbsoluteURI()

It should be created inside the component itself.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Resolved: Re: Reloading zone from custom event handler

Posted by George Christman <gc...@cardaddy.com>.
Thiago, is that a better solution than what I just recently posted as a
solution?

Also, I can't figure out how to generate a url with the component in it. 

Link link = resources.createEventLink("mySubmit");
link.toAbsoluteURI()

only gives me 
/eprs/testtemplate:mysubmit

but I need

/eprs/testtemplate.vendorzone:mysubmit

Any Suggestions?

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Reloading-zone-from-custom-event-handler-tp5531638p5531713.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Resolved: Re: Reloading zone from custom event handler

Posted by George Christman <gc...@cardaddy.com>.
Resolved

Just needed to remove $.ajax and add tapestryZone and pass in my parameters. 

            $("#" + spec.linkId).bind("click", function(){
                var specs = {
                    url: "/eprs/testtemplate.vendorzone:mysubmit",
                    params : {value : $("#" + spec.idInput).val()}
                };
                
                $('#vendorZone').tapestryZone("update", specs);
            });


--
View this message in context: http://tapestry.1045711.n5.nabble.com/Reloading-zone-from-custom-event-handler-tp5531638p5531668.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Reloading zone from custom event handler

Posted by George Christman <gc...@cardaddy.com>.
Thanks Guys, I was able to combine a little from the both of you to come up
with a solution. I'd like to start by saying, I was completely unaware of
t:type="any" , what a life saver. I manage to find that within the bind
code. 

Anyhow I developed a simple mixin enabling you to submit a single value to
the backend. Works like so. 

Once again, thanks. 

         Display Addresses 

the mixin

    public void afterRender() {
        Link link = resources.createEventLink("inPlace");

        JSONObject json = new JSONObject();

        json.put("id", element.getClientId());
        json.put("idInput", idInput);
        json.put("zoneId", zone);
        json.put("url", link.toAbsoluteURI());

        js.addInitializerCall("inPlace", json);
    }

this js

(function( $ ) {
    T5.extendInitializers(function(){
    
        function init(spec) {
            
            $("#" + spec.id).bind("click", function(){
                var specs = {
                    url: spec.url,
                    params : {value : $("#" + spec.idInput).val()}
                };
                
                $("#" + spec.zoneId).tapestryZone("update", specs);
            });
        }
        return {
            mySubmit: init
        };

    });
    
}) ( jQuery );

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Reloading-zone-from-custom-event-handler-tp5531638p5532289.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Reloading zone from custom event handler

Posted by François Facon <fr...@atos.net>.
Hi George
did you try the bind mixin?

see documentation at http://tapestry5-jquery.com/mixins/docsbind

and test at

https://github.com/got5/tapestry5-jquery/blob/master/src/test/java/org/got5/tapestry5/jquery/pages/Bind.java

and

https://github.com/got5/tapestry5-jquery/blob/master/src/test/resources/org/got5/tapestry5/jquery/pages/Bind.tml

2012/3/2 George Christman <gc...@cardaddy.com>:
> Hello, I'm using Tapestry-Jquery and I'm trying to get the zone to reload.
> I'm able to get the request parameter values without issue, just won't
> reload the zone.
>
> I have the following method
>
>    @OnEvent(value = "mySubmit")
>    Object ajaxLink() {
>           value = request.getParameter("value");
>           System.out.println(value);
>           return zone.getBody();
>    }
>
>    void afterRender() {
>
>        Link link = resources.createEventLink("mySubmit");
>        JSONObject json = new JSONObject();
>        json.put("linkId", "ajaxLink");
>        json.put("idInput", "contactName");
>        json.put("zoneId", "vendorZone");
>        json.put("url", link.toAbsoluteURI());
>
>        js.addInitializerCall("mySubmit", json);
>    }
>
> I'm using the following script to handle the ajax
>
>        function init(spec) {
>            $("#" + spec.id).bind("click", function(){
>                $.ajax({
>                    url: spec.url,
>                    data: {value : $("#" + spec.idInput).val()}
>                });
>            });
>        }
>
> tml
>
> <input t:type="textfield" t:id="contactName"/>
> Test Link
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Reloading-zone-from-custom-event-handler-tp5531638p5531638.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

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


Re: Reloading zone from custom event handler

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Fri, 02 Mar 2012 14:35:04 -0300, George Christman  
<gc...@cardaddy.com> wrote:

> Hello, I'm using Tapestry-Jquery and I'm trying to get the zone to  
> reload.
> I'm able to get the request parameter values without issue, just won't
> reload the zone.

Hi!

Your JavaScript must have something like this:

Tapestry.findZoneManager(element);
zoneObject.updateFromUrl(updateUrl)

ZoneManager, the object returned by Tapestry.findZoneManager, takes care  
of everything for zone updates.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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