You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Stas Ostapenko <st...@gmail.com> on 2005/09/16 18:12:31 UTC
How to use simple servlet as a view with Struts ?
Hi !
I'm trying to resolve how to use servlet as a view with Struts. It's
very diffcult to find how to do it. I have asked at struts user
mailing list but nobody answered.
How to get ActionMessages and form bean objects when simple sevlet is
used as a view ? How to get particular error message string for global message ?
Plese help.
Regards, Stas.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org
Re: How to use simple servlet as a view with Struts ?
Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
On Fri, September 16, 2005 12:41 pm, Joe Germuska said:
> One common use case for this is using the VelocityServlet. If one
> doesn't use JSPs, odds are at least decent that your alternative view
> technology is packaged as some kind of servlet. This may also come
> up once StandAlone Tiles is set up, in that a separate servlet will
> process the view, although Standalone Tiles with JSP would still be
> able to use the standard Struts taglibs.
Fair point. Never having used Velocity I have no frame of reference with
regard to it.
What I should probably have said originally is something more like:
"If your looking to write your own servlet as your view technology, I
would first ask if there doesn't already exist something to do what you
need".
That's closer to what I actually meant :) It's not that having a servlet
as the view technology is neccessarily not good or right or anything like
that, just that if your going to write that piece yourself, before I went
through the effort I'd see if what's out there already did the trick.
> If you're using some other view technology, this is a wheel you'd
> have to re-invent. Well, maybe the STXX project did something
> similar for people who use XSLT and XML for views? Just curious,
> what is your view technology?
JSP for me, which of course means servlets in the end :)
FYI, I have done an XSLT transformation engine as the view technology, but
even there I did it with JSP, i.e., XML returned from an Action, always
forwarding to a single JSP that performs the transformation... and yes,
you can slap me, it *was* a big scriplet chunk! (well, ~200 lines as I
recall, not sure that should be considered "big"). For me, as this
demonstrates, even if I'm going to implement an alternate view technology
myself, I'd *still* consider doing it from a JSP. I suppose I have no
logical reason though, other than it just "feels" right.
Eh, clearly going a bit OT here... I think the OP got his answer either
way :)
> Joe
Frank
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org
Re: How to use simple servlet as a view with Struts ?
Posted by Joe Germuska <Jo...@Germuska.com>.
>I would start by asking *why* you'd want to do this? I'd be willing to
>bet that whatever the requirement is that there are ways to accomplish it
>without resorting to this.
One common use case for this is using the VelocityServlet. If one
doesn't use JSPs, odds are at least decent that your alternative view
technology is packaged as some kind of servlet. This may also come
up once StandAlone Tiles is set up, in that a separate servlet will
process the view, although Standalone Tiles with JSP would still be
able to use the standard Struts taglibs.
Struts/Velocity users have dealt with this by producing a standard
Velocity Tool which provides the bridge between Struts and Velocity
which is otherwise provided by struts-taglibs.
If you're using some other view technology, this is a wheel you'd
have to re-invent. Well, maybe the STXX project did something
similar for people who use XSLT and XML for views? Just curious,
what is your view technology?
Joe
--
Joe Germuska
Joe@Germuska.com
http://blog.germuska.com
"Narrow minds are weapons made for mass destruction" -The Ex
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org
Re: How to use simple servlet as a view with Struts ?
Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
I would start by asking *why* you'd want to do this? I'd be willing to
bet that whatever the requirement is that there are ways to accomplish it
without resorting to this.
That being said, if you really want to go down that path, all the objects
you are looking for are in the request object as attributes. You can get
at them by retrieving the appropriate key, and you can find what the
appropriate key is probably everything you want by looking at the Globals
class. This class has static fields that define the keys under which
various objects can be found.
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
On Fri, September 16, 2005 12:12 pm, Stas Ostapenko said:
> Hi !
> I'm trying to resolve how to use servlet as a view with Struts. It's
> very diffcult to find how to do it. I have asked at struts user
> mailing list but nobody answered.
> How to get ActionMessages and form bean objects when simple sevlet is
> used as a view ? How to get particular error message string for global
> message ?
> Plese help.
>
> Regards, Stas.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org
Re: How to use simple servlet as a view with Struts ?
Posted by Craig McClanahan <cr...@gmail.com>.
On 9/16/05, Stas Ostapenko <st...@gmail.com> wrote:
>
> Hi !
> I'm trying to resolve how to use servlet as a view with Struts. It's
> very diffcult to find how to do it. I have asked at struts user
> mailing list but nobody answered.
Under the covers, Struts is just doing a RequestDispatcher.forward() call
when your Action returns an appropriate ActionForward. Therefore, you need
to ensure that the URL defined in that <forward> element corresponds to a
context relative path that is mapped (in web.xml) to your alternate view
handling servlet. The Velocity integration referenced by Joe does exactly
this.
How to get ActionMessages and form bean objects when simple sevlet is
> used as a view ? How to get particular error message string for global
> message ?
> Plese help.
The answers are different for each of the things you're asking about:
* *IF* you create the form bean ahead of time, it will be passed as a
request or session
scope object with a key equal to the form bean name. If you're using the
standard
view technology, the <html:form> tag will create this bean if it doesn't
exist -- your
alternate view technology will likely need to have that same functionality.
* The ActionMessages instance is passed as a request scope attribute
whose key is defined by the manifest constant Globals.MESSAGE_KEY.
* Localized text for the actual messages is looked up (in the standard view
techology) in the applicaton resource bundle(s), which are defined in your
struts-config.xml. You can see how that's done by looking at the source code
for the <html:errors> tag, and emulate the same behavior.
Regards, Stas.
Craig