struts action mapping input attribute - dynamic value ?

P

Pavel

Greetings to all -

I'm having a difficulty with struts action mapping input attribute. In
my case, I have the following actions sequence:

prepareData -> showData1 -> saveData
prepareData -> showData2 -> saveData
prepareData -> showData3 -> saveData
....

where
- prepareData is the Action that fills the form bean with the data
to be edited. Part of this data also identifies what jsp is used to
show the data (different template). Once form bean is filled, action
forwards the control to one of the JSPs.
- showDataX.jsp are the JSPs that show the data.
- saveData is the Action that saves the data.

The form bean that is used here has a validate() method that may
return errors so the input attribute must be specified in the saveData
mapping. Here is my problem: I can specify only one of them which
means that errors will be displayed only on one of the JSPs. If any
other JSP was used to forward to by prepareData action then errors
will be displayed on the one that is specified in the input attribute.
If no input attribute is specified, an error is thrown from struts
RequestProcessor saying that input attribute is missing.

Does anybody know how I could get around it ?

P.S. Wouldn't it make sense for struts to try to use the original
destination if the input attribute is not specified ?

Thanks
Pavel
 
S

Sudsy

Pavel said:
Greetings to all -

I'm having a difficulty with struts action mapping input attribute. In
my case, I have the following actions sequence:

prepareData -> showData1 -> saveData
prepareData -> showData2 -> saveData
prepareData -> showData3 -> saveData
...

where
- prepareData is the Action that fills the form bean with the data
to be edited. Part of this data also identifies what jsp is used to
show the data (different template). Once form bean is filled, action
forwards the control to one of the JSPs.
- showDataX.jsp are the JSPs that show the data.
- saveData is the Action that saves the data.

The form bean that is used here has a validate() method that may
return errors so the input attribute must be specified in the saveData
mapping. Here is my problem: I can specify only one of them which
means that errors will be displayed only on one of the JSPs. If any
other JSP was used to forward to by prepareData action then errors
will be displayed on the one that is specified in the input attribute.
If no input attribute is specified, an error is thrown from struts
RequestProcessor saying that input attribute is missing.

Does anybody know how I could get around it ?

Three different actions, each with input specified to be the
originating JSP page. You can specify the same ActionForm
(name attribute) and servlet (class attribute) for all three.
It's just a matter of adding a couple of actions tags to the
struts-config.xml file.
 
P

Pavel

Thanks for the hint. Your solution works well but only for static
number of JSPs. Every time new JSP template is added,
struts-config.xml would have to be modified.

Actually, all I needed to do is to specify 'prepareData' as an input
attribute value for 'saveData'. It works great for me by allowing to
add new templates to the application seamlessly.

Thanks Pavel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top