You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by UPBrandon <bc...@up.com> on 2008/02/13 17:18:47 UTC

Opening DynamicWebResource from Button/AjaxButton?

In a project I am working on, I wrote a DynamicWebResource that generates a
PDF file and, by setting the Content-Disposition in the header, got it so
that the user is prompted to download the PDF when they click on a
ResourceLink to my PDF-generating resource.

That all works fine but now I need to open the PDF from a button.  I want to
allow the user to select a value in a form and press a button to view
somewhat of a report for the item they selected.  However, there doesn't
appear to be any type of button that would lead a user to my
DynamicWebResource.  Is there any way to have a button do a submit (update
the model) and then lead the user to a resource?

-Brandon
-- 
View this message in context: http://www.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton--tp15459841p15459841.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: I also have the question

Posted by UPBrandon <bc...@up.com>.
>From what I've read, the difference between the two browsers is that IE uses
the file name's extension to determine what type of file it is and other
browsers like FireFox use the MIME type provided by the remote server (your
application in this case.)

So, IE is seeing ".csv" and assuming it's a CSV file.  FireFox on the other
hand is looking at the "text/plain" MIME type you provided and assuming it's
a plain text file.  You are using the wrong mime type.


wch2001 wrote:
> 
> thanks, UPBrandon
> 
> I tried your code, for csv, 
> 
> public class CsvRequestTarget extends ByteDataRequestTarget {
>     
>         public CsvRequestTarget(byte[] data, String fileName) {
>                 super("text/plain", data, fileName+".csv");
>         }
>         
> } 
> but it can not work with IE and ff.
> 
> Could you tell me your code about csv ?
> 
> thanks a lot
> 
> UPBrandon wrote:
>> 
>> For a while, we were using a solution that allowed us to download
>> generated PDF's but it only seemed to work in IE and some people had
>> trouble using it from "outside connections."
>> 
>> What I wanted was a way to access dynamic/generated content that:
>> - Doesn't cause Wicket to be come non-responsive after the request
>> - Works in at least IE and FF
>> - Allows a file name to be provided
>> - Allows a mime type to be provided
>> 
>> After taking another stab at it, I was able to get that working.  Here is
>> what I ended up with:
>> 
>> public class ByteDataRequestTarget extends ByteArrayResource implements
>> IRequestTarget {
>> 	private String fileName;
>> 
>> 	public ByteDataRequestTarget(String mimeType, byte[] data, String
>> fileName) {
>> 		super(mimeType, data, fileName);
>> 		this.fileName = fileName;
>> 	}
>> 
>> 	public void detach(RequestCycle requestCycle) { }
>> 
>> 	public void respond(RequestCycle requestCycle) {
>> 		requestCycle.setRequestTarget(new
>> ResourceStreamRequestTarget(this.getResourceStream() ) {
>> 			public String getFileName() {
>> 				return fileName;
>> 			}
>> 		} );
>> 	}
>> }
>> 
>> And then I subclassed for different common file types like PDF and CSV. 
>> Those subclasses basically just provide the MIME type for the user and
>> automatically add the file extension.
>> 
>> public class PdfRequestTarget extends ByteDataRequestTarget {
>> 	public PdfRequestTarget(byte[] data, String fileName) {
>> 		super(Constants.PDF_MIME_TYPE, data, fileName+".pdf");
>> 	}
>> }
>> 
>> To use the class, you do something like this:
>> 
>> new Button(buttonId, new Model("My Button") ) {
>> 	public void onSubmit() {
>> 		getRequestCycle().setRequestTarget(new
>> PdfRequestTarget(getSomePdfData(), "FileName") );
>> 	}
>> };
>> 
>> I hope that helps.
> 
> 

-- 
View this message in context: http://www.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton--tp15459841p21550916.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: I also have the question

Posted by wch2001 <wc...@hotmail.com>.
thanks, UPBrandon

I tried your code, for csv, 

public class CsvRequestTarget extends ByteDataRequestTarget {
    
        public CsvRequestTarget(byte[] data, String fileName) {
                super("text/plain", data, fileName+".csv");
        }
        
} 
but it can not work with IE and ff.

Could you tell me your code about csv ?

thanks a lot

