You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andreas Leitner <al...@macron.at> on 2001/07/25 10:13:19 UTC

Newbee: design question

Hi,

I am pretty new to tomcat/struts but nevertheless trying to create a
simple application using the two (; I have troubles getting my design
right, maybe some people on this list could give me some hints, they
would be greatly appreciated.

The idea is that I have a DB backend that stores a bunch of documents
identified by an integer. Now the user can click on a link and view the
document (that's the first step). Now the link looks like this:
<html:link page="/viewDocument.do?documentId=33>view doc with id
33</html:link>

Now, what I want to happen when the user clicks this link is:
Run a controller that checks if the documentId is valid, and if so,
retrieve the document from the DB and store it somewhere in the request
scope, then forward to the actual viewer, otherwise forward to an error
page. The forwards will be done using local forward mappings in the
config file, in order to seperate buisness logic from presentation code.

What I don't understand is: Do I have to create a Form class for this
action? The documentId comes as an Parameter in the request scope and
struts won't fill out the Form anyway (cause there is not form). The
example that came with struts did create a form class in this case,
that's why I am confused. My thinking was that I could just simply add a
custom Document class to the request scope, which the actual viewer
would then read.

Another issue: Can I unify access to Forms fields and Parameters? For my
example it would probably not make a lot of sense, but it would be neat
(from a theoretical POV) if it would not matter if the user just clicked
on a link with parameters or he submitted a form. As long as the both
contain the same fields/parameters, struts could always fill out a Form
class. Or am I missing something?

Regards,
Andreas


Re: Newbee: design question

Posted by Martin Cooper <ma...@tumbleweed.com>.
You don't have to create a form bean if you don't want or need to. In your
example, the form bean would only have one property, and that property came
directly from a link (minimizing the risk of invalid values, and hence the
need for validation in the form bean), so you could just use
request.getParameter() instead if you wanted to.

Regarding "unifying" access to form fields and parameters, I'm not sure what
you're getting at. If a form bean is used, Struts will populate it from the
request parameters regardless of how the request was submitted. So long as
the form bean has a property corresponding to each parameter name, the form
will contain all of the request parameter values when your action class is
called.

--
Martin Cooper


----- Original Message -----
From: "Andreas Leitner" <al...@macron.at>
To: <st...@jakarta.apache.org>
Sent: Wednesday, July 25, 2001 1:13 AM
Subject: Newbee: design question


>
> Hi,
>
> I am pretty new to tomcat/struts but nevertheless trying to create a
> simple application using the two (; I have troubles getting my design
> right, maybe some people on this list could give me some hints, they
> would be greatly appreciated.
>
> The idea is that I have a DB backend that stores a bunch of documents
> identified by an integer. Now the user can click on a link and view the
> document (that's the first step). Now the link looks like this:
> <html:link page="/viewDocument.do?documentId=33>view doc with id
> 33</html:link>
>
> Now, what I want to happen when the user clicks this link is:
> Run a controller that checks if the documentId is valid, and if so,
> retrieve the document from the DB and store it somewhere in the request
> scope, then forward to the actual viewer, otherwise forward to an error
> page. The forwards will be done using local forward mappings in the
> config file, in order to seperate buisness logic from presentation code.
>
> What I don't understand is: Do I have to create a Form class for this
> action? The documentId comes as an Parameter in the request scope and
> struts won't fill out the Form anyway (cause there is not form). The
> example that came with struts did create a form class in this case,
> that's why I am confused. My thinking was that I could just simply add a
> custom Document class to the request scope, which the actual viewer
> would then read.
>
> Another issue: Can I unify access to Forms fields and Parameters? For my
> example it would probably not make a lot of sense, but it would be neat
> (from a theoretical POV) if it would not matter if the user just clicked
> on a link with parameters or he submitted a form. As long as the both
> contain the same fields/parameters, struts could always fill out a Form
> class. Or am I missing something?
>
> Regards,
> Andreas
>
>