You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Baran <ba...@gmail.com> on 2009/04/13 08:42:07 UTC

Struts access static list

Hi Guys,

This is about implementing reusability in the actions. I am struggling to
identify the ways how we can share some comming functionality between
different actions. Lets say I got a list of users i need to use as a
combobox list at multiple pages. Right now I have to push the code in every
action I need that list displayed for. 

any idea if I can use that list at multiple places without repeating the
code. I guess we need to have it static, but not sure how we can use a list
as an static element.

Any help would be great!

Thanks
Baran
-- 
View this message in context: http://www.nabble.com/Struts-access-static-list-tp23018571p23018571.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts access static list

Posted by Baran <ba...@gmail.com>.
Thanks Guys.

Being new to Struts is the only issue I have right now and this is the
reason I am not able to use my own ideas to the fuller. Your suggestions
have helped a lot.

Baran 


newton.dave wrote:
> 
> mitch gorman wrote:
>> Baran wrote:
>>> This is about implementing reusability in the actions. I am struggling
>>> to
>>> identify the ways how we can share some comming functionality between
>>> different actions. Lets say I got a list of users i need to use as a
>>> combobox list at multiple pages. Right now I have to push the code in
>>> every
>>> action I need that list displayed for. 
>>>
>>> any idea if I can use that list at multiple places without repeating the
>>> code. I guess we need to have it static, but not sure how we can use a
>>> list
>>> as an static element
>>
>>        it's a matter of reorganizing your Java classes.  extract all the
>> code that's common to all your user-related classes into a class called
>> UserActionSupport, and then have all those user-related classes extend
>> from UserActionSupport.
> 
> For another option, consider moving that kind of code into service 
> objects. I'm not convinced the implementation of that behavior belongs 
> in the action class unless it's *very* tightly-focused and never used 
> anywhere else.
> 
> There are various mechanisms that allow us to pull common code into our 
> actions without inheritance (think DI/IoC). Using them keeps our action 
> class hierarchy thin and light.
> 
> Putting the code into our actions proper *could* lead to a heavier 
> action hierarchy than necessary, where we'd use only a small portion of 
> the functionality at any given time.
> 
> A combination of the two, where we split the app into areas of 
> functionality, create base classes for each that pull in required 
> services, and add additional services in sub-classes only when we need 
> to, may be the most flexible.
> 
> Dave
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts-access-static-list-tp23018571p23032982.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts access static list

Posted by Dave Newton <ne...@yahoo.com>.
mitch gorman wrote:
> Baran wrote:
>> This is about implementing reusability in the actions. I am struggling to
>> identify the ways how we can share some comming functionality between
>> different actions. Lets say I got a list of users i need to use as a
>> combobox list at multiple pages. Right now I have to push the code in every
>> action I need that list displayed for. 
>>
>> any idea if I can use that list at multiple places without repeating the
>> code. I guess we need to have it static, but not sure how we can use a list
>> as an static element
>
>        it's a matter of reorganizing your Java classes.  extract all the
> code that's common to all your user-related classes into a class called
> UserActionSupport, and then have all those user-related classes extend
> from UserActionSupport.

For another option, consider moving that kind of code into service 
objects. I'm not convinced the implementation of that behavior belongs 
in the action class unless it's *very* tightly-focused and never used 
anywhere else.

There are various mechanisms that allow us to pull common code into our 
actions without inheritance (think DI/IoC). Using them keeps our action 
class hierarchy thin and light.

Putting the code into our actions proper *could* lead to a heavier 
action hierarchy than necessary, where we'd use only a small portion of 
the functionality at any given time.

A combination of the two, where we split the app into areas of 
functionality, create base classes for each that pull in required 
services, and add additional services in sub-classes only when we need 
to, may be the most flexible.

Dave


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


RE: Struts access static list

Posted by Martin Gainty <mg...@hotmail.com>.
I sent this to you already but apparently was lost
you can use the spring plugin to create the necessary entities for you e.g.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:bean="http://www.springframework.org/schema/util"
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
       http://www.springframework.org/schema/util 
       http://www.springframework.org/schema/util/spring-util-2.0.xsd">

  <util:bean id="BaranBean" path="com.baran.BaranBean">
  </util:bean>

</beans>then in your Action class declare the bean, mutator and accessor e.g.
public class BaranAction extends ActionSupport
{
  public com.baran.BaranBean baran_bean;