UPBrandon wrote:
> 
> For a while, we were using a solution that allowed us to download
> generated PDF's but it only seemed to work in IE and some people had
> trouble using it from "outside connections."
> 
> What I wanted was a way to access dynamic/generated content that:
> - Doesn't cause Wicket to be come non-responsive after the request
> - Works in at least IE and FF
> - Allows a file name to be provided
> - Allows a mime type to be provided
> 
> After taking another stab at it, I was able to get that working.  Here is
> what I ended up with:
> 
> public class ByteDataRequestTarget extends ByteArrayResource implements
> IRequestTarget {
> 	private String fileName;
> 
> 	public ByteDataRequestTarget(String mimeType, byte[] data, String
> fileName) {
> 		super(mimeType, data, fileName);
> 		this.fileName = fileName;
> 	}
> 
> 	public void detach(RequestCycle requestCycle) { }
> 
> 	public void respond(RequestCycle requestCycle) {
> 		requestCycle.setRequestTarget(new
> ResourceStreamRequestTarget(this.getResourceStream() ) {
> 			public String getFileName() {
> 				return fileName;
> 			}
> 		} );
> 	}
> }
> 
> And then I subclassed for different common file types like PDF and CSV. 
> Those subclasses basically just provide the MIME type for the user and
> automatically add the file extension.
> 
> public class PdfRequestTarget extends ByteDataRequestTarget {
> 	public PdfRequestTarget(byte[] data, String fileName) {
> 		super(Constants.PDF_MIME_TYPE, data, fileName+".pdf");
> 	}
> }
> 
> To use the class, you do something like this:
> 
> new Button(buttonId, new Model("My Button") ) {
> 	public void onSubmit() {
> 		getRequestCycle().setRequestTarget(new
> PdfRequestTarget(getSomePdfData(), "FileName") );
> 	}
> };
> 
> I hope that helps.
> 
> 
> wch2001 wrote:
>> 
>> UPBrandon,
>> Did u find any solution for it?
>> 
>> anyone can help?
>> 
>> thanks
>> 
>> 
>> UPBrandon wrote:
>>> 
>>> It's not that I necessary want to see the page refreshed with updated
>>> form values.  In fact, I would prefer that the user not leave the page
>>> at all.  All the form contains is a checkgroup of "things" to include in
>>> the PDF.  All I want to do when the button is pressed is view/download
>>> the PDF but the form with the checkgroup needs to be submitted first so
>>> I can see what was checked when I generate the PDF.
>>> 
>>> I suppose taking the ResourceReference's and using it in the onload
>>> would work but it seems like such a hack, not to mention that it might
>>> cause problems if the user uses the back button.  While working on my
>>> DynamicWebResource, I was able to download a PDF and continue using my
>>> application using a link (assigned to either a link or button in HTML.) 
>>> The only problem is that it doesn't do a submit.  Accessing the
>>> DynamicWebResource from a button works but makes my app non-responsive. 
>>> What I would like to do is either make the ResourceLink somehow submit
>>> my form or, even better, make a button component that handles the
>>> request in a way that doens't break Wicket.  Ideas/suggestions?
>>> 
>>> -Brandon
>>> 
>>> 
>>> igor.vaynberg wrote:
>>>> 
>>>> so you want to see the page with updated form values _and_ stream the
>>>> pdf?
>>>> 
>>>> why dont you take that url you generated for your resourceref and
>>>> append it to a window.onload javascript that does window.location=url;
>>>> 
>>>> -gior
>>>> 
>>>>>
>>>>>  As I mentioned in my previous response, I couldn't use
>>>>>  getRequestCycle().setRequestTarget() directly because of the way the
>>>>> API
>>>>>  works (you can use a ResourceReference but not a Resource.)  Instead,
>>>>> I
>>>>>  ended up with something like this:
>>>>>
>>>>>  new AjaxButton(buttonId, form) {
>>>>>         protected void onSubmit(AjaxRequestTarget target, Form form) {
>>>>>                 ResourceReference pdfReference = new
>>>>> ResourceReference("") {
>>>>>                         protected Resource newResource() {
>>>>>                                 return new BillPdfWebResource(...);
>>>>>                         }
>>>>>                 };
>>>>>                 String url =
>>>>> getRequestCycle().get().urlFor(pdfReference).toString();
>>>>>                 getRequestCycle().setRequestTarget(new
>>>>> RedirectRequestTarget(url) );
>>>>>         }
>>>>>  }
>>>>>
>>>>>  It works... but only once.  When I click on the button, everything
>>>>> works, my
>>>>>  PDF gets generated and downloaded but then my app becomes
>>>>> unresponsive.  I
>>>>>  can't interact with the site at all until I "start over."  Is there a
>>>>> better
>>>>>  way to go about this that wouldn't cause that side effect?  Whatever
>>>>>  approach I take, I need to be able to submit a form when the PDF is
>>>>>  generated.  My example doesn't show it but my BillPdfWebResource
>>>>> class
>>>>>  generates a PDF based on the user's selection and my Form's Model
>>>>> needs to
>>>>>  be updated.  Any suggestions?
>>>>>
>>>>>  -Brandon
>>>>>
>>>>>  igor.vaynberg wrote:
>>>>>  >
>>>>>  > onsubmit() {
>>>>>  >   getrequestcycle().setrequesttarget(new
>>>>>  > redirectrequesttarget(urlfor(resourceref)));
>>>>>  > }
>>>>>  >
>>>>>  > -igor
>>>>>  >
>>>>>  > On Feb 13, 2008 8:18 AM, UPBrandon <bc...@up.com> wrote:
>>>>>  >>
>>>>>  >> In a project I am working on, I wrote a DynamicWebResource that
>>>>> generates
>>>>>  >> a
>>>>>  >> PDF file and, by setting the Content-Disposition in the header,
>>>>> got it so
>>>>>  >> that the user is prompted to download the PDF when they click on a
>>>>>  >> ResourceLink to my PDF-generating resource.
>>>>>  >>
>>>>>  >> That all works fine but now I need to open the PDF from a button. 
>>>>> I want
>>>>>  >> to
>>>>>  >> allow the user to select a value in a form and press a button to
>>>>> view
>>>>>  >> somewhat of a report for the item they selected.  However, there
>>>>> doesn't
>>>>>  >> appear to be any type of button that would lead a user to my
>>>>>  >> DynamicWebResource.  Is there any way to have a button do a submit
>>>>>  >> (update
>>>>>  >> the model) and then lead the user to a resource?
>>>>>  >>
>>>>>  >> -Brandon
>>>> 
>>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton--tp15459841p21474898.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: I also have the question

