struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Nenning <Christoph.Nenn...@lex-com.net>
Subject Re: Url rewriting of .action to .jsp
Date Mon, 23 Sep 2013 08:45:09 GMT
It seems a little late to join this discussion, but anyway here is what I 
think.


Per default the framework shows validation errors for simple GET requests.

The easiest way to work around that is to add "!input" to the url, like 
this:

login!input.action

You can bookmark that and generate links to the page like that.


But I consider that rather ugly.


The solution proposed by Lukasz is to use 2 actions: one for GET requests 
and another one for POST requests. I didn't think of that before.



Here is what we usually do:
- action.execute() is used for displaying the page (GET requests)
- it returns INPUT (as it is the default for validation errors)
- the INPUT result is mapped to a tile
- enable DMI
- for POST requests the actions provide other methods like 
login()/save()/create()
- those methods return a result name like "redisplay" which is mapped to a 
actionRedirect result (redirect after POST)
- to invoke the other action methods we use parameter names prefixed with 
"method:"

That way we get nice URLs for GET requests and pages are shown without 
validation errors per default. And we can handle the complete page in one 
action class.


An issue that arises is to properly initialize actions. If validation 
errors are present execute() is not invoked, so we use Prepareable to load 
data we need to display (or init lists used for <select>s and stuff like 
that). But we have to take care that we don't override user input with DB 
content in prepare(), so some initializtaion is done in prepare() and some 
is done in execute().

To avoid that we use AJAX validation which makes actions much simpler.



Regards,
Christoph




> 
> "You cannot forward to actions"
> 
> Thanks, that was the idea that was missing from my understanding.
> 
> Got it working the way I wanted in a minute :)
> 
> Many thanks - appreciated :)
> Serdyn du Toit
> 
> 
> 
> On Mon, Sep 23, 2013 at 8:47 AM, Lukasz Lenart 
<lukaszlenart@apache.org>wrote:
> 
> > 2013/9/22 Serdyn du Toit <dutoitns@gmail.com>:
> > > What I have now is as follows:
> > >     <package name="login" namespace="/admin/login" 
extends="default">
> > >         <default-interceptor-ref name="any" />
> > >         <action name="login-form">
> > >             <result name="success">/admin/login/login.jsp</result>
> > >         </action>
> > >         <action name="login"
> > > class="com.d6.admin.login.AdminUserLoginAction">
> > >             <result 
name="input">/admin/login/login-form.htm</result>
> > >             <result
> > name="success">/admin/dashboard/dashboard.htm</result>
> > >         </action>
> > >     </package>
> > >
> > > The following part is just problematic - I'm struggling to find 
these
> > > resources.  My browser tells me "the requested resources is not
> > available",
> > > but when I hit the actions directly everything works 100%
> >
> > You cannot forward to actions - that what you do right now: <result
> > name="input">.... - changing extension to .htm doesn't change action
> > in a file. You can forward only to static resources (files), actions
> > are logical resources.
> >
> > Remove "struts.action.extension" - stick with default.
> >
> > Check out struts2-blank application and see how it is solved there -
> > example.xml, Login action class, Login.jsp and Login-validation.xml
> >
> > https://svn.apache.org/repos/asf/struts/struts2/trunk/apps/blank/
> >
> >
> > Regards
> > --
> > Ɓukasz
> > + 48 606 323 122 http://www.lenart.org.pl/
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >

This Email was scanned by Sophos Anti Virus

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message