question about ActionForm parameter of Action.execute() method

2003-03-26 Thread Kevin HaleBoyes
Can the ActionForm parameter of the Action.execute method be
null?  Under what circumstances will it be null and when will
it be not-null?

Is this described anywhere?

In the struts-example source, some of the actions check the
form parameter and will instantiate (and put it into scope) if
it is null.  Is that something that has to be done?  Why doesn't
Struts do the instantiation and putting into scope?

Thanks,
Kevin.


__
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: question about ActionForm parameter of Action.execute() metho d

2003-03-26 Thread Kevin HaleBoyes

--- Wendy Smoak [EMAIL PROTECTED] wrote:
 Kevin wrote:
  Can the ActionForm parameter of the Action.execute method be
  null?  Under what circumstances will it be null and when will
  it be not-null?
 
 If there is no form bean associated with the action in
 struts-config.xml,
 then the ActionForm parameter will be null.

And this association is done using the 'name' attribute of action
to refer to a form-bean element?

Thanks for your help,
Kevin.


__
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: question about findForward()

2002-12-04 Thread Kevin HaleBoyes

--- Emmanuel Boudrant [EMAIL PROTECTED] wrote:
 
  You need a redirection. In a redirection, the request (who
 containt the form) is not propagate. Just put in forward
 declaration :
 forward name=toto path=/path_to_toto.jsp redirect=true/
 If your form is stored in session scope, you need to call reset();
 -emmanuel

and

--- Karr, David [EMAIL PROTECTED] wrote:
 Do you just mean you want to do a redirect?  If so, you can do this
 without changing your code, just change the forward definition (in
 your
 action, or global) to have 'redirect=true'.
 

Thank you both.

The strange thing is, I tried the redirect attribute before I posted
my question last night.  I must have done something wrong because
I tried it again this morning after seeing your responses and it
works just as you said.  As a note, it seems to work the same
whether I reset() the form or not (it is in session scope).

Emmanuel, why do you say that I need to call reset()?

Thanks again,
Kevin

__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




html:submit question

2002-12-03 Thread Kevin HaleBoyes
I have a couple of html:submit elements on one html:form.
How do I distinguish between the different buttons?

Specifically, I have

 html:submit property=operationEdit Loan/html:submit
 html:submit property=operationReject Loan/html:submit

The form bean has a setOpereration(String) setter method which
is called with the text of the button (ie, Edit Loan)
when the form is submitted.

When I look at the HTML that is rendered in the browser, I see that
the property attribute becomes the name attribute of the input
element.

The way it works now, I have to compare the value of the operation
property of the form bean against the string that is displayed to
the user.  That seems a bit fragile - suppose the customer wants the
Reject Loan to be Cancel Loan instead.  I'd have to change code
in my action to effect the change.

I'm looking for an attribute to html:submit that is the value that
gets set to the property (operation).  Is there such a thing.

I want to avoid having a different form-bean-attribute for each
submit tag (like operation1, operation2, etc.).

Thanks,
Kevin.


__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: html:submit question

2002-12-03 Thread Kevin HaleBoyes

--- Gemes Tibor [EMAIL PROTECTED] wrote:
 2002. december 3. 16:30 dátummal Kevin HaleBoyes ezt írtad:
 
  The way it works now, I have to compare the value of the
 operation
  property of the form bean against the string that is displayed to
  the user.  That seems a bit fragile - suppose the customer wants
 the
  Reject Loan to be Cancel Loan instead.  I'd have to change
 code
  in my action to effect the change.
 
 Use LookupDispatchAction then. 

Wonderful!  That is it exactly!
Thanks

 Tib

Kevin.


__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




question about findForward()

2002-12-03 Thread Kevin HaleBoyes
I'm having trouble explaining what I want but I'll have a go
of it anyway...

I'm in a Save action as a result of the POSTing of a form
via a html:cancel button.  I do the test:

if (isCancelled(request)) {}

and detect the cancel.  I'd like to go to another Action but
I don't want to propagate the POST.  I want it to be a GET
where the input ActionForm is empty.

I'm calling
 ActionForward forward = mapping.findForward(forwardName);
 return forward;
to go to the new action but it propagates the POST.

Is there anyway turn the POST into a GET?
Should I just call form.reset() manually?


I hope this makes sense.
Kevin.


__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




how to handle empty form fields

2002-11-28 Thread Kevin HaleBoyes
I have a form field that is to represent a Date value.
I input it using a html:text tag

html:text property=assignedDate size=12/

