开发者

Wizard form in Struts

I am creating a wizard in Struts. It cotains 4 steps. For Each step I have separate ActionClass say:-

  • Step1Action.java
  • Step2Action.java
  • Step3Action.java
  • Step4Action.java

and in each class the开发者_运维技巧re are 2 methods input() and process().

  • input() method is for showing the page in input mode
  • process() method is will be use for processing the submitted data (if validation is ok)

I am carrying all data upto the last step in a session. And saving all of them in database in the last step

Similaly 4 action tags in struts.xml like :-

    <action name="step1" class="com.mycomp.myapp.action.Step1Action1" method="input">                       
      <result name="success" type="redirectAction">step2</result>   
      <result name="input">/view/step1.jsp</result>     
    </action>

    <action name="step2" class="com.mycomp.myapp.action.Step1Action2" method="input">                       
      <result name="success" type="redirectAction">step3</result>   
      <result name="input">/view/step2.jsp</result>     
    </action>

But I think I am going wrong. Please Tell me How will I handle This case?


If you are trying to develop some wizard like functionality than there is already an interceptor in struts2 for the same Scope Interceptor here are the details for the same http://struts.apache.org/2.0.14/docs/scope-interceptor.html


There is something conceptually wrong here - and the conceptual error lies before the wizard scenario.

For one thing, a Struts2 action should not (typically) have a "input" method. A Struts2 action should DO SOMETHING (method) on behalf of a client request (URL), and return a RESULT (string) which returns a new VIEW (jsp page) to the client.

"input" is (conventionally) just a RESULT that corresponds to the case "I cannot do what I (action) am supposed to do because the data entered is incomplete, or invalid; let's tell the user to try to input the data again"

You should be sure to understand the simplest use cases (the typical input form with a result message), before attempting a wizard. See here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