Hello Wicket Developers,

I discovered a  serious problem in Wicket 1.2 while  my Wicket app
went in production.

Previously I was using ""  (root context) in the servlet container
configuration,  and servlet  mapping  "/*" in  web.xml.  It  works
great.  You  may be surprised,  but yes,  it works.  I  don't have
static resources  to serve, so  I didn't  need to do  the "/app/*"
servlet mapping that is recommended in the documentation.

But for production we had the  bad idea to change the context path
to "/myapp"  (non-root context), still with  servlet mapping "/*".
And in this configuration, Wicket ceased to work properly.

Note: I'm  not  talking about  servlet  mapping  "/", which  is  a
different story, I know using that will not work with Wicket.  I'm
only talking about servlet mapping "/*".

The  symptom is  that  submitting forms  using  the "POST"  method
leaded to strange  errors that revealed that all  form values were
lost.  Looking at the page  source, <form>'s action attribute gave
me a hint, it was written:

<form action="/myapp?wicket:interface=:2:registerForm::IFormSubmitListener" 
wicket:id="registerForm" method="post" id="registerForm">
                   ^^^
Instead of:

<form action="/myapp/?wicket:interface=:2:registerForm::IFormSubmitListener" 
wicket:id="registerForm" method="post" id="registerForm">
                   ^^^

In  this case,  the servlet  engine will  redirect from  /myapp to
/myapp/  to force  using a  canonical URL,  and that's  why I  was
loosing the form values after POST.

The good news is that a one-line patch to WebRequestCodingStrategy
is sufficient  to fix the  wrong Wicket behaviour  (see attached).
As you  know the URL prefix  is computed only at  the first Wicket
request, and  when I  request http://myserver/myapp/";  the servlet
container returns  "" (empty string) as  getServletPath().  So the
empty string shall not  be a no-go for appending a  "/" at the end
of the URL.

I  tested the  patch only  with Jetty  5, but  if you  feel it  is
necessary, I can take the time to test on other servlet containers
too.

Thanks for reading up to the end!
-- 
     Jean-Baptiste Quenot
aka  John Banana Qwerty
http://caraldi.com/jbq/
--- src/java/wicket/protocol/http/request/WebRequestCodingStrategy.java.orig    
Sun Aug 27 12:50:17 2006
+++ src/java/wicket/protocol/http/request/WebRequestCodingStrategy.java Fri Sep 
 8 15:52:09 2006
@@ -802,7 +821,7 @@
                                        buffer.append(contextPath);
                                }
                                String path = request.getServletPath();
-                               if (path != null && !path.equals(""))
+                               if (path != null)
                                {
                                        if (!buffer.endsWith("/") && 
!path.startsWith("/"))
                                                buffer.append("/");
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-develop mailing list
Wicket-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-develop

Reply via email to