You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by cqasker <cq...@yahoo.com> on 2011/09/01 23:18:35 UTC

StreamResponse and inPlace Grid question

Basically I have a inPlace=true grid and some linksubmits to various
exporting options. When the submits are hit, some data from the grid is
exported. That works great. However once things are exported and downloaded,
the paging and other partial page submits on the page don't work for the
grid. From firebug, I see the ajax calls are being made and data is
received. However the grid is not updated.

I would do the download in a hidden iframe or window but I want to avoid
this and besides I need the state of the grid and the grid data. Is there a
way to either fix the grid so that the grid is updated? or another way?



--
View this message in context: http://tapestry.1045711.n5.nabble.com/StreamResponse-and-inPlace-Grid-question-tp4760076p4760076.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: StreamResponse and inPlace Grid question

Posted by cqasker <cq...@yahoo.com>.
Thanks Joost, interesting, I will try your workaround as well and take a look
at your proposed workaround. This should indeed save me a ton of time.

--
View this message in context: http://tapestry.1045711.n5.nabble.com/StreamResponse-and-inPlace-Grid-question-tp4760076p4771433.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: StreamResponse and inPlace Grid question

Posted by "Joost Schouten (ml)" <jo...@jsportal.com>.
  This sounds like a problem I had a while ago. Check out [1] and [2]

A stream response will casue the pages onUnload to be called cleaning up 
all the zone managers (I believe). A quick fix is to add a 
target="_blank" to your download link. But this will in most browsers 
cause an empty tab to be opened for your download. The best way is to 
download the stream to a hidden iframe which will keep you page working 
as it should and the download to nicely download on the same page.

Hope it helps,
Joost

[1] 
http://tapestry.1045711.n5.nabble.com/File-download-breaks-ajax-zone-manager-td4434859.html
[2] https://issues.apache.org/jira/browse/TAP5-1533

On 1/09/11 11:18 PM, cqasker wrote:
> Basically I have a inPlace=true grid and some linksubmits to various
> exporting options. When the submits are hit, some data from the grid is
> exported. That works great. However once things are exported and downloaded,
> the paging and other partial page submits on the page don't work for the
> grid. From firebug, I see the ajax calls are being made and data is
> received. However the grid is not updated.
>
> I would do the download in a hidden iframe or window but I want to avoid
> this and besides I need the state of the grid and the grid data. Is there a
> way to either fix the grid so that the grid is updated? or another way?
>
>
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/StreamResponse-and-inPlace-Grid-question-tp4760076p4760076.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: StreamResponse and inPlace Grid question

Posted by cqasker <cq...@yahoo.com>.
Thanks Taha -- I'll make a self running example to see if I can reproduce it.
Been a little busy lately but I should have it sometime this week.  Thanks
again for taking a look.

--
View this message in context: http://tapestry.1045711.n5.nabble.com/StreamResponse-and-inPlace-Grid-question-tp4760076p4771427.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: StreamResponse and inPlace Grid question

Posted by Taha Hafeez <ta...@gmail.com>.
Hi

The javascript id will change only if there is a zone surrounding the
grid. I can't see any in the code.  If there is not then can you share
an example for simulating the issue