and it corresponds to a String field in the form bean.
It is an optional field and not usually filled in.

In the business logic I call

BeanUtils.copyProperties(lrdto, lrform);

to copy from the form bean to the DTO.  In the DTO the
assignedDate property has the type java.sql.Date.

When the field is left empty on the form I get a
org.apache.commons.beanutils.ConversionException exception
from copyProperties() that was generated by SqlDateConverter.

I'm wondering how to avoid the exception.
If I set a value into the field before I submit the form then
it works fine.  I only run into the exception when I leave the
field blank but my business requirements state that this field
is optional.

There are a __lot__ of questions regarding Date input and
validation in the archives but I didn't find anything about
this exception or optional Date fields.

Thanks for any help,
Kevin.


__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




question about empty form fields

2002-11-27 Thread Kevin HaleBoyes
I have a FormBean that has all strings as the datatypes.
I then have a DTO bean that has the proper datatypes for the
different properties - java.sql.Date, int, etc.

In my JSP form I have an input field that is supposed to represent
a date field.  It is not a required field.  I'm not using the 
Validator framework.

html:text property=assignedDate size=12/

So, when the form is submitted with the assignedDate field have not
been set, the value in the FormBean is the empty string .

After validating the fields in the FormBean,
I call BeanUtils.copyProperties() to move the values from the
FormBean into the DTO but I get a ConversionException on this
empty field.  I've attached the exception report below.

If I fill in the field with a properly formed date then everything
works fine.  It is only when I leave the field empty that I get
the exception.

Am I doing something I shouldn't?  Just as an empty string field
is valid and handled properly, I feel that an empty date field is
valid and should be handled properly.

How can I fix it?  I could check the value of the date fields and
if they are empty then I could set them to null (which
SqlDateConverter handles correctly) but this is a hack!
I could also register my own converter that handles an empty string
for input but I feel that this is such a common use case for input
date strings I'm confused that it isn't handled.

Thanks for any help,
Kevin.






org.apache.commons.beanutils.ConversionException
at
org.apache.commons.beanutils.converters.SqlDateConverter.convert(SqlDateConverter.java:162)
at
org.apache.commons.beanutils.BeanUtils.copyProperty(BeanUtils.java:359)
at
org.apache.commons.beanutils.BeanUtils.copyProperties(BeanUtils.java:265)
at
com.illuminat.cml.LoanRequestSaveAction.execute(LoanRequestSaveAction.java:130)
at
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:446)
at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:266)
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
com.illuminat.cml.IdentityFilter.doFilter(IdentityFilter.java:101)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:527)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2396)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:469)
at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at

Re: struggling with indexed/repeating input fields

2002-11-20 Thread Kevin HaleBoyes
 From: Leonardo Maciel [EMAIL PROTECTED]
 I GOT IT!

 I forgot to send the struts-config.xml and there were the
difference

 VERY-IMPORTANT
 if I set the action scope=request I get:
 javax.servlet.ServletException: BeanUtils.populate
 ...
 Caused by: java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
 or
 Caused by: java.lang.NullPointerException
 
 make sure you don't have scope=request in your action ...
/action
 /VERY-IMPORTANT


You have really made my day!!!  Thanks.

I took the code you gave me and the code from the original link
(yes, thanks Dave).

I couldn't get either of them to work since I just automatically
put in the scope=request into the configuration entry.  I was
getting a similar error message:
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)
...
- Root Cause -
java.lang.ArrayIndexOutOfBoundsException: 0 = 0
at java.util.Vector.elementAt(Vector.java:427)

Which is similar to every other attempt I've made.  The
array/vector/list/collection wasn't initialized to have the correct
size before the indexed setters were called.  I kind of consider it
to be a bug in BeanUtils but I'm not sure.

It would
never have occurred to me that the scope would effect it.  As soon
as I made that change and restarted, it worked!

I've not tried the nested tags but I suspect the crucial element is
the scope of the form bean.

I do agree with [EMAIL PROTECTED] about having to put
the bean into session scope - I'll have to manage that very
carefully or implement the indexed setter that you gave and that
Jim Krygowski mentioned.  I'll also look at the lazyList from
Commons Collection.


Thanks again!
Also, thanks to everyone else who helped.

Kevin.



__
Do you Yahoo!?
Yahoo! Web Hosting - Let the expert host your site
http://webhosting.yahoo.com

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




struggling with indexed/repeating input fields