  public void setBaranBean(BaranBean baran_bean) {
      this.baran_bean = baran_bean;
  }
  public void getBaranBean() {
      return this.baran_bean;
  }
}Did you try this?
Martin 
______________________________________________ 
Disclaimer and Confidentiality/Verzicht und Vertraulichkeitanmerkung / Note de déni et de confidentialité 
This message is confidential. If you should not be the intended receiver, then we ask politely to report. Each unauthorized forwarding or manufacturing of a copy is inadmissible. This message serves only for the exchange of information and has no legal binding effect. Due to the easy manipulation of emails we cannot take responsibility over the the contents.
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.






> Date: Mon, 13 Apr 2009 09:00:32 -0400
> From: mgorman@shadowtv.com
> To: user@struts.apache.org
> Subject: Re: Struts access static list
> 
> Baran wrote:
> > Hi Guys,
> >
> > This is about implementing reusability in the actions. I am struggling to
> > identify the ways how we can share some comming functionality between
> > different actions. Lets say I got a list of users i need to use as a
> > combobox list at multiple pages. Right now I have to push the code in every
> > action I need that list displayed for. 
> >
> > any idea if I can use that list at multiple places without repeating the
> > code. I guess we need to have it static, but not sure how we can use a list
> > as an static element
>        it's a matter of reorganizing your Java classes.  extract all the
> code that's common to all your user-related classes into a class called
> UserActionSupport, and then have all those user-related classes extend
> from UserActionSupport.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

_________________________________________________________________
Rediscover Hotmail®: Get quick friend updates right in your inbox. 
http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Updates1_042009

Re: Struts access static list

Posted by mitch gorman <mg...@shadowtv.com>.
Baran wrote:
> Hi Guys,
>
> This is about implementing reusability in the actions. I am struggling to
> identify the ways how we can share some comming functionality between
> different actions. Lets say I got a list of users i need to use as a
> combobox list at multiple pages. Right now I have to push the code in every
> action I need that list displayed for. 
>
> any idea if I can use that list at multiple places without repeating the
> code. I guess we need to have it static, but not sure how we can use a list
> as an static element
       it's a matter of reorganizing your Java classes.  extract all the
code that's common to all your user-related classes into a class called
UserActionSupport, and then have all those user-related classes extend
from UserActionSupport.


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


Re: Struts access static list

Posted by Baran <ba...@gmail.com>.
Hello Chris,

well this is what I was doing yesterday, I have this naive issue
here...mainly because of the fact that I am new to it. If we have an action
that does the the job for us. I use s:action with actionResult="false" for
no html rendering, is there a way if I can use the output as an input for a
combobox. I mean call the action class and fetch the output and push it in a
combobox or something. 

I know this is something I should not be asking at this level but being new
justify my query :)

Thanks

musomesa wrote:
> 
> Why not write the code in its own action or pojo and use <s:action> or 
> <s:bean> wherever you want it?
> Chris M
> **************The Average US Credit Score is 692. See Yours in Just 2 Easy 
> Steps! 
> (http://pr.atwola.com/promoclk/100126575x1221621489x1201450100/aol?redir=http:%2F%2Fwww.freecreditreport.com%2Fpm%2Fdefault.aspx%3Fsc%3D668072%26h
> mpgID%3D62%26bcd%3DAprilAvgfooterNO62)
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts-access-static-list-tp23018571p23033129.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts access static list

Posted by Baran <ba...@gmail.com>.
Thanks Chris,

It helped a lot in sorting things out. Also thanks to Dave for tossing up
"SDO", it sounds interesting and I would certainly consider using it at some
place.  

Thanks

musomesa wrote:
> 
> Yes, in between the <s:action> or <s:bean> tags the object is sitting on 
> top of the value stack so you can access it with OGNL like you would a 
> 'normal' action. Handy for things like populating combo boxes which crop
> up all 
> over the place.
> Chris M
>  
>  
> **************The Average US Credit Score is 692. See Yours in Just 2 Easy 
> Steps! 
> (http://pr.atwola.com/promoclk/100126575x1221421325x1201417411/aol?redir=http:%2F%2Fwww.freecreditreport.com%2Fpm%2Fdefault.aspx%3Fsc%3D668072%26h
> mpgID%3D62%26bcd%3DAprilAvgfooterNO62)
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts-access-static-list-tp23018571p23033840.html
Sent from the Struts - User mailing list archive at Nabble.com.


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