On Fri, Sep 2, 2011 at 8:58 PM, cqasker <cq...@yahoo.com> wrote:
> Sure (and thanks as usual Taha!) so I have a wrapper around a grid and the
> csv export. I simplified the code quite a bit so hopefully its easy to
> understand.
>
> page tml:
>       <t:myGrid source="data" inPlace="true"/>
> in myGrid.tml
>   <t:form>
>      <t:grid t:id="grid"/>
>      <t:if test="${exportCsv}">
>         <t:csvExporter t:id="csvExporter"/>
>      </t:if>
>      <t:block id="empty">Move along, nothing to see.</t:block>
>  </t:form>
>
> in MyGrid.java
> @Component
> private CsvExporter csvExporter(parameters={"hasData=hasData"});
>
> @Component(publishParameters = "add, class, columnIndex,, encoder, empty,
> exclude, inPlace, include, lean, model, overrides, reorder, row, rowClass,
> rowIndex, sortModel, volatile",
>           parameters = {"pagerPosition=prop:pagerPosition",
> "rowsPerPage=rowsPerPage", "source=prop:source"})
> private Grid grid;
>
> @Property
> private GridDataSource source;
>
> public boolean isHasData()
> {return this.source.getAvailableRows() > 0;}
>
> //form submit event handler
> @OnEvent(value="submit")
> Object runExport() throws Exception
> {
>  //example of grid state I am using to generate the csv -- ie, csv is
> generated in order that user sortted the grid. if I do not do this, the csv
> source is in its unsorted original unsorted state
>  this.source.prepare(0, this.source.getAvailableRows(),
> this.grid.getSortModel().getSortConstraints());
>  ByteArrayOutputStream baos = getCsv(this.source,
> this.csvExporter.getMonthSel()); //gets csv data and filters only data for a
> month
>  return new ExportStreamResponse(baos); //just a simple implementation of
> StreamResponse
> }
>
> CsvExporter.tml
> <t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
>   <t:if test="${hasData}">
>      <div>
>         <ul>
>            <t:loop source="1..12" value="month">
>               <li>
>
>
>                        ${exportFormatMsg}
>
>
>               </li>
>            </t:loop>
>         </ul>
>      </div>
>   </t:if>
> </t:container>
>
> CsvExporter.java
>
> @Parameter(required = true)
> @Property
> private boolean hasData();
>
> @Property
> private int month;
>
> private int monthSel;
> public int getMonthSel()
> {return this.monthSel;}
>
> @SuppressWarnings("unused")
> @Component(parameters = {"event=clicky", "context=monthSel", "defer=false"})
> private LinkSubmit csvLink;
>
> @OnEvent(value = "clicky")
> void linkExport(int month)
> {
>  this.monthSel = month;
> }
>
>
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/StreamResponse-and-inPlace-Grid-question-tp4760076p4762779.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
>
>



-- 
Regards

Taha Hafeez Siddiqi (tawus)
http://tawus.wordpress.com

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


Re: StreamResponse and inPlace Grid question

Posted by cqasker <cq...@yahoo.com>.
Sure (and thanks as usual Taha!) so I have a wrapper around a grid and the
csv export. I simplified the code quite a bit so hopefully its easy to
understand.

page tml:
       <t:myGrid source="data" inPlace="true"/>
in myGrid.tml
   <t:form>
      <t:grid t:id="grid"/>
      <t:if test="${exportCsv}">
         <t:csvExporter t:id="csvExporter"/>
      </t:if>
      <t:block id="empty">Move along, nothing to see.</t:block>
  </t:form>              

in MyGrid.java
@Component
private CsvExporter csvExporter(parameters={"hasData=hasData"});

@Component(publishParameters = "add, class, columnIndex,, encoder, empty,
exclude, inPlace, include, lean, model, overrides, reorder, row, rowClass,
rowIndex, sortModel, volatile",
           parameters = {"pagerPosition=prop:pagerPosition",
"rowsPerPage=rowsPerPage", "source=prop:source"})
private Grid grid;

@Property
private GridDataSource source;

public boolean isHasData()
{return this.source.getAvailableRows() > 0;}

//form submit event handler   
@OnEvent(value="submit")
Object runExport() throws Exception
{
  //example of grid state I am using to generate the csv -- ie, csv is
generated in order that user sortted the grid. if I do not do this, the csv
source is in its unsorted original unsorted state
  this.source.prepare(0, this.source.getAvailableRows(),
this.grid.getSortModel().getSortConstraints());
  ByteArrayOutputStream baos = getCsv(this.source,
this.csvExporter.getMonthSel()); //gets csv data and filters only data for a
month
  return new ExportStreamResponse(baos); //just a simple implementation of
StreamResponse
}     

CsvExporter.tml
<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
   <t:if test="${hasData}">
      <div>
         <ul>
            <t:loop source="1..12" value="month">
               <li>
                  
                      
                        ${exportFormatMsg}
                      
                                   
               </li>
            </t:loop>
         </ul>
      </div>
   </t:if>  
