You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Francesco Cadili <fc...@skylink.it> on 2003/05/04 09:37:43 UTC

[TO DO] Struts Framework extension (2)

This mail is a reply to the answer to the proposal path "Mapping 
multiple action to the same uri".

The example posted in the fist mail "[TO DO] Struts Framework 
extension" was extracted from a real problem solved without the 
struts framework. However there was so much likeness between my 
solution and the struts framework to suggest me to propose a struts 
extension.

The problem was about building a j2ee application with light HTML 
front end (the  network band was not too high) and an application 
logic (controller) full implemented at server level with a fairly 
complex business logic.

Part of the application functionality was about collecting some data 
from the user and putting it inside the database. Unlikely, since the 
input data logic was complex and we can't create neither too big HTML 
pages or a rich user interface (with too client scripting), we had to 
break down the input process into several step.

As an example consider the insertion into the database of a group of 
rows to a database table. We have an input page that collect the data 
(that are temporary stored in the server session under an appropriate 
id) than a page that chose the insertion method (substitution, 
queuing or inserting) that fires the database insertion.

The problem with this schema arose when we had to apply the 
uri/action mapping of the struts framework since we had to keep the 
right input flow without too much coding.

The solution to this problem was a local pattern that is very similar 
to struts. We had used this schema:

1. /data/insert/insert.do

The local controller that handles all the user inputs, collects it 
and fires the right business method.

2. /WEB-INF/data/insert/collect.jsp
    /WEB-INF/data/insert/select.jsp
    /WEB-INF/data/insert/success.jsp

The private jsps used to collect and start the insertion process.

3. /data/insert/index.jsp

The usual public entry point that redirects the user to the 
/data/insert/insert.do servlet.

To gain some application protection we used the POST method to submit 
the input data to the servlet and we checked the referrer page to 
prevent the application from cracks.

The first redirection was needed to read the type table data inside 
some Java Beans.


With struts this could be done always with some extra coding that is 
grater than the coding solution from the scratch. The proposal 
submitted in "[TO DO] Struts Framework extension" was a fixing to 
struts to solve this problem.

There is another problem with struts that is due to the use of a 
single configuration file. With my solution the different controller 
and their logic were loosely coupled, whereas with the use of a 
single struts.xml they are not.

This limitation can be overcome collecting the information about the 
same uri in another configuration file:

    <action    path="/data/insert/insert.do"
                type="org.apache.struts.webapp.insert.Step1Action"
	       protocol="POST"
	       resolver="/data/insert/insert.do"
	       button="org.apache.struts.webapps.Submit1"
                name="step1Form"
                scope="request"
                input="/WEB-INF/data/insert/step1.jsp">
         <forward name="next-step" path="/WEB-INF/data/insert/step2.jsp" />
    </action>

   <action-mappings>
     <action    path="/data/insert/insert.do"
                type="org.apache.struts.webapp.insert.Step2Action"
	       protocol="POST"
	       resolver="/data/insert/insert.do"
	       button="org.apache.struts.webapps.Submit2"
                name="step1Form"
                scope="request"
                input="/WEB-INF/data/insert/step2.jsp">
         <forward name="next-step" path="/WEB-INF/data/insert/step3.jsp" />
    </action>

     <action    path="/data/insert/insert.do"
                type="org.apache.struts.webapp.insert.Step3Action"
	       protocol="POST"
	       resolver="/data/insert/insert.do"
	       button="org.apache.struts.webapps.Submit3"
                name="step3Form"
                scope="request"
                input="/WEB-INF/data/insert/step3.jsp">
         <forward name="next-step" path="/WEB-INF/data/insert/success.jsp" />
    </action>

    <resolver   path="/data/insert/insert.do">
      <input    path="/data/insert/" />
      <input    path="/data/insert/index.jsp" />
      <input    path="/data/insert/insert.do" />
    </resolver>

    </resolver>

See "[TO DO] Struts Framework extension" for further info.


Hi,
	Francesco

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org