Posted by UPBrandon <bc...@up.com>.
For a while, we were using a solution that allowed us to download generated
PDF's but it only seemed to work in IE and some people had trouble using it
from "outside connections."

What I wanted was a way to access dynamic/generated content that:
- Doesn't cause Wicket to be come non-responsive after the request
- Works in at least IE and FF
- Allows a file name to be provided
- Allows a mime type to be provided

After taking another stab at it, I was able to get that working.  Here is
what I ended up with:

public class ByteDataRequestTarget extends ByteArrayResource implements
IRequestTarget {
	private String fileName;

	public ByteDataRequestTarget(String mimeType, byte[] data, String fileName)
{
		super(mimeType, data, fileName);
		this.fileName = fileName;
	}

	public void detach(RequestCycle requestCycle) { }

	public void respond(RequestCycle requestCycle) {
		requestCycle.setRequestTarget(new
ResourceStreamRequestTarget(this.getResourceStream() ) {
			public String getFileName() {
				return fileName;
			}
		} );
	}
}

And then I subclassed for different common file types like PDF and CSV. 
Those subclasses basically just provide the MIME type for the user and
automatically add the file extension.

public class PdfRequestTarget extends ByteDataRequestTarget {
	public PdfRequestTarget(byte[] data, String fileName) {
		super(Constants.PDF_MIME_TYPE, data, fileName+".pdf");
	}
}

To use the class, you do something like this:

new Button(buttonId, new Model("My Button") ) {
	public void onSubmit() {
		getRequestCycle().setRequestTarget(new PdfRequestTarget(getSomePdfData(),
"FileName") );
	}
};

I hope that helps.