2002-11-19 Thread Kevin HaleBoyes
I've asked this question several times on this mailing list but
I've never received an answer that would help.  I've dug a bit
deeper and understand more about the problem but I'm still really
struggling with indexed/repeating input fields so I thought I'd
ask again.  I'm starting to wonder if it is possible.

In my ActionForm I have an array property that is initialized to
null (I don't know the values until the Action executes).
I have a getter
that returns the entire array and a setter that takes an array.
I also have indexed getters and setters.  The array is of another
class (that simply has two strings in it with the default/empty
constructor and getters and setters).

In my (edit) action I construct an array and call the setter in the
action form instance (that I just created).  I then forward to a JSP
page that has a logic:iterate tag and html:text tags all within
a form tag.  The form has a html:submit that calls my save action.
The save action simply forwards to a confirmation JSP page that
has a similar iteration to display the input values.

The initial edit form gets displayed properly - the expected
number of iterations are performed and the expected values of the
input fields is shown.  When I press the submit button things break.
I know that isn't terribly descriptive but how it breaks depends
on how I form the html:text tags - there are two cases that I've
tried.

In the first case, I use the following in the edit JSP form:

logic:iterate id=li name=IndexedForm property=lineItem
  html:text name=li property=itemNo indexed=true/
  html:text name=li property=desc indexed=true/
/logic:iterate

As I said, it displays properly.  I change the desc text and hit
the submit button and end up getting an exception:

  ApplicationDispatcher[/cml] Servlet.service() for servlet
   jsp threw exception
  org.apache.jasper.JasperException: No collection found

In the save action I printed the toString() of the input form
before forwarding to the JSP page and can see that the array is
in fact null.  Why is it null?  Who is responsible for instantiating
an array for that field - struts or the application?  If it is the
application, how can it know how big to make the array?


In the second case, I use the following in the edit JSP form:

logic:iterate id=li name=IndexedForm
property=lineItem indexId=i
   % String prop1 = lineItem[ + i + ].itemNo; %
   html:text property=%= prop1 % size=30/
   % String prop2 = lineItem[ + i + ].desc; %
   html:text property=%= prop2 % size=30/
/logic:iterate

Again, it displays properly.  I change the desc text and hit the
submit button and end up getting an exception:

StandardWrapperValve[action]: Servlet.service() for
servlet action threw exception
javax.servlet.ServletException: BeanUtils.populate
...
Caused by: java.lang.NullPointerException
at
com.illuminat.cml.IndexedForm.getLineItem(IndexedForm.java:286)


This happens even before it calls the save action.


So, I'm at a loss as to how to handle indexed or repeating fields.
I've looked at the code in html-setters.jsp and TestBean from the
exercise-taglib in the distribution but that uses fixed size
arrays and static initializers.  It hasn't been simple to go from
that to a variable number of array elements and non-static
(from a database) initialization.

I've also looked in the archives and
on the current mailing list and found nothing.  Actually, I've been
seeing more questions regarding indexed properties lately
(mostly using
DynaBeans) but they are generally going un-answered or not coming
up with solutions, just more questions.  This is not a complaint
as I know everyone is very busy but it does mean that I've not found
anything in the archives.

Help would be most appreciated.  Sample code would be even nicer!
Is it even possible with Struts (version 1.1b2)?
I can furnish code or a better explaination if needed.

Kevin




__
Do you Yahoo!?
Yahoo! Web Hosting - Let the expert host your site
http://webhosting.yahoo.com

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




need help with indexed properties

2002-11-07 Thread Kevin HaleBoyes
I have a Forms Bean

public class IndexedForm {
  private String items[] = new String[] {one, two};
  public String[] getItems()  { return items; }
  public void setItems( String[] v )  { items = v; }
}

and a JSP page to display/edit the items:

logic:iterate id=i name=IndexedForm property=items
  bean:write name=i/  br
  html:text property=items indexed=true/
/logic:iterate

The bean:write tag displays the contents correctly but
the html:text tag doesn't.  Instead, I get
[Ljava.lang.String;de530a
which looks like the address of the items array.

Why doesn't this work?

I've tried adding indexed getters and setters but that didn't
work.  I've also searched the archives since this seems like a
common problem but I've not come across an answer - similar things
but nothing that shed any light on my problem.
In fact this
http://www.mail-archive.com/struts-user;jakarta.apache.org/msg47247.html
is very similar but there was never a reply to the last post.

I'm running Struts 1.1b2 on Tomcat 4.1.10.

I'm really at a loss and would appreciate any help.
Kevin.


__
Do you Yahoo!?
U2 on LAUNCH - Exclusive greatest hits videos
http://launch.yahoo.com/u2

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




repeating input fields

2002-10-14 Thread Kevin HaleBoyes

I know this has been asked before but I'm unable to find anything
in the archive - probably not using the right search terms...

I'm trying to create a form that allows the user to input a list
of strings.  Kind of like a detail block (of a master-detail
relationship).

So I have

  public class LoanPurpose {
private String id;
private String description;
public String getId() {return id;}
public void   setId( String v ) { id = v; }
public String getDescription() {return description;}
public void   setDescription( String v ) {description = v;}
  }

and a Form bean

  public class LoansForm extends ActionForm {
private LoansPurpose[] purposes = null;
public LoanPurpose[] getPurposes() {return purposes;}
public void setPurposes( LoanPurpose[] v ) {purposes = v;}
public void reset(ActionMapping mapping,
   HttpServletRequest request) {purposes = null;}
  }


In my JSP form I have:

html:form action=/saveLoanPurps method=post
table
logic:iterate id=p name=LoansForm property=purposes
  trtd
  html:text name=p property=id size=15/
  /tdtd
  bean:write name=p property=description filter=true/
  /td/tr
/logic:iterate
/table
html:submitSave/html:submit
/html:form


If I stuff a few values into the purposes array in the edit
action they properly get displayed when the form is rendered.


This is where I get lost though.  When I hit the Save submit
button I don't get the results I expect.  In the Save action I
print the contents of the LoansForm.purposes array and it is null,
instead of having the contents of the input fields.

What am I missing?


Any help would be most appreciated.
Thanks,
Kevin.

__
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos  More
http://faith.yahoo.com

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




RE: repeating input fields

2002-10-14 Thread Kevin HaleBoyes

 instead of:
   property=id
   property=description
 
 use:
   property=purposes[1].id
   property=purposes[1].description

That makes sense!  I made the changes to the JSP file and also
added indexed getter/setter to the form bean.

  public class LoansForm extends ActionForm {
private LoansPurpose[] purposes = null;
public LoanPurpose[] getPurposes()
   {return purposes;}
public void setPurposes( LoanPurpose[] v )
   {purposes = v;}
public LoanPurpose getPurposes( int idx )
   {return purposes[idx];}
public void setPurposes( int idx, LoanPurpose v )
   {purposes[idx] = v;}
public void reset(ActionMapping mapping,
   HttpServletRequest request) {purposes = null;}
  }

But now when I submit the Save I'm getting an exception

javax.servlet.ServletException: BeanUtils.populate
...
- Root Cause -
java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor16.invoke(Unknown
Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:475)
at
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:410)
at
org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:749)
at
org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:780)
at
org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:793)
at
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:726)
at
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:978)


