I hope someone can give me a hand.  I'm trying to do something similar, and
seemingly stumped.

I have a form that I want to have the user fill out, and then I just want to
email the completed form to someone on our team.  So, I created subclasses
of form components that can be switched from "edit" to "view" mode, and that
works great.  So, I submit the form, and swap them out to "view" mode so
that it is the exact same form, except instead of text fields and the like,
I then have labels that display the input, in an un-editable way.

Now, the problem: In the onSubmit() of my Button, I switch the fields over,
and then I would like to render the page to a String and email it, and then
render the page for the user.

I've tried the methods below, and both are failing - can someone please
help.

First, I tried JBQ's method, slightly modified since I'm not in a request
target.  Maybe that's the problem.  Maybe I need to specifically mount this
page to a request strategy as he does in the example.  But, I'd rather be
able to accomplish this in the form itself.

   final StringResponse emailResponse = new StringResponse();
   final WebResponse originalResponse =
(WebResponse)RequestCycle.get().getResponse();
   RequestCycle.get().setResponse(emailResponse);
   RequestCycle.get().getRequestTarget().respond(RequestCycle.get());
   // Here send the email instead of dumping it to stdout!
   System.out.println(emailResponse.toString());
   RequestCycle.get().setResponse(originalResponse);
   RequestCycle.get().setRequestTarget(new BookmarkablePageRequestTarget(
Home.class));

I get this error (BTW - I'm on 1.2.6 with this app until we have an RC
release):

Caused by: java.lang.ClassCastException: wicket.response.StringResponse
   at wicket.protocol.http.WebRequestCycle.getWebResponse(
WebRequestCycle.java:110)
   at wicket.markup.html.WebPage.configureResponse(WebPage.java:249)
   at wicket.markup.html.pages.ExceptionErrorPage.configureResponse(
ExceptionErrorPage.java:106)
   at wicket.Page.onRender(Page.java:854)
   at wicket.Component.render(Component.java:1526)
   at wicket.Page.renderPage(Page.java:408)
   at wicket.request.target.component.PageRequestTarget.respond(
PageRequestTarget.java:67)
   at wicket.request.compound.DefaultResponseStrategy.respond(
DefaultResponseStrategy.java:49)
   at wicket.request.compound.AbstractCompoundRequestCycleProcessor.respond
(AbstractCompoundRequestCycleProcessor.java:66)
   at wicket.RequestCycle.respond(RequestCycle.java:950)
   at wicket.RequestCycle.step(RequestCycle.java:1025)

I also tried using WicketTester in my onSubmit, and it failed:

               WicketTester tester = new WicketTester();
               tester.startPage(AdvertiseOnTHF.this);
               String email = tester.getServletResponse().getDocument();
               // Here send the email instead of dumping it to stdout!
               System.out.println("EMAIL: " + email);
               info("Your request has been sent.");

I can't do this because a lot of things in my app depend on getSession()
being my sub-class of WebSession, and getApp() being my sub-class of WebApp.

So, what to do?  Any suggestions?  Should I just mount this form
specifically to a request strategy and do it more like JBQ's example?

Thank you!
Jeremy Thomerson


On 6/24/07, Jean-Baptiste Quenot <[EMAIL PROTECTED]> wrote:

* John Krasnay:
> OK, so WicketTester is the way to go. JBQ's response implied that there
> was a more direct way to do it, but I'll give WicketTester a try.

Yes there is a more direct way.  I'm sorry I made an error, I
meant StringResponse, not StringRequestTarget.  I spent a few
minutes writing the example, as this is a recurring question, here
it is:


http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/staticpages/Application.java?revision=550248&view=markup

Look at the very bottom, where I'm using a custom
BookmarkablePageRequestTarget:

new BookmarkablePageRequestTarget(Page.class, params) {
        /**
         * @see
org.apache.wicket.request.target.component.BookmarkablePageRequestTarget#respond
(org.apache.wicket.RequestCycle)
         */
        @Override
        public void respond(RequestCycle requestCycle)
        {
                if (requestParams.getString("email") != null) {
                        final StringResponse emailResponse = new
StringResponse();
                        final WebResponse originalResponse =
(WebResponse)RequestCycle.get().getResponse();
                        RequestCycle.get().setResponse(emailResponse);
                        super.respond(requestCycle);
                        // Here send the email instead of dumping it to
stdout!
                        System.out.println(emailResponse.toString());
                        RequestCycle.get().setResponse(originalResponse);
                        RequestCycle.get().setRequestTarget(new
BookmarkablePageRequestTarget(Sent.class));
                } else {
                        super.respond(requestCycle);
                }
        }
};

The example can be found in latest wicket examples in the
"staticpages" demo.
--
     Jean-Baptiste Quenot
aka  John Banana   Qwerty
http://caraldi.com/jbq/

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to