wch2001 wrote:
> 
> UPBrandon,
> Did u find any solution for it?
> 
> anyone can help?
> 
> thanks
> 
> 
> UPBrandon wrote:
>> 
>> It's not that I necessary want to see the page refreshed with updated
>> form values.  In fact, I would prefer that the user not leave the page at
>> all.  All the form contains is a checkgroup of "things" to include in the
>> PDF.  All I want to do when the button is pressed is view/download the
>> PDF but the form with the checkgroup needs to be submitted first so I can
>> see what was checked when I generate the PDF.
>> 
>> I suppose taking the ResourceReference's and using it in the onload would
>> work but it seems like such a hack, not to mention that it might cause
>> problems if the user uses the back button.  While working on my
>> DynamicWebResource, I was able to download a PDF and continue using my
>> application using a link (assigned to either a link or button in HTML.) 
>> The only problem is that it doesn't do a submit.  Accessing the
>> DynamicWebResource from a button works but makes my app non-responsive. 
>> What I would like to do is either make the ResourceLink somehow submit my
>> form or, even better, make a button component that handles the request in
>> a way that doens't break Wicket.  Ideas/suggestions?
>> 
>> -Brandon
>> 
>> 
>> igor.vaynberg wrote:
>>> 
>>> so you want to see the page with updated form values _and_ stream the
>>> pdf?
>>> 
>>> why dont you take that url you generated for your resourceref and
>>> append it to a window.onload javascript that does window.location=url;
>>> 
>>> -gior
>>> 
>>>>
>>>>  As I mentioned in my previous response, I couldn't use
>>>>  getRequestCycle().setRequestTarget() directly because of the way the
>>>> API
>>>>  works (you can use a ResourceReference but not a Resource.)  Instead,
>>>> I
>>>>  ended up with something like this:
>>>>
>>>>  new AjaxButton(buttonId, form) {
>>>>         protected void onSubmit(AjaxRequestTarget target, Form form) {
>>>>                 ResourceReference pdfReference = new
>>>> ResourceReference("") {
>>>>                         protected Resource newResource() {
>>>>                                 return new BillPdfWebResource(...);
>>>>                         }
>>>>                 };
>>>>                 String url =
>>>> getRequestCycle().get().urlFor(pdfReference).toString();
>>>>                 getRequestCycle().setRequestTarget(new
>>>> RedirectRequestTarget(url) );
>>>>         }
>>>>  }
>>>>
>>>>  It works... but only once.  When I click on the button, everything
>>>> works, my
>>>>  PDF gets generated and downloaded but then my app becomes
>>>> unresponsive.  I
>>>>  can't interact with the site at all until I "start over."  Is there a
>>>> better
>>>>  way to go about this that wouldn't cause that side effect?  Whatever
>>>>  approach I take, I need to be able to submit a form when the PDF is
>>>>  generated.  My example doesn't show it but my BillPdfWebResource class
>>>>  generates a PDF based on the user's selection and my Form's Model
>>>> needs to
>>>>  be updated.  Any suggestions?
>>>>
>>>>  -Brandon
>>>>
>>>>  igor.vaynberg wrote:
>>>>  >
>>>>  > onsubmit() {
>>>>  >   getrequestcycle().setrequesttarget(new
>>>>  > redirectrequesttarget(urlfor(resourceref)));
>>>>  > }
>>>>  >
>>>>  > -igor
>>>>  >
>>>>  > On Feb 13, 2008 8:18 AM, UPBrandon <bc...@up.com> wrote:
>>>>  >>
>>>>  >> In a project I am working on, I wrote a DynamicWebResource that
>>>> generates
>>>>  >> a
>>>>  >> PDF file and, by setting the Content-Disposition in the header, got
>>>> it so
>>>>  >> that the user is prompted to download the PDF when they click on a
>>>>  >> ResourceLink to my PDF-generating resource.
>>>>  >>
>>>>  >> That all works fine but now I need to open the PDF from a button. 
>>>> I want
>>>>  >> to
>>>>  >> allow the user to select a value in a form and press a button to
>>>> view
>>>>  >> somewhat of a report for the item they selected.  However, there
>>>> doesn't
>>>>  >> appear to be any type of button that would lead a user to my
>>>>  >> DynamicWebResource.  Is there any way to have a button do a submit
>>>>  >> (update
>>>>  >> the model) and then lead the user to a resource?
>>>>  >>
>>>>  >> -Brandon
>>> 
>> 
> 

-- 
View this message in context: http://www.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton--tp15459841p21462901.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


I also have the question

Posted by wch2001 <wc...@hotmail.com>.
UPBrandon,
Did u find any solution for it?

anyone can help?

thanks


