You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Menke, John" <Jo...@acs-inc.com> on 2004/02/03 15:35:52 UTC

static variables in actions

if I have a collection of state names and I don't want to have to retrieve
it over and over again can i
do something like this in my action?


static Collection _collection;

if (collection == null ){
   _collection = getCollectionFromDB();
}

form.setCollection = _collection









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


RE: static variables in actions

Posted by Nicolás de Amorrortu <na...@interbanking.com.ar>.
You can also try the Providers Framework that we have posted to the
sourceforge (http://providers.sourceforge.net).
It was developed to solve the problem that you described. With this
framework you define your collections on a XML file, and then you can
use it through select tag (of struts) using de "optionsTag" provided
with the framework.
The collections could be defined to be retrieved from DataSource or
Fixed Collections.
The DataSource definition is something like ...
 	<provider name="cities" 
		className="ar.com.koalas.providers.JDBCProvider">
		<set-property property="jndi" value="MySqlDS"/>
		<set-property property="keyName" value="code"/>
		<set-property property="description"
value="description"/>
		<param>
			<param-name>query</param-name>
			<param-value>select * from cities</param-value>
		</param>
	</provider>

Then in your JSP you use this collection (named 'cities') like this
<select name="selTest">
	<prv:options provider="cities"/>
</select>

Cheers,
Nicolás


-----Original Message-----
From: Robert Taylor [mailto:rtaylor@mulework.com] 
Sent: Martes, 03 de Febrero de 2004 11:40 a.m.
To: Struts Users Mailing List
Subject: RE: static variables in actions


John, why not retrieve these from the DB at application start up time
and place them in the ServletContext where they are accessible for the
life time of the application and easily rendered by JSTL or Struts tags.

robert

> -----Original Message-----
> From: Menke, John [mailto:John.Menke@acs-inc.com]
> Sent: Tuesday, February 03, 2004 9:36 AM
> To: Struts (E-mail)
> Subject: static variables in actions
>
>
> if I have a collection of state names and I don't want to have to 
> retrieve it over and over again can i do something like this in my 
> action?
>
>
> static Collection _collection;
>
> if (collection == null ){
>    _collection = getCollectionFromDB();
> }
>
> form.setCollection = _collection
>
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


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

NOTA DE CONFIDENCIALIDAD
Este mensaje (y sus anexos) es confidencial, esta dirigido exclusivamente a las personas direccionadas en el mail y puede contener informacion (i)de propiedad exclusiva de Interbanking S.A. o (ii) amparada por el secreto profesional. Cualquier opinion en el contenido, es exclusiva de su autor y no representa necesariamente la opinion de Interbanking S.A. El acceso no autorizado, uso, reproduccion, o divulgacion esta prohibido. Interbanking S.A no asumira responsabilidad ni obligacion legal alguna por cualquier informacion incorrecta o alterada contenida en este mensaje. Si usted ha recibido este mensaje por error, le rogamos tenga la amabilidad de destruirlo inmediatamente junto con todas las copias del mismo, notificando al remitente. No debera utilizar, revelar, distribuir, imprimir o copiar este mensaje ni ninguna de sus partes si usted no es el destinatario. Muchas gracias.



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


RE: static variables in actions

Posted by Robert Taylor <rt...@mulework.com>.
John, why not retrieve these from the DB at application start up time
and place them in the ServletContext where they are accessible for
the life time of the application and easily rendered by JSTL or Struts
tags.

robert

> -----Original Message-----
> From: Menke, John [mailto:John.Menke@acs-inc.com]
> Sent: Tuesday, February 03, 2004 9:36 AM
> To: Struts (E-mail)
> Subject: static variables in actions
>
>
> if I have a collection of state names and I don't want to have to retrieve
> it over and over again can i
> do something like this in my action?
>
>
> static Collection _collection;
>
> if (collection == null ){
>    _collection = getCollectionFromDB();
> }
>
> form.setCollection = _collection
>
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


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