Hi, all.
So, from what I've seen ex post facto, I have been looking at Struts a
bit differently than it had been intended to be used. I have designed
and (partially) built my application around the concept of exclusively
using forms for communications between the view and the controller (or
whichever category the Action bit officially falls into.)
So, my current approach for the display of information is to pass the
form through a stateless Session EJB in order to fill in the values,
modify the model, or whatever else needs to be done. For instance,
here's a snippet from one of my actions:
--------
try {
ServiceProviderGlobalForm globalForm =
( ServiceProviderGlobalForm ) form;
String id = request.getParameter( "id" );
globalForm.setSpId( Integer.parseInt( id ) );
// This method fills the form based on the ID set above
this.fillForm( request, globalForm );
}
catch ( NumberFormatException nfe ) {
ActionErrors errors = new ActionErrors();
System.err.println( "Number format Exception" );
errors.add( ActionErrors.GLOBAL_ERROR,new ActionError( "Number
format Exception in perform" ) );
saveErrors( request, errors );
}
finally {
return ( mapping.findForward( "globalview" ) );
}
--------
... and here's the important part of the fill method:
--------
Utils utils = Factory.createUtils( );
ServiceProviderToolHome spToolHome = (ServiceProviderToolHome )
utils.getHomeInterface( ServiceProviderToolHome.class.getName() );
ServiceProviderTool sptool = spToolHome.create();
form = sptool.fillGlobalForm( form );
--------
...so I learned The Hard Way that a) EJB (and any remote calls,
probably) methods pass objects by value and b) reference modifications
in the perform method are lost...
So, the above approach won't work.
My question(s) for y'all:
1) Is there a way to reassign the reference for the form to be
returned?
2) If not, what is another approach that I could use?
For the sort term, I was thinking of just creating a visitor object
that will fill the forms locally, thus maintaining the originally
referenced form. My boss hates the idea, and I'll admit it's not
pretty. Furthermore, I'm fairly new to Java (especially the
presentation layer,) so I could very well be missing something obvious.
What do you folks suggest?
TIA,
-Chris
__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/