UPBrandon wrote:
> 
> It's not that I necessary want to see the page refreshed with updated form
> values.  In fact, I would prefer that the user not leave the page at all. 
> All the form contains is a checkgroup of "things" to include in the PDF. 
> All I want to do when the button is pressed is view/download the PDF but
> the form with the checkgroup needs to be submitted first so I can see what
> was checked when I generate the PDF.
> 
> I suppose taking the ResourceReference's and using it in the onload would
> work but it seems like such a hack, not to mention that it might cause
> problems if the user uses the back button.  While working on my
> DynamicWebResource, I was able to download a PDF and continue using my
> application using a link (assigned to either a link or button in HTML.) 
> The only problem is that it doesn't do a submit.  Accessing the
> DynamicWebResource from a button works but makes my app non-responsive. 
> What I would like to do is either make the ResourceLink somehow submit my
> form or, even better, make a button component that handles the request in
> a way that doens't break Wicket.  Ideas/suggestions?
> 
> -Brandon
> 
> 
> igor.vaynberg wrote:
>> 
>> so you want to see the page with updated form values _and_ stream the
>> pdf?
>> 
>> 
>> why dont you take that url you generated for your resourceref and
>> append it to a window.onload javascript that does window.location=url;
>> 
>> -gior
>> 
>> 
>> On Wed, Feb 20, 2008 at 2:33 PM, UPBrandon <bc...@up.com> wrote:
>>>
>>>  As I mentioned in my previous response, I couldn't use
>>>  getRequestCycle().setRequestTarget() directly because of the way the
>>> API
>>>  works (you can use a ResourceReference but not a Resource.)  Instead, I
>>>  ended up with something like this:
>>>
>>>  new AjaxButton(buttonId, form) {
>>>         protected void onSubmit(AjaxRequestTarget target, Form form) {
>>>                 ResourceReference pdfReference = new
>>> ResourceReference("") {
>>>                         protected Resource newResource() {
>>>                                 return new BillPdfWebResource(...);
>>>                         }
>>>                 };
>>>                 String url =
>>> getRequestCycle().get().urlFor(pdfReference).toString();
>>>                 getRequestCycle().setRequestTarget(new
>>> RedirectRequestTarget(url) );
>>>         }
>>>  }
>>>
>>>  It works... but only once.  When I click on the button, everything
>>> works, my
>>>  PDF gets generated and downloaded but then my app becomes unresponsive. 
>>> I
>>>  can't interact with the site at all until I "start over."  Is there a
>>> better
>>>  way to go about this that wouldn't cause that side effect?  Whatever
>>>  approach I take, I need to be able to submit a form when the PDF is
>>>  generated.  My example doesn't show it but my BillPdfWebResource class
>>>  generates a PDF based on the user's selection and my Form's Model needs
>>> to
>>>  be updated.  Any suggestions?
>>>
>>>  -Brandon
>>>
>>>
>>>
>>>
>>>  igor.vaynberg wrote:
>>>  >
>>>  > onsubmit() {
>>>  >   getrequestcycle().setrequesttarget(new
>>>  > redirectrequesttarget(urlfor(resourceref)));
>>>  > }
>>>  >
>>>  > -igor
>>>  >
>>>  >
>>>  > On Feb 13, 2008 8:18 AM, UPBrandon <bc...@up.com> wrote:
>>>  >>
>>>  >> In a project I am working on, I wrote a DynamicWebResource that
>>> generates
>>>  >> a
>>>  >> PDF file and, by setting the Content-Disposition in the header, got
>>> it so
>>>  >> that the user is prompted to download the PDF when they click on a
>>>  >> ResourceLink to my PDF-generating resource.
>>>  >>
>>>  >> That all works fine but now I need to open the PDF from a button.  I
>>> want
>>>  >> to
>>>  >> allow the user to select a value in a form and press a button to
>>> view
>>>  >> somewhat of a report for the item they selected.  However, there
>>> doesn't
>>>  >> appear to be any type of button that would lead a user to my
>>>  >> DynamicWebResource.  Is there any way to have a button do a submit
>>>  >> (update
>>>  >> the model) and then lead the user to a resource?
>>>  >>
>>>  >> -Brandon
>>>  >> --
>>>  >> View this message in context:
>>>  >>
>>> http://www.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton--tp15459841p15459841.html
>>>  >> Sent from the Wicket - User mailing list archive at Nabble.com.
>> 
>>>  >>
>>>  >>
>>>  >>
>>> ---------------------------------------------------------------------
>>>  >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>  >> For additional commands, e-mail: users-help@wicket.apache.org
>>>  >>
>>>  >>
>>>  >
>>>  > ---------------------------------------------------------------------
>>>  > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>  > For additional commands, e-mail: users-help@wicket.apache.org
>>>  >
>>>  >
>>>  >
>>>
>>>  --
>>>  View this message in context:
>>> http://www.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton--tp15459841p15600541.html
>>>
>>>
>>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>>
>>>
>>>  ---------------------------------------------------------------------
>>>  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>  For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton--tp15459841p21449042.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Opening DynamicWebResource from Button/AjaxButton?

