Re: Two ActionForms colliding on property name

2003-01-27 Thread David Graham
Yet another reason to not use Action chaining.  Maybe you could rethink why 
you're chaining the actions.

David






From: Derek Richardson [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: Two ActionForms colliding on property name
Date: Mon, 27 Jan 2003 15:43:05 -0500

I have one action forwarding to another action. The first action and the 
second action both have form-beans specified using the name attribute and 
these form beans are different. Unfortunately, these two ActionForms each 
have an attribute named value, but in ActionForm one it is a String, 
while, in ActionForm two, it is a List.

You probably already see the problem. Here is what I think it is. When a 
JSP submits to the first action, there is a request parameter called 
value which is a String. When the first action forwards to the second, 
ActionForm two is populated from the request, the string is found in place 
of the list, and I get BeanUtil.populate() errors.

Any suggestions (other than changing the attribute names, which is a 
possibility, but not my preference)?

Thanks,

Derek Richardson



Here's the error, if you're interested:



type Exception report

message Internal Server Error

description The server encountered an internal error (Internal Server 
Error) that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: BeanUtils.populate
	at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:980)
	at 
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:779)
	at 
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:246)
	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1292)
	at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at 
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:683)
	at 
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:431)
	at 
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:355)
	at 
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1014)
	at 
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:417)
	at 
org.apache.struts.action.RequestProcessor.processActionForward(RequestProcessor.java:390)
	at 
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:271)
	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1292)
	at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
	at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
	at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
	at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
	at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
	at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
	at 
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
	at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
	at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
	at 
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
	at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
	at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
	at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
	at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
	at 
org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
	at 
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
	at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
	at 
org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
	at 

RE: Two ActionForms colliding on property name

2003-01-27 Thread Derek Richardson
I have gone back and read the posts on action chaining to October 21 2002. If I need 
to go back further, let me know. I have rethought why I am chaining the actions and 
this is what I have come up with.

As I understand it, this is the popular and well-liked Struts convention:

Action1 - JSP1 - Action2 - JSP2 - Action3 - JSP3 - ... - ActionN - JSPn

This seems somewhat messy to me because a single Action has to handle both 
post-processing the last JSP and pre-processing the next JSP. For instance, Action2 
has to both do whatever it has been asked to do by JSP1 and also prepare for the 
display of JSP2. So, (1) Action2 will first take some input from JSP1 and save it to 
the model and then (2) read some other data from the model and package it up for JSP2 
to consume. This strikes me as two logically separate concerns being coupled together 
in a single non-cohesive action.

The model that is more intuitive to me is:

PreAction1 - JSP1 - PostAction1 - PreAction2 - JSP2 - PostAction2 - ... - 
PreActionN - JSPn

Of course, in some cases the post-processing of the last request *is* closely linked 
to the preprocessing of the next response. In this situation, the current convention 
works well. However, imagine the case of coming out of the last JSP in an Add Foo 
wizard. You want to (1) save the new Foo and (2) redisplay the list of all Foos so the 
user can decide what to do next. These two activities are not closely linked. 
Additionally, consider that you also can come out of a Delete Foo page where you 
want to (1) delete the outdated Foo and (2) redisplay the list of all Foos so the user 
can decide what to do next. Not only are the activities not closely linked, but it 
sure would be nice to have an Action that encapsulates the common activity #2 so that 
code doesn't have to be duplicated. Notice, in this case, there is no pollution of the 
Action by business logic: all the action does is call a method on the business logic 
facade to get a Collection of Foos and then put it in the request scope. I don't see 
any non-cumbersome way of eliminating this duplication without action chaining of the 
restricted type I am talking about.

In short, some of my Actions prepare data for a JSP to display. I can't forward to the 
JSP without preparing the data first. I may want to forward to the same JSP from 
several different places in my workflow. I don't want to duplicate the data 
preparation code in several different places in my workflow. Is there a solution for 
me other than action chaining?

FYI, I am halfway through the Cavaness book and don't remember seeing action chaining 
discussed. I have not read any other of the Struts books. If what I am asking is 
covered in depth somewhere else, a short summary and a clear citation that will let me 
find the resource is appreciated.

Thanks,

Derek Richardson

 -Original Message-
 From: David Graham [mailto:[EMAIL PROTECTED]]
 Sent: Monday, January 27, 2003 3:51 PM
 To: [EMAIL PROTECTED]
 Subject: Re: Two ActionForms colliding on property name
 
 
 Yet another reason to not use Action chaining.  Maybe you 
 could rethink why 
 you're chaining the actions.
 
 David
 
 
 
 
 
 
 From: Derek Richardson [EMAIL PROTECTED]
 Reply-To: Struts Users Mailing List 
 [EMAIL PROTECTED]
 To: Struts Users Mailing List [EMAIL PROTECTED]
 Subject: Two ActionForms colliding on property name
 Date: Mon, 27 Jan 2003 15:43:05 -0500
 
 I have one action forwarding to another action. The first 
 action and the 
 second action both have form-beans specified using the name 
 attribute and 
 these form beans are different. Unfortunately, these two 
 ActionForms each 
 have an attribute named value, but in ActionForm one it is 
 a String, 
 while, in ActionForm two, it is a List.
 
 You probably already see the problem. Here is what I think 
 it is. When a 
 JSP submits to the first action, there is a request parameter called 
 value which is a String. When the first action forwards to 
 the second, 
 ActionForm two is populated from the request, the string is 
 found in place 
 of the list, and I get BeanUtil.populate() errors.
 
 Any suggestions (other than changing the attribute names, which is a 
 possibility, but not my preference)?
 
 Thanks,
 
 Derek Richardson
 
 
 
 Here's the error, if you're interested:
 
 
 
 type Exception report
 
 message Internal Server Error
 
 description The server encountered an internal error 
 (Internal Server 
 Error) that prevented it from fulfilling this request.
 
 exception
 
 javax.servlet.ServletException: BeanUtils.populate
  at 
 org.apache.struts.util.RequestUtils.populate(RequestUtils.java:980)
  at 
 org.apache.struts.action.RequestProcessor.processPopulate(Req
 uestProcessor.java:779)
  at 
 org.apache.struts.action.RequestProcessor.process(RequestProc
 essor.java:246)
  at 
 org.apache.struts.action.ActionServlet.process(ActionServlet.j
 ava:1292