You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "lidijaldo ." <li...@gmail.com> on 2013/10/30 14:49:33 UTC

Simply refresh a zone after datatable record edit - not so simple?

I thought this should be simple but I can't seem to find the solution.

I have a datatable displayed on my page. After I successfully edit some
row, I would like to refresh a zone on my page.

This is the relevant part of my .tml file, let's say I'm trying to refresh
current time after I edited a row:

<table t:type="jquery/datatable" t:id="najdiEdiDataTable"
t:source="datasource"
                       t:row="moduleItem" t:rowIndex="index"
t:model="sourcemodel"
                       t:rowsPerPage="10" t:options="dataTableOptions" />

<t:zone t:id="boxZone" id="boxZone">
    ${getTime()}
</t:zone>



My java code:
At the end of the edit method, before I return response to re-draw
datatable with the modified objects, I'm also trying to refresh the above
zone:

@InjectComponent
@Property
private Zone boxZone;

@OnEvent(component = DATATABLE_ID, value = EVENT_EDITOR_EDIT)
    public Object edit(@RequestParameter("action") String action) throws
Exception {

        .... // edit and save object

        // refresh module box
        logger.debug("request.isXHR() = " + request.isXHR());      // this
outputs "true"
    ajaxResponseRenderer.addRender("boxZone", boxZone);

        return new TextStreamResponse("application/json",
response.toString());
}

public String getTime() {
    return new java.util.Date().toString();
}


But it seems that ajaxResponseRenderer.addRender("boxZone", boxZone);
doesn't do anything. Am I missing something? Isn't it that simple?

Regards,
Lidija

Re: Simply refresh a zone after datatable record edit - not so simple?

Posted by "lidijaldo ." <li...@gmail.com>.
Each of the row in my datatable represents an object with an image that
should be displayed in a zone. The zone should refresh after each row
change because the image for that object can be changed.

What I did was simply refresh the whole page with JavaScript after the row
was successfully edited (and file uploaded through editor). There's
probably some more elegant solution but it's ok for what I need:

So I'm calling location.reload(); on editor's onSubmitSuccess. If success,
location.reload() then reloads the whole page and object in the zone is
displayed ok.

Regards,
Lidija

Re: Simply refresh a zone after datatable record edit - not so simple?

Posted by "lidijaldo ." <li...@gmail.com>.
Bugger :-/. I didn't know that, thanks.

My current JSON response is:

{
  "row" : {
    "validTo" : "30-11-2013",
    "id" : 19,
    "imageFilename" : "",
    "title" : "Jesen",
    "url2" : "http://blah.com",
    "validFrom" : "30-10-2013",
    "active" : true,
    "url" : "http://www.blah2.com"
  }
}

This is the data for the given object / row in the datatable.

I tried to do as you and Nathan suggested - changed the method to return
void. If I don't return StreamResponse, I get the following JavaScript
alert:
"DataTables warning (table id = 'najdiEdiDataTable'): Requested unknown
parameter 'id' from the data source for row 0"

In Firebug it seems I get a response for the zone though:
{

  "zones" : {    "boxZone" : "\nMon Nov 04 06:20:47 CET 2013\n"  }}

But the zone doesn't refresh. Maybe because of the Javascript alert?

Is there another way to refresh a zone after I edit a row in a datatable?

Regards,
Lidija

On Wed, Oct 30, 2013 at 4:43 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Wed, 30 Oct 2013 11:49:33 -0200, lidijaldo . <li...@gmail.com>
> wrote:
>
>  @OnEvent(component = DATATABLE_ID, value = EVENT_EDITOR_EDIT)
>>     public Object edit(@RequestParameter("action") String action) throws
>> Exception {
>>
>>         .... // edit and save object
>>
>>         // refresh module box
>>         logger.debug("request.isXHR() = " + request.isXHR());      // this
>> outputs "true"
>>     ajaxResponseRenderer.addRender("boxZone", boxZone);
>>
>>         return new TextStreamResponse("application/json",
>> response.toString());
>> }
>>
>
> You either use AjaxResponseRenderer.addRender() or return a
> StreamResponse, but not both at the same time. It's like trying to give two
> answers for the same requests. As you want to refresh a zone, you shouldn't
> return a StreamResponse.
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Simply refresh a zone after datatable record edit - not so simple?

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 30 Oct 2013 11:49:33 -0200, lidijaldo . <li...@gmail.com>  
wrote:

> @OnEvent(component = DATATABLE_ID, value = EVENT_EDITOR_EDIT)
>     public Object edit(@RequestParameter("action") String action) throws
> Exception {
>
>         .... // edit and save object
>
>         // refresh module box
>         logger.debug("request.isXHR() = " + request.isXHR());      //  
> this
> outputs "true"
>     ajaxResponseRenderer.addRender("boxZone", boxZone);
>
>         return new TextStreamResponse("application/json",
> response.toString());
> }

You either use AjaxResponseRenderer.addRender() or return a  
StreamResponse, but not both at the same time. It's like trying to give  
two answers for the same requests. As you want to refresh a zone, you  
shouldn't return a StreamResponse.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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


Re: Simply refresh a zone after datatable record edit - not so simple?

Posted by Nathan Quirynen <na...@pensionarchitects.be>.
Why do you return following in the event?

return new TextStreamResponse("application/json", response.toString());


Does it work if you return void?

On 30/10/13 15:25, lidijaldo . wrote:
> Thank you for your response.
>
> I changed the call to addRender:
> ajaxResponseRenderer.addRender(boxZone);
>
> I restarted the application.
>
> I'm using Firebug but absolutely nothing happens that's connected to the
> zone. There's an ajax request to edit the row and I can see the request -
> the POST parameters and the JSON response that's returned to the browser.
>
> But nothing concerning the zone. There must be something I'm missing.
> There's no java exception and no JavaScript error.
>
> Is there any simple tapestry example for refreshing the zone from java?
>
> Regards,
> Lidija
>
>
> On Wed, Oct 30, 2013 at 2:57 PM, Dmitry Gusev <dm...@gmail.com>wrote:
>
>> Looks ok to me at first glance.
>>
>>>     ajaxResponseRenderer.addRender("boxZone", boxZone);
>> You don't have to specify clientId when you passing a zone here and this
>> zone has id attribute declared in template.
>>
>> Try inspecting network activity in your browser's developer tools (firebug,
>> etc.) to see how zone update works, i.e. what's returned to client when you
>> call ajaxResponseRenderer.addRender(...);
>>
>> There is a bug in tapestry when you have to restart the app if you changed
>> zone id in your template -- it won't be picked up without restart.
>>
>>
>> On Wed, Oct 30, 2013 at 5:49 PM, lidijaldo . <li...@gmail.com> wrote:
>>
>>> I thought this should be simple but I can't seem to find the solution.
>>>
>>> I have a datatable displayed on my page. After I successfully edit some
>>> row, I would like to refresh a zone on my page.
>>>
>>> This is the relevant part of my .tml file, let's say I'm trying to
>> refresh
>>> current time after I edited a row:
>>>
>>> <table t:type="jquery/datatable" t:id="najdiEdiDataTable"
>>> t:source="datasource"
>>>                        t:row="moduleItem" t:rowIndex="index"
>>> t:model="sourcemodel"
>>>                        t:rowsPerPage="10" t:options="dataTableOptions" />
>>>
>>> <t:zone t:id="boxZone" id="boxZone">
>>>     ${getTime()}
>>> </t:zone>
>>>
>>>
>>>
>>> My java code:
>>> At the end of the edit method, before I return response to re-draw
>>> datatable with the modified objects, I'm also trying to refresh the above
>>> zone:
>>>
>>> @InjectComponent
>>> @Property
>>> private Zone boxZone;
>>>
>>> @OnEvent(component = DATATABLE_ID, value = EVENT_EDITOR_EDIT)
>>>     public Object edit(@RequestParameter("action") String action) throws
>>> Exception {
>>>
>>>         .... // edit and save object
>>>
>>>         // refresh module box
>>>         logger.debug("request.isXHR() = " + request.isXHR());      //
>> this
>>> outputs "true"
>>>     ajaxResponseRenderer.addRender("boxZone", boxZone);
>>>
>>>         return new TextStreamResponse("application/json",
>>> response.toString());
>>> }
>>>
>>> public String getTime() {
>>>     return new java.util.Date().toString();
>>> }
>>>
>>>
>>> But it seems that ajaxResponseRenderer.addRender("boxZone", boxZone);
>>> doesn't do anything. Am I missing something? Isn't it that simple?
>>>
>>> Regards,
>>> Lidija
>>>
>>
>>
>> --
>> Dmitry Gusev
>>
>> AnjLab Team
>> http://anjlab.com
>>


-- 

Een klare kijk op aanvullende pensioenen

*Nathan Quirynen*
03 340 04 60 | 0494 28 45 15
nathan@pensionarchitects.be <ma...@pensionarchitects.be>

Follow us on Web <http://www.pensionarchitects.be> | Twitter
<http://www.twitter.com/pen_arch> | LinkedIn
<http://www.linkedin.com/company/pension-architects> | RSS
<http://feeds.feedburner.com/pensionarchitects> | YouTube
<http://www.youtube.com/pensionarchitects>


Re: Simply refresh a zone after datatable record edit - not so simple?

Posted by Dmitry Gusev <dm...@gmail.com>.
You can find simple example in the maven archetype for tapestry5:

http://tapestry.apache.org/getting-started.html

Can you post your JSON response here?


On Wed, Oct 30, 2013 at 6:25 PM, lidijaldo . <li...@gmail.com> wrote:

> Thank you for your response.
>
> I changed the call to addRender:
> ajaxResponseRenderer.addRender(boxZone);
>
> I restarted the application.
>
> I'm using Firebug but absolutely nothing happens that's connected to the
> zone. There's an ajax request to edit the row and I can see the request -
> the POST parameters and the JSON response that's returned to the browser.
>
> But nothing concerning the zone. There must be something I'm missing.
> There's no java exception and no JavaScript error.
>
> Is there any simple tapestry example for refreshing the zone from java?
>
> Regards,
> Lidija
>
>
> On Wed, Oct 30, 2013 at 2:57 PM, Dmitry Gusev <dmitry.gusev@gmail.com
> >wrote:
>
> > Looks ok to me at first glance.
> >
> > >     ajaxResponseRenderer.addRender("boxZone", boxZone);
> > You don't have to specify clientId when you passing a zone here and this
> > zone has id attribute declared in template.
> >
> > Try inspecting network activity in your browser's developer tools
> (firebug,
> > etc.) to see how zone update works, i.e. what's returned to client when
> you
> > call ajaxResponseRenderer.addRender(...);
> >
> > There is a bug in tapestry when you have to restart the app if you
> changed
> > zone id in your template -- it won't be picked up without restart.
> >
> >
> > On Wed, Oct 30, 2013 at 5:49 PM, lidijaldo . <li...@gmail.com>
> wrote:
> >
> > > I thought this should be simple but I can't seem to find the solution.
> > >
> > > I have a datatable displayed on my page. After I successfully edit some
> > > row, I would like to refresh a zone on my page.
> > >
> > > This is the relevant part of my .tml file, let's say I'm trying to
> > refresh
> > > current time after I edited a row:
> > >
> > > <table t:type="jquery/datatable" t:id="najdiEdiDataTable"
> > > t:source="datasource"
> > >                        t:row="moduleItem" t:rowIndex="index"
> > > t:model="sourcemodel"
> > >                        t:rowsPerPage="10" t:options="dataTableOptions"
> />
> > >
> > > <t:zone t:id="boxZone" id="boxZone">
> > >     ${getTime()}
> > > </t:zone>
> > >
> > >
> > >
> > > My java code:
> > > At the end of the edit method, before I return response to re-draw
> > > datatable with the modified objects, I'm also trying to refresh the
> above
> > > zone:
> > >
> > > @InjectComponent
> > > @Property
> > > private Zone boxZone;
> > >
> > > @OnEvent(component = DATATABLE_ID, value = EVENT_EDITOR_EDIT)
> > >     public Object edit(@RequestParameter("action") String action)
> throws
> > > Exception {
> > >
> > >         .... // edit and save object
> > >
> > >         // refresh module box
> > >         logger.debug("request.isXHR() = " + request.isXHR());      //
> > this
> > > outputs "true"
> > >     ajaxResponseRenderer.addRender("boxZone", boxZone);
> > >
> > >         return new TextStreamResponse("application/json",
> > > response.toString());
> > > }
> > >
> > > public String getTime() {
> > >     return new java.util.Date().toString();
> > > }
> > >
> > >
> > > But it seems that ajaxResponseRenderer.addRender("boxZone", boxZone);
> > > doesn't do anything. Am I missing something? Isn't it that simple?
> > >
> > > Regards,
> > > Lidija
> > >
> >
> >
> >
> > --
> > Dmitry Gusev
> >
> > AnjLab Team
> > http://anjlab.com
> >
>



-- 
Dmitry Gusev

AnjLab Team
http://anjlab.com

Re: Simply refresh a zone after datatable record edit - not so simple?

Posted by "lidijaldo ." <li...@gmail.com>.
Thank you for your response.

I changed the call to addRender:
ajaxResponseRenderer.addRender(boxZone);

I restarted the application.

I'm using Firebug but absolutely nothing happens that's connected to the
zone. There's an ajax request to edit the row and I can see the request -
the POST parameters and the JSON response that's returned to the browser.

But nothing concerning the zone. There must be something I'm missing.
There's no java exception and no JavaScript error.

Is there any simple tapestry example for refreshing the zone from java?

Regards,
Lidija


On Wed, Oct 30, 2013 at 2:57 PM, Dmitry Gusev <dm...@gmail.com>wrote:

> Looks ok to me at first glance.
>
> >     ajaxResponseRenderer.addRender("boxZone", boxZone);
> You don't have to specify clientId when you passing a zone here and this
> zone has id attribute declared in template.
>
> Try inspecting network activity in your browser's developer tools (firebug,
> etc.) to see how zone update works, i.e. what's returned to client when you
> call ajaxResponseRenderer.addRender(...);
>
> There is a bug in tapestry when you have to restart the app if you changed
> zone id in your template -- it won't be picked up without restart.
>
>
> On Wed, Oct 30, 2013 at 5:49 PM, lidijaldo . <li...@gmail.com> wrote:
>
> > I thought this should be simple but I can't seem to find the solution.
> >
> > I have a datatable displayed on my page. After I successfully edit some
> > row, I would like to refresh a zone on my page.
> >
> > This is the relevant part of my .tml file, let's say I'm trying to
> refresh
> > current time after I edited a row:
> >
> > <table t:type="jquery/datatable" t:id="najdiEdiDataTable"
> > t:source="datasource"
> >                        t:row="moduleItem" t:rowIndex="index"
> > t:model="sourcemodel"
> >                        t:rowsPerPage="10" t:options="dataTableOptions" />
> >
> > <t:zone t:id="boxZone" id="boxZone">
> >     ${getTime()}
> > </t:zone>
> >
> >
> >
> > My java code:
> > At the end of the edit method, before I return response to re-draw
> > datatable with the modified objects, I'm also trying to refresh the above
> > zone:
> >
> > @InjectComponent
> > @Property
> > private Zone boxZone;
> >
> > @OnEvent(component = DATATABLE_ID, value = EVENT_EDITOR_EDIT)
> >     public Object edit(@RequestParameter("action") String action) throws
> > Exception {
> >
> >         .... // edit and save object
> >
> >         // refresh module box
> >         logger.debug("request.isXHR() = " + request.isXHR());      //
> this
> > outputs "true"
> >     ajaxResponseRenderer.addRender("boxZone", boxZone);
> >
> >         return new TextStreamResponse("application/json",
> > response.toString());
> > }
> >
> > public String getTime() {
> >     return new java.util.Date().toString();
> > }
> >
> >
> > But it seems that ajaxResponseRenderer.addRender("boxZone", boxZone);
> > doesn't do anything. Am I missing something? Isn't it that simple?
> >
> > Regards,
> > Lidija
> >
>
>
>
> --
> Dmitry Gusev
>
> AnjLab Team
> http://anjlab.com
>

Re: Simply refresh a zone after datatable record edit - not so simple?

Posted by Dmitry Gusev <dm...@gmail.com>.
Looks ok to me at first glance.

>     ajaxResponseRenderer.addRender("boxZone", boxZone);
You don't have to specify clientId when you passing a zone here and this
zone has id attribute declared in template.

Try inspecting network activity in your browser's developer tools (firebug,
etc.) to see how zone update works, i.e. what's returned to client when you
call ajaxResponseRenderer.addRender(...);

There is a bug in tapestry when you have to restart the app if you changed
zone id in your template -- it won't be picked up without restart.


On Wed, Oct 30, 2013 at 5:49 PM, lidijaldo . <li...@gmail.com> wrote:

> I thought this should be simple but I can't seem to find the solution.
>
> I have a datatable displayed on my page. After I successfully edit some
> row, I would like to refresh a zone on my page.
>
> This is the relevant part of my .tml file, let's say I'm trying to refresh
> current time after I edited a row:
>
> <table t:type="jquery/datatable" t:id="najdiEdiDataTable"
> t:source="datasource"
>                        t:row="moduleItem" t:rowIndex="index"
> t:model="sourcemodel"
>                        t:rowsPerPage="10" t:options="dataTableOptions" />
>
> <t:zone t:id="boxZone" id="boxZone">
>     ${getTime()}
> </t:zone>
>
>
>
> My java code:
> At the end of the edit method, before I return response to re-draw
> datatable with the modified objects, I'm also trying to refresh the above
> zone:
>
> @InjectComponent
> @Property
> private Zone boxZone;
>
> @OnEvent(component = DATATABLE_ID, value = EVENT_EDITOR_EDIT)
>     public Object edit(@RequestParameter("action") String action) throws
> Exception {
>
>         .... // edit and save object
>
>         // refresh module box
>         logger.debug("request.isXHR() = " + request.isXHR());      // this
> outputs "true"
>     ajaxResponseRenderer.addRender("boxZone", boxZone);
>
>         return new TextStreamResponse("application/json",
> response.toString());
> }
>
> public String getTime() {
>     return new java.util.Date().toString();
> }
>
>
> But it seems that ajaxResponseRenderer.addRender("boxZone", boxZone);
> doesn't do anything. Am I missing something? Isn't it that simple?
>
> Regards,
> Lidija
>



-- 
Dmitry Gusev

AnjLab Team
http://anjlab.com