</t:container>

CsvExporter.java

@Parameter(required = true)
@Property
private boolean hasData();

@Property
private int month;

private int monthSel;
public int getMonthSel()
{return this.monthSel;}

@SuppressWarnings("unused")
@Component(parameters = {"event=clicky", "context=monthSel", "defer=false"})
private LinkSubmit csvLink;

@OnEvent(value = "clicky")
void linkExport(int month)
{
  this.monthSel = month;
}



--
View this message in context: http://tapestry.1045711.n5.nabble.com/StreamResponse-and-inPlace-Grid-question-tp4760076p4762779.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: StreamResponse and inPlace Grid question

Posted by Taha Hafeez <ta...@gmail.com>.
Hi

My guess is that you are updating some zone around the grid which
causes the javascript id of grid's own zone to change after the first
call and so ajax fails after that. If you share some code, may be we
can suggest a solution.


On Fri, Sep 2, 2011 at 2:48 AM, cqasker <cq...@yahoo.com> wrote:
> Basically I have a inPlace=true grid and some linksubmits to various
> exporting options. When the submits are hit, some data from the grid is
> exported. That works great. However once things are exported and downloaded,
> the paging and other partial page submits on the page don't work for the
> grid. From firebug, I see the ajax calls are being made and data is
> received. However the grid is not updated.
>
> I would do the download in a hidden iframe or window but I want to avoid
> this and besides I need the state of the grid and the grid data. Is there a
> way to either fix the grid so that the grid is updated? or another way?
>
>
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/StreamResponse-and-inPlace-Grid-question-tp4760076p4760076.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
>
>



-- 
Regards

Taha Hafeez Siddiqi (tawus)
http://tawus.wordpress.com

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


Re: StreamResponse and inPlace Grid question

Posted by cqasker <cq...@yahoo.com>.
Hey guys, just wanted to finally follow up. Time has been scarce lately so I
didn't get a chance to post my findings. Again thanks to Taha and especially
Joost for helping with this issue -- you guys made me look in the right
places especially that JIRA issue. 

So basically I do have the same problem as described in
https://issues.apache.org/jira/browse/TAP5-1533.
The problem is that after streamed response downloads ajax requests were
being stopped because  of the window unload event. The patch is correct but
unfortunately I can't/didn't figure out how to use my own version of
Tapestry.js

So I think I found a relatively elegant solution to use until the patch/fix
comes out. Mixins to the rescue!
So for each link that causes a streamed response to be returned add the
following mixin which will upon the click event set Tapestry.windowUnloaded
property to false. And voila, all the ajax will still work on the page.  The
key to this is that the unload event is handled before the click event
giving the mixin the chance to properly reset the state.  StreamedResponses
are sort of the exception to the rule that a new non ajax response doesn't
always mean a new page/window. This way I don't have to deal with
downloading through an iframe or new window.

<t:linksubmit t:id="download"
t:mixins="streamedResponsePatch">Download</t:linksubmit>

@Import(library="StreamedResponsePatch.js")
public class StreamedResponsePatch
{

   @Inject
   private JavaScriptSupport javaScriptSupport;

   @InjectContainer
   private ClientElement clientElement;

   @AfterRender
   public void after()
   {
      JSONObject j = new JSONObject();
      j.put("elementId", this.clientElement.getClientId());
      this.javaScriptSupport.addInitializerCall("StreamedResponsePatch", j);
   }

}


//
StreamedResponsePatch=Class.create(
{
  initialize: function(spec)
  {
      this.elementId = spec.elementId;
      Event.observe($(this.elementId), 'click',
this.update.bindAsEventListener(this));
  },

  update: function(e)
  {Tapestry.windowUnloaded = false;},

});

Tapestry.Initializer.StreamedResponsePatch = function(spec)
{new StreamedResponsePatch(spec);}

 

--
View this message in context: http://tapestry.1045711.n5.nabble.com/StreamResponse-and-inPlace-Grid-question-tp4760076p4837399.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