You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by nn kk <in...@abv.bg> on 2013/08/21 15:47:35 UTC

exception handling

 Hi,
I want to create my custom exception handling, I saw there are a few ways to replace the Exception Report Page or override the RequestExceptionHandler and again replace the default page. But is it possible to handle only specific type of exceptions, or exceptions from specific pages or forms, and to leave the rest to the default? It will be best if it can be done to redirect diferent exceptions to different pages again depending on the concrete page or form where the exception is thrown

Best Regards!

-----------------------------------------------------------------
Само сега спечели смартфон SAMSUNG и още много награди!виж
http://www.specheli.eu/specheli-textgbg.php

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


RE: Submitting id & value of a t:select component onChange

Posted by Lance Java <la...@googlemail.com>.
If you are generating a placeholder serverside and replacing it clientside,
there's no need to use a request parameter. You can just use the event
context.

You only need a request parameter when appending to the URL in javascript
rather than replacing a token.

Note that if you have ValueEncoders registered for your types, you don't
need to worry about String / Integer id's… you can use your domain objects
/ enums etc instead and let tapestry do the conversion for you.

RE: Submitting id & value of a t:select component onChange

Posted by Ben Titmarsh <be...@hotmail.co.uk>.
Thanks Lance,

Here's another effort.  I'm sure theres a better way to get the value into the request parameter than I've done here?  This generates a request URL like this:

/editcube:colourprofileoverridechanged/283021?newColourProfile=MONO_RED&t:ac=1

Page Class:

    public Object onColourProfileOverrideChanged(Integer cubeCardId, @RequestParameter(value="newColourProfile") String newColourProfile) throws InterruptedException {
        //Do Stuff
        return gridZone.getBody();
    }
    
    public String getColourProfileOverrideChangedUrl() {
        Link link = resources.createEventLink("ColourProfileOverrideChanged", cubeCard.getId());
        link.addParameter("newColourProfile", "[VALUE]");
        return link.toAbsoluteURI();
    }

Component:

<t:select t:id="colourProfileOverride" t:clientId="colourProfileOverride" class="cubeAjaxUpdate" t:value="cubeCard.colourCombinationOverride" blankOption="never" data-url="${ColourProfileOverrideChangedUrl}" />

Javascript:

                 $(document).find(".cubeAjaxUpdate").change(function() {    
                    $("#gridZone").tapestryZone("update", {
                        url: $(this).data("url").replace('[VALUE]', $(this).val()),
                        params: parameters
                    });
                });

Cheers,
Ben.

> Date: Wed, 21 Aug 2013 18:26:37 +0100
> Subject: RE: Submitting id & value of a t:select component onChange
> From: lance.java@googlemail.com
> To: users@tapestry.apache.org
> 
> You'll need to append a request parameter to a serverside generated event
> url and use @RequestParam serverside to get the value in the event
 		 	   		  

RE: Submitting id & value of a t:select component onChange

Posted by Lance Java <la...@googlemail.com>.
You'll need to append a request parameter to a serverside generated event
url and use @RequestParam serverside to get the value in the event

RE: Submitting id & value of a t:select component onChange

Posted by Ben Titmarsh <be...@hotmail.co.uk>.
Thanks Lance,

Here is an updated effort using tapestryZone.  This is much better as the zone was not being refreshed before!

                 var parameters = {};
                 parameters["t:zoneid"] = gridZone;
                 
                 $(document).find(".cubeAjaxUpdate").change(function() {    
                    $("#gridZone").tapestryZone("update", {
                        url: "/editcube:"+$(this).data("event")+"/"+$(this).data("cardid")+"/"+$(this).val()+"?t:ac=1",
                        params: parameters
                    });
                });

However, I'm unsure how I could use component resources to generate the url on the server side.  I presume you are referring to CreateEventLink (http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ComponentResourcesCommon.html#createEventLink%28java.lang.String,%20java.lang.Object...%29).  However at the time I would generate this link I don't have the value of the field (the second context param) so how can I generate the whole URL like you describe?