Posted by UPBrandon <bc...@up.com>.
It's not that I necessary want to see the page refreshed with updated form
values.  In fact, I would prefer that the user not leave the page at all. 
All the form contains is a checkgroup of "things" to include in the PDF. 
All I want to do when the button is pressed is view/download the PDF but the
form with the checkgroup needs to be submitted first so I can see what was
checked when I generate the PDF.

I suppose taking the ResourceReference's and using it in the onload would
work but it seems like such a hack, not to mention that it might cause
problems if the user uses the back button.  While working on my
DynamicWebResource, I was able to download a PDF and continue using my
application using a link (assigned to either a link or button in HTML.)  The
only problem is that it doesn't do a submit.  Accessing the
DynamicWebResource from a button works but makes my app non-responsive. 
What I would like to do is either make the ResourceLink somehow submit my
form or, even better, make a button component that handles the request in a
way that doens't break Wicket.  Ideas/suggestions?

-Brandon


igor.vaynberg wrote:
> 
> so you want to see the page with updated form values _and_ stream the pdf?
> 
> 
> why dont you take that url you generated for your resourceref and
> append it to a window.onload javascript that does window.location=url;
> 
> -gior
> 
> 
> On Wed, Feb 20, 2008 at 2:33 PM, UPBrandon <bc...@up.com> wrote:
>>
>>  As I mentioned in my previous response, I couldn't use
>>  getRequestCycle().setRequestTarget() directly because of the way the API
>>  works (you can use a ResourceReference but not a Resource.)  Instead, I
>>  ended up with something like this:
>>
>>  new AjaxButton(buttonId, form) {
>>         protected void onSubmit(AjaxRequestTarget target, Form form) {
>>                 ResourceReference pdfReference = new
>> ResourceReference("") {
>>                         protected Resource newResource() {
>>                                 return new BillPdfWebResource(...);
>>                         }
>>                 };
>>                 String url =
>> getRequestCycle().get().urlFor(pdfReference).toString();
>>                 getRequestCycle().setRequestTarget(new
>> RedirectRequestTarget(url) );
>>         }
>>  }
>>
>>  It works... but only once.  When I click on the button, everything
>> works, my
>>  PDF gets generated and downloaded but then my app becomes unresponsive. 
>> I
>>  can't interact with the site at all until I "start over."  Is there a
>> better
>>  way to go about this that wouldn't cause that side effect?  Whatever
>>  approach I take, I need to be able to submit a form when the PDF is
>>  generated.  My example doesn't show it but my BillPdfWebResource class
>>  generates a PDF based on the user's selection and my Form's Model needs
>> to
>>  be updated.  Any suggestions?
>>
>>  -Brandon
>>
>>
>>
>>
>>  igor.vaynberg wrote:
>>  >
>>  > onsubmit() {
>>  >   getrequestcycle().setrequesttarget(new
>>  > redirectrequesttarget(urlfor(resourceref)));
>>  > }
>>  >
>>  > -igor
>>  >
>>  >
>>  > On Feb 13, 2008 8:18 AM, UPBrandon <bc...@up.com> wrote:
>>  >>
>>  >> In a project I am working on, I wrote a DynamicWebResource that
>> generates
>>  >> a
>>  >> PDF file and, by setting the Content-Disposition in the header, got
>> it so
>>  >> that the user is prompted to download the PDF when they click on a
>>  >> ResourceLink to my PDF-generating resource.
>>  >>
>>  >> That all works fine but now I need to open the PDF from a button.  I
>> want
>>  >> to
>>  >> allow the user to select a value in a form and press a button to view
>>  >> somewhat of a report for the item they selected.  However, there
>> doesn't
>>  >> appear to be any type of button that would lead a user to my
>>  >> DynamicWebResource.  Is there any way to have a button do a submit
>>  >> (update
>>  >> the model) and then lead the user to a resource?
>>  >>
>>  >> -Brandon
>>  >> --
>>  >> View this message in context:
>>  >>
>> http://www.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton--tp15459841p15459841.html
>>  >> Sent from the Wicket - User mailing list archive at Nabble.com.
>>  >>
>>  >>
>>  >> ---------------------------------------------------------------------
>>  >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>  >> For additional commands, e-mail: users-help@wicket.apache.org
>>  >>
>>  >>
>>  >
>>  > ---------------------------------------------------------------------
>>  > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>  > For additional commands, e-mail: users-help@wicket.apache.org
>>  >
>>  >
>>  >
>>
>>  --
>>  View this message in context:
>> http://www.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton--tp15459841p15600541.html
>>
>>
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>>  ---------------------------------------------------------------------
>>  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>  For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton--tp15459841p15613180.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: I also have the question