Caused by: java.lang.NullPointerException
at
com.illuminat.cml.LoansForm.getPurposes(LoansForm.java:1420)
... 49 more

(obviously, I've trimmed the exception report)

Line 1420 of LoansForm.java is the indexed getter.  So my purposes
array is null and I'm trying to get the value at a particular index
(idx=3 in this test run).
The array is null because I set it to that in the reset() method.
That's what I'm supposed to do though, isn't it?

How can I know to allocate the array and what size it should be?
I'm missing something here!  For instance, I'm executing a Save
so why is the indexed getter being called and not the indexed
setter?

 This should get you started...

It did indeed, and I thank you for that.  Unfortunately, it has
raised more questions and I'm at a loss as to how to proceed!

Thanks again,
Kevin

__
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos  More
http://faith.yahoo.com

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




RE: struts-config.xml question

2002-10-03 Thread Kevin HaleBoyes

Victor and Emmanuel, thanks for your answers.
With them, and the later discussion on similar topics I
think I understand.  Part of my confusion comes from a bug I've
not been able to repeat.  At one point in time I changed the
'attribute' property to 'name' and my application stopped working.
It seems that I had done something else (not sure what) and the
problem had nothing to do with using 'name'.  I've just tried to
repeat it in isolation and I can't.

Again, thanks.
Kevin.

__
Do you Yahoo!?
New DSL Internet Access from SBC  Yahoo!
http://sbc.yahoo.com

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




RE: EL and the developer's roadmap

2002-10-03 Thread Kevin HaleBoyes

 First time I've heard of EL too.  Where can I get more info?

Others have already noted

 http://java.sun.com/products/jsp/jstl/index.html

Also have a look at a couple of OnJava articles (the printable
versions)

 http://www.onjava.com/lpt/a/2611
 http://www.onjava.com/lpt/a/2610

Kevin.

__
Do you Yahoo!?
New DSL Internet Access from SBC  Yahoo!
http://sbc.yahoo.com

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




struts-config.xml question

2002-10-01 Thread Kevin HaleBoyes

I'm looking at the struts-example and its struts-config.xml file.

In the action section for editRegistration, 'attribute' is set
to 'registrationForm'.  As I understand it (from the DTD), attribute
is the name of the scoped (session or request) attribute that is used
to access the ActionForm bean.

Now in the action section for saveRegistration 'name' is set
to 'registrationForm'.  'name' is the name of the form bean that is
associated with this mapping.

What is the difference between 'attribute' and 'name'?
It seems that they are the same thing.  Is this true?

Looking at the source for the edit and save registration actions,
they both call mapping.getAttribute() to get the name of the
ActionForm bean.  Why does that work for the saveRegistration
action when it doesn't even have an 'attribute' defined for its
action?

Why doesn't saveRegistration use 'attribute' instead of 'name'?

Thanks,
Kevin.


__
Do you Yahoo!?
New DSL Internet Access from SBC  Yahoo!
http://sbc.yahoo.com

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: MVC and Struts

2002-09-20 Thread Kevin HaleBoyes

Jin, thank you very much for your help.
A question based on something you said...

 Your Xform would do basic validation
 ie format/type checking. The business validation of
 the values would be done in Xmaintainence.

I've actually not implemented the validate() method of the
(struts) form (XForm).  In some cases the format and type of
a field requires knowledge of the business logic.  All of the
fields in XForm are strings but do represent other data types.
There is a date field for example.  Should XForm really know
that the takenOn field is a date?  Should XForm really know
that the takenOn field is required?  I'm not so sure that XForm
should know anything like that.  Maybe it should but what if we
consider a different, more complex, field.  Maybe my XForm needs
to collect a WidgetId field as input.  WidgetIds are very specific
to my business and the format and type of them probably differs
from your WidgetIds.  If I have XForm check the format or type of
the incoming WidgetId then my view component knows a little too
much about my model.

Again, thanks for your help.
Kevin.

__
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




MVC and Struts

2002-09-19 Thread Kevin HaleBoyes

I have a struts application modelled after the struts-example.
It has
   XForm.java as the form bean,
   x.jsp to display the form, and
   EditXAction.java and SaveXAction.java to process the actions.

Edit and Save actions need to use an XMaintainance class as it
provides the knowledge of the business logic.

In SaveXAction I've checked to make sure the request wasn't cancelled
and checked the transaction token (normal struts stuff).  I need to
do additional validations when an XForm is being created so I've
added a validate() method to XMaintainance.

So the SaveXAction code does something like the following:

ActionErrors errors = new ActionErrors();
XForm xf = (XForm)form;
XMaintainance xm = new XMaintainance();
if ( ! xm.validate(xf) ) {
errors.add(error, new ActionError(Xerrors));
}

and later check to see if there have been any errors, and if so,
saveErrors() and saveToken() are called and we forward back to the
mapping.getInput().

That works great!

My question is:

XForm is considered to be a View component.
SaveXAction is considered to be a Controller component.
XMaintainance is a Model component.

By passing the XForm to XMaintainance haven't I mingled the two
components when there was no need?  Mingled is the wrong word.

Instead,
SaveXAction could mediate the interaction between the view and
the model by copying values from the view into the controller:

xm.setXFormField1( xf.getField1() );
...
if ( ! xm.validate() ) {
errors.add(error, new ActionError(Xerrors));
}


Performance wise it would be wasteful to copy the values from
XForm to XMaintainance.  But isn't one of the goal of MVC to
separate the Model from the View by way of the Controller?

Where do we make the split between the three components?  

For instance,
how do report errors from XMaintainance?  I could change the
code above to be:

ActionErrors errors = new ActionErrors();
XForm xf = (XForm)form;
XMaintainance xm = new XMaintainance();
if ( ! xm.validate(xf, errors) ) {
errors.add(error, new ActionError(Xerrors));
}

But now I've mingled a core Controller element (ActionError) to
the Business logic layer.  If I don't do this though, I'll have to
use something similar to ActionErrors that XMaintainance knows about.
SaveXAction would have to copy these errors to the Struts
ActionErrors.  It seems like a lot of copying is being done in order
to separate the components.

Does any of this make any sense?  I guess I'm looking for advice,
on how to split the three MVC components and pass information
between the layers.

Thanks,
K.




__
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]