> Date: Wed, 21 Aug 2013 17:18:08 +0100
> Subject: RE: Submitting id & value of a t:select component onChange
> From: lance.java@googlemail.com
> To: users@tapestry.apache.org
> 
> 1. You should not generate your URL's clientside. Instead, generate via
> ComponentResources serverside and add a "data-url" attribute instead.
> 
> 2.  When I look at the tapestry-jquery page here
> http://tapestry5-jquery.com/mixins/docsbind
> 
> I can see an include for bind.js (
> http://tapestry5-jquery.com/assets/40a195d04cdc0bf0/app/assets/mixins/bind/bind.js
> )
> 
> In bind.js, I can see that tapestry-jquery uses element.tapestryZone(…) to
> update a zone. I'd probably do the same instead of using $.ajax(…)
 		 	   		  

RE: Submitting id & value of a t:select component onChange

Posted by Lance Java <la...@googlemail.com>.
1. You should not generate your URL's clientside. Instead, generate via
ComponentResources serverside and add a "data-url" attribute instead.

2.  When I look at the tapestry-jquery page here
http://tapestry5-jquery.com/mixins/docsbind

I can see an include for bind.js (
http://tapestry5-jquery.com/assets/40a195d04cdc0bf0/app/assets/mixins/bind/bind.js
)

In bind.js, I can see that tapestry-jquery uses element.tapestryZone(…) to
update a zone. I'd probably do the same instead of using $.ajax(…)

RE: Submitting id & value of a t:select component onChange

Posted by Ben Titmarsh <be...@hotmail.co.uk>.
Well thanks a lot for your advice Lance, this worked beautifully!  For reference I added the following data attributes to each of my selects (with a unique event name for each select type):

data-cardid="${cubeCard.id}" data-event="colourprofileoverridechanged"

Then I wrote the following JS snippet to perform the ajax submission & zone update:

                 $(document).find(".cubeAjaxUpdate").change(function() {
                    $("#savingUpdate").show(); 
                   
                    request = $.ajax({
                        url: "/editcube:"+$(this).data("event")+"/"+$(this).data("cardid")+"/"+$(this).val()+"?t:ac=1",
                        type: "post",
                        data: "t:zoneid=gridZone"
                    });
                
                    request.done(function (response, textStatus, jqXHR){
                        $("#savingUpdate").hide(); 
                    });
                });