Posted by eugenebalt <eu...@yahoo.com>.
UPBrandon, I tried your code, and it doesn't repaint the form. Isn't that
something you wanted to do? When I tried it, it gave me the file stream, but
the form was NOT updated...
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton-tp1877751p3082294.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Opening DynamicWebResource from Button/AjaxButton?

Posted by Igor Vaynberg <ig...@gmail.com>.
so you want to see the page with updated form values _and_ stream the pdf?


why dont you take that url you generated for your resourceref and
append it to a window.onload javascript that does window.location=url;

-gior


On Wed, Feb 20, 2008 at 2:33 PM, UPBrandon <bc...@up.com> wrote:
>
>  As I mentioned in my previous response, I couldn't use
>  getRequestCycle().setRequestTarget() directly because of the way the API
>  works (you can use a ResourceReference but not a Resource.)  Instead, I
>  ended up with something like this:
>
>  new AjaxButton(buttonId, form) {
>         protected void onSubmit(AjaxRequestTarget target, Form form) {
>                 ResourceReference pdfReference = new ResourceReference("") {
>                         protected Resource newResource() {
>                                 return new BillPdfWebResource(...);
>                         }
>                 };
>                 String url = getRequestCycle().get().urlFor(pdfReference).toString();
>                 getRequestCycle().setRequestTarget(new RedirectRequestTarget(url) );
>         }
>  }
>
>  It works... but only once.  When I click on the button, everything works, my
>  PDF gets generated and downloaded but then my app becomes unresponsive.  I
>  can't interact with the site at all until I "start over."  Is there a better
>  way to go about this that wouldn't cause that side effect?  Whatever
>  approach I take, I need to be able to submit a form when the PDF is
>  generated.  My example doesn't show it but my BillPdfWebResource class
>  generates a PDF based on the user's selection and my Form's Model needs to
>  be updated.  Any suggestions?
>
>  -Brandon
>
>
>
>
>  igor.vaynberg wrote:
>  >
>  > onsubmit() {
>  >   getrequestcycle().setrequesttarget(new
>  > redirectrequesttarget(urlfor(resourceref)));
>  > }
>  >
>  > -igor
>  >
>  >
>  > On Feb 13, 2008 8:18 AM, UPBrandon <bc...@up.com> wrote:
>  >>
>  >> In a project I am working on, I wrote a DynamicWebResource that generates
>  >> a
>  >> PDF file and, by setting the Content-Disposition in the header, got it so
>  >> that the user is prompted to download the PDF when they click on a
>  >> ResourceLink to my PDF-generating resource.
>  >>
>  >> That all works fine but now I need to open the PDF from a button.  I want
>  >> to
>  >> allow the user to select a value in a form and press a button to view
>  >> somewhat of a report for the item they selected.  However, there doesn't
>  >> appear to be any type of button that would lead a user to my
>  >> DynamicWebResource.  Is there any way to have a button do a submit
>  >> (update
>  >> the model) and then lead the user to a resource?
>  >>
>  >> -Brandon
>  >> --
>  >> View this message in context:
>  >> http://www.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton--tp15459841p15459841.html
>  >> Sent from the Wicket - User mailing list archive at Nabble.com.
>  >>
>  >>
>  >> ---------------------------------------------------------------------
>  >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>  >> For additional commands, e-mail: users-help@wicket.apache.org
>  >>
>  >>
>  >
>  > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>  > For additional commands, e-mail: users-help@wicket.apache.org
>  >
>  >
>  >
>
>  --
>  View this message in context: http://www.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton--tp15459841p15600541.html
>
>
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>  For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: Opening DynamicWebResource from Button/AjaxButton?

Posted by UPBrandon <bc...@up.com>.
As I mentioned in my previous response, I couldn't use
getRequestCycle().setRequestTarget() directly because of the way the API
works (you can use a ResourceReference but not a Resource.)  Instead, I
ended up with something like this:

new AjaxButton(buttonId, form) {
	protected void onSubmit(AjaxRequestTarget target, Form form) {
		ResourceReference pdfReference = new ResourceReference("") {
			protected Resource newResource() {
				return new BillPdfWebResource(...);
			}
		};
		String url = getRequestCycle().get().urlFor(pdfReference).toString();
		getRequestCycle().setRequestTarget(new RedirectRequestTarget(url) );
	}
}

It works... but only once.  When I click on the button, everything works, my
PDF gets generated and downloaded but then my app becomes unresponsive.  I
can't interact with the site at all until I "start over."  Is there a better
way to go about this that wouldn't cause that side effect?  Whatever
approach I take, I need to be able to submit a form when the PDF is
generated.  My example doesn't show it but my BillPdfWebResource class
generates a PDF based on the user's selection and my Form's Model needs to
be updated.  Any suggestions?

-Brandon


igor.vaynberg wrote:
> 
> onsubmit() {
>   getrequestcycle().setrequesttarget(new
> redirectrequesttarget(urlfor(resourceref)));
> }
> 
> -igor
> 
> 
> On Feb 13, 2008 8:18 AM, UPBrandon <bc...@up.com> wrote:
>>
>> In a project I am working on, I wrote a DynamicWebResource that generates
>> a
>> PDF file and, by setting the Content-Disposition in the header, got it so
>> that the user is prompted to download the PDF when they click on a
>> ResourceLink to my PDF-generating resource.
>>
>> That all works fine but now I need to open the PDF from a button.  I want
>> to
>> allow the user to select a value in a form and press a button to view
>> somewhat of a report for the item they selected.  However, there doesn't
>> appear to be any type of button that would lead a user to my
>> DynamicWebResource.  Is there any way to have a button do a submit
>> (update
>> the model) and then lead the user to a resource?
>>
>> -Brandon
>> --
>> View this message in context:
>> http://www.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton--tp15459841p15459841.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton--tp15459841p15600541.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Opening DynamicWebResource from Button/AjaxButton?

Posted by UPBrandon <bc...@up.com>.
The urlFor() method can take a few different types but not a
Resource/WebResource/DynamicWebResource.  It can take a ResourceReference
but would mean that I would have to register an object of my
DynamicWebResource class as a shared resource before I could get a reference
to it, wouldn't it?  It would be nice if there was a more "direct" approach.

-Brandon


igor.vaynberg wrote:
> 
> onsubmit() {
>   getrequestcycle().setrequesttarget(new
> redirectrequesttarget(urlfor(resourceref)));
> }
> 
> -igor
> 
>> In a project I am working on, I wrote a DynamicWebResource that generates
>> a
>> PDF file and, by setting the Content-Disposition in the header, got it so
>> that the user is prompted to download the PDF when they click on a
>> ResourceLink to my PDF-generating resource.
>>
>> That all works fine but now I need to open the PDF from a button.  I want
>> to
>> allow the user to select a value in a form and press a button to view
>> somewhat of a report for the item they selected.  However, there doesn't
>> appear to be any type of button that would lead a user to my
>> DynamicWebResource.  Is there any way to have a button do a submit
>> (update
>> the model) and then lead the user to a resource?
>>
>> -Brandon
>> --
>> View this message in context:
>> http://www.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton--tp15459841p15459841.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton--tp15459841p15466386.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: Opening DynamicWebResource from Button/AjaxButton?

Posted by Igor Vaynberg <ig...@gmail.com>.
onsubmit() {
  getrequestcycle().setrequesttarget(new
redirectrequesttarget(urlfor(resourceref)));
}

-igor


On Feb 13, 2008 8:18 AM, UPBrandon <bc...@up.com> wrote:
>
> In a project I am working on, I wrote a DynamicWebResource that generates a
> PDF file and, by setting the Content-Disposition in the header, got it so
> that the user is prompted to download the PDF when they click on a
> ResourceLink to my PDF-generating resource.
>
> That all works fine but now I need to open the PDF from a button.  I want to
> allow the user to select a value in a form and press a button to view
> somewhat of a report for the item they selected.  However, there doesn't
> appear to be any type of button that would lead a user to my
> DynamicWebResource.  Is there any way to have a button do a submit (update
> the model) and then lead the user to a resource?
>
> -Brandon
> --
> View this message in context: http://www.nabble.com/Opening-DynamicWebResource-from-Button-AjaxButton--tp15459841p15459841.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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