struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lirian Ostrovica" <lirian.ostrov...@senecac.on.ca>
Subject Re: How to get a reference to an Action instance
Date Thu, 02 Jan 2003 03:12:01 GMT
Hi,

In a few words, what I'm writing is a Struts version of my own Form 
Validation Framework.

My validation framework provides it's own Action, ActionForm and form 
taglibs.
Form taglibs are a seamless extension of Struts ones, because the tags 
preserve exactly the same naming and attributes.

I am facing the problem while writing my own extension of 
org.apache.struts.taglib.html.FormTag, when it comes to considering the 
following scenario:

1- the client is asking for the form by directly typing the path to the 
form presentation jsp, and not through the respective Action.
In this case, it is the duty of the FormTag to get the ActinForm, put 
it in the designated scope, and perform whatever else needed before 
presenting the form.

2- The form going to be presented, has one or more fields with initial 
values, but the initial values are 'DYNAMIC' in the meaning that they 
might be different from client to client, they might depend on overall 
system's state, and so on.

My framework's Action class provides the following method for the 
framework users to implement (if they need to):

  public String getDynamicInitialValue(String fieldName,
                                       HttpServletRequest request) {

	return null;
  }

There is also another method for multiple value fields, but the idea is 
the same.

So, in order to prepare fields for display, my FormTag needs to have a 
reference to the respective Action simply for the sake of calling this 
method.

By the way, I do not know how Struts itself handles the dynamic initial 
values?

This is the whole story, and I hope it is clear, my New Years Eve drink 
permitting -:).

Thanks to you guys for the previous answers, and I'm looking forward to 
any further opinion.

Lirian




----- Original Message -----
From: Kris Schneider <kris@dotech.com>
Date: Monday, December 30, 2002 8:57 am
Subject: Re: How to get a reference to an Action instance

> As others have said, it's unclear exactly what it is you need to 
> do, but here's
> a general suggestion for having a tag handler and action play 
> nicely together -
> use scoped attributes. In other words, if your tag handler needs some
> information from your action, have the action place the 
> information in a request
> (or session or application) attribute that the handler can access 
> through its
> current PageContext. Of course, this implies that the action 
> operates on the
> request before the JSP...
> 
> Quoting Martin Cooper <martinc@apache.org>:
> 
> > On Sun, 29 Dec 2002, Lirian Ostrovica wrote:
> > 
> > > Hi,
> > >
> > > I need to access an Action instance (I have its class name) while
> > > writting a Tag.
> > >
> > > I have seen that ActionServlet stores Action instances in a 
> 'protected'> > variable (FastHashMap), and so far the only way I 
> can see, is to extend
> > > ActionServlet and write my own 'public' method to do the job.
> > > But of course I do not prefer to extend ActionServlet just for 
> that...> 
> > Even if you know the class name, there is no guarantee that an 
> instance of
> > that Action exists, since Action instances are created as 
> needed. And even
> > if an instance does exist, what would be the purpose of 
> accessing it? An
> > Action instance should not maintain state, since that will cause 
> threading> problems, and if you need to access class data, then 
> you do not need an
> > instance.
> > 
> > Perhaps if you tell us what you are trying to achieve, we can 
> help you
> > find the right way to do that.
> > 
> > --
> > Martin Cooper
> > 
> > 
> > >
> > > If there is any other way, can someone please let me know
> > >
> > > thanks a lot
> > >
> > > lirian
> > >
> > >
> > > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:  
> > <mailto:struts-user-unsubscribe@jakarta.apache.org>
> > > For additional commands, e-mail:
> > <mailto:struts-user-help@jakarta.apache.org>
> > >
> > >
> > 
> > 
> > --
> > To unsubscribe, e-mail:  
> > <mailto:struts-user-unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail:
> > <mailto:struts-user-help@jakarta.apache.org>
> 
> -- 
> Kris Schneider <mailto:kris@dotech.com>
> D.O.Tech       <" target="l">http://www.dotech.com/>
> 
> --
> To unsubscribe, e-mail:   <mailto:struts-user-
> unsubscribe@jakarta.apache.org>For additional commands, e-mail: 
> <mailto:struts-user-help@jakarta.apache.org>
> 
> 


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


Mime
View raw message