> Date: Wed, 21 Aug 2013 15:55:06 +0100
> Subject: Re: Submitting id & value of a t:select component onChange
> From: lance.java@googlemail.com
> To: users@tapestry.apache.org
> 
> tapestry-jquery has rewritten Tapestry's javascript and I'm not too
> familiar with it. I'm sure there's a function in there to trigger a zone
> update.
> On 21 Aug 2013 15:26, "Lance Java" <la...@googlemail.com> wrote:
> 
> > You could use data attributes and some clientside jquery just like a
> > non-tapestry app.
> >
> > TML
> > <t:grid row="current" id="myGrid">
> >    <p:someCell><t:select … data-foo="current.foo" data-bar="current.bar" …
> > /></p:someCell>
> > </t:grid>
> >
> >
> >
> > JS
> > $("#myGrid").find("select").change(function() {
> >    var select = $(this);
> >    var foo = select.data("foo");
> >    var bar = select.data("bar");
> >    doStuff(foo, bar);
> >
> > };
> >
 		 	   		  

Re: Submitting id & value of a t:select component onChange

Posted by Lance Java <la...@googlemail.com>.
tapestry-jquery has rewritten Tapestry's javascript and I'm not too
familiar with it. I'm sure there's a function in there to trigger a zone
update.
On 21 Aug 2013 15:26, "Lance Java" <la...@googlemail.com> wrote:

> You could use data attributes and some clientside jquery just like a
> non-tapestry app.
>
> TML
> <t:grid row="current" id="myGrid">
>    <p:someCell><t:select … data-foo="current.foo" data-bar="current.bar" …
> /></p:someCell>
> </t:grid>
>
>
>
> JS
> $("#myGrid").find("select").change(function() {
>    var select = $(this);
>    var foo = select.data("foo");
>    var bar = select.data("bar");
>    doStuff(foo, bar);
>
> };
>

RE: Submitting id & value of a t:select component onChange

Posted by Ben Titmarsh <be...@hotmail.co.uk>.
Thanks Lance, this looks great!  I've not written any raw jQuery Ajax code, in the past I've just left this all to Tapestry.  Presumably I should be using this: http://api.jquery.com/jQuery.ajax/ Or is there a preferred approach?

> Date: Wed, 21 Aug 2013 15:26:56 +0100
> Subject: Re: Submitting id & value of a t:select component onChange
> From: lance.java@googlemail.com
> To: users@tapestry.apache.org
> 
> You could use data attributes and some clientside jquery just like a
> non-tapestry app.
> 
> TML
> <t:grid row="current" id="myGrid">
>    <p:someCell><t:select … data-foo="current.foo" data-bar="current.bar" …
> /></p:someCell>
> </t:grid>
> 
> 
> 
> JS
> $("#myGrid").find("select").change(function() {
>    var select = $(this);
>    var foo = select.data("foo");
>    var bar = select.data("bar");
>    doStuff(foo, bar);
> 
> };
 		 	   		  

Re: Submitting id & value of a t:select component onChange

Posted by Lance Java <la...@googlemail.com>.
You could use data attributes and some clientside jquery just like a
non-tapestry app.

TML
<t:grid row="current" id="myGrid">
   <p:someCell><t:select … data-foo="current.foo" data-bar="current.bar" …
/></p:someCell>
</t:grid>



JS
$("#myGrid").find("select").change(function() {
   var select = $(this);
   var foo = select.data("foo");
   var bar = select.data("bar");
   doStuff(foo, bar);

};

Submitting id & value of a t:select component onChange

Posted by Ben Titmarsh <be...@hotmail.co.uk>.
I have a Tapestry Grid component with three columns.  Each cell contains a select component that I want to submit their id and value via Ajax when the value changes.  The id isn't the client side component id but rather an id that the server uses to lookup and save the value that has changed.

In order to perform this Ajax request I am using the jQuery/bind mixin.  My grid typically has around 50 rows and as a result the bind mixin ends up generating a boatload of Javascript like this:

Tapestry.init({
  "activate" : [
    "card"
  ],
  "jqbind" : [
{
      "elementId" : "colourProfileOverride_22",
      "zoneUpdate" : "highlight",
      "hideTime" : "500",
      "callback" : "addContext",
      "eventType" : "change",
      "preventDefault" : true,
      "url" : "http://localhost:8080/editcube:colourprofileoverridechanged/65/CoNtExT?t:ac=1",
      "zoneId" : "gridZone",
      "hideEffect" : "slide",
      "contextMarker" : "CoNtExT"
    },
    {
      "elementId" : "convertedManaCostOverride_22",
      "zoneUpdate" : "highlight",
      "hideTime" : "500",
      "callback" : "addContext",
      "eventType" : "change",
      "preventDefault" : true,
      "url" : "http://localhost:8080/editcube:convertedmanacostoverridechanged/65/CoNtExT?t:ac=1",
      "zoneId" : "gridZone",
      "hideEffect" : "slide",
      "contextMarker" : "CoNtExT"
    },
    {
      "elementId" : "superTypeOverride_22",
      "zoneUpdate" : "highlight",
      "hideTime" : "500",
      "callback" : "addContext",
      "eventType" : "change",
      "preventDefault" : true,
      "url" : "http://localhost:8080/editcube:supertypeoverridechanged/65/CoNtExT?t:ac=1",
      "zoneId" : "gridZone",
      "hideEffect" : "slide",
      "contextMarker" : "CoNtExT"
    }

  ]
});

This is really slowing down my page load time which is a problem in particular for mobile users.  I'm using the bind mixin because it's the only technique that I could find that can add the new value of the select component as a context parameter using bind.callback and the addContext function below.  Adding the value to the context is the only way I've found to get this information back to the server in the Ajax request.

Can anyone advise me on how to either cut down the Javascript generated by the jquery/bind mixin or describe an alternative approach for submitting Select values via Ajax such that the request includes the id and value of the select that has changed?  For reference here is a snippet of my grid:

<t:zone t:id="gridZone" id="gridZone">

<script type="text/javascript">
    function addContext(event,ui,url) { 
        url.addContext(event.target.value);
     }             
</script>

    <t:grid id="editCubeGrid" source="cubeCards" row="cubeCard" model="cubeCardModel" inPlace="true" rowsPerPage="rows" pagerPosition="both"
                reorder="colourProfile,convertedManaCost,superTypeCombinationOverride">

<p:colourProfileCell>
        <t:select t:id="colourProfileOverride" t:clientId="colourProfileOverride" class="cubeAjaxUpdate" t:value="cubeCard.colourCombinationOverride" blankOption="never" t:mixins="jquery/bind" bind.context="cubeCard.id" bind.event="ColourProfileOverrideChanged" bind.eventType="change" bind.zone="gridZone" bind.callback="addContext"/>
</p:colourProfileCell>
<p:convertedManaCostCell>
        <t:select t:id="convertedManaCostOverride" t:clientId="convertedManaCostOverride" model="literal:0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30" class="cubeAjaxUpdate" t:value="cubeCard.convertedManaCostOverride" blankOption="never" t:mixins="jquery/bind" bind.context="cubeCard.id" bind.event="ConvertedManaCostOverrideChanged" bind.eventType="change" bind.zone="gridZone" bind.callback="addContext" />
</p:convertedManaCostCell>
<p:superTypeCombinationOverrideCell>
        <t:select t:id="superTypeOverride" t:clientId="superTypeOverride" class="cubeAjaxUpdate" t:value="cubeCard.superTypeCombinationOverride" blankOption="never" t:mixins="jquery/bind" bind.context="cubeCard.id" bind.event="SuperTypeOverrideChanged" bind.eventType="change" bind.zone="gridZone"  bind.callback="addContext" />
</p:superTypeCombinationOverrideCell>

    </t:grid>
</t:zone>


Much appreciated,
Ben.
 		 	   		  

Re: exception handling

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 21 Aug 2013 10:47:35 -0300, nn kk <in...@abv.bg> wrote:

>  Hi,

Hi!

> I want to create my custom exception handling, I saw there are a few  
> ways to replace the Exception Report Page or override the  
> RequestExceptionHandler and again replace the default page. But is it  
> possible to handle only specific type of exceptions, or exceptions from  
> specific pages or forms, and to leave the rest to the default?

Advise or decorate RequestExceptionHandler using Tapestry-IoC instead of  
overriding.

-- 
Thiago H. de Paula Figueiredo

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


Re: exception handling

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
Take a look at Tynamo tapestry-exceptionpage module.
http://docs.codehaus.org/display/TYNAMO/tapestry-exceptionpage+guide

On Aug 21, 2013, at 9:47 AM, nn kk wrote:

> Hi,
> I want to create my custom exception handling, I saw there are a few ways to replace the Exception Report Page or override the RequestExceptionHandler and again replace the default page. But is it possible to handle only specific type of exceptions, or exceptions from specific pages or forms, and to leave the rest to the default? It will be best if it can be done to redirect diferent exceptions to different pages again depending on the concrete page or form where the exception is thrown
> 
> Best Regards!
> 
> -----------------------------------------------------------------
> Само сега спечели смартфон SAMSUNG и още много награди!виж
> http://www.specheli.eu/specheli-textgbg.php
> 
> ---------------------------------------------------------------------
> 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