You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bhaarat Sharma <bh...@gmail.com> on 2009/04/21 19:14:46 UTC

retrieving action name in ActionClass

I have a JSP page that is very commonly used all throughout the application
(with minor tweaks).

here is the snippet form struts.xml for it:

 <action name="ReportSelectionAction"
class="com.generate.web.action.reports.ReportSelection">
    <result>/reports/IncomeReportselection_struts2.jsp</result>
    <result name="failure">login.jsp</result>
   </action>

The action class ReportSelection has bunch of getters/setters and logic in
it.  The jsp that it goes to is IncomeReportselection_struts2.jsp.  The JSP
has some labels that are specific to 'IncomeReport' If I want to make this
jsp general, I want to change to labels to something more specific to where
the action came from.

is there a way to retrieve the action name in the action class?? like in the
above example, is there a way to retrieve action name
"ReportSelectionAction" in the "ReportSelection" class?

Why I want to do that is that way I can set labels in the action class.
something like

If (actionName.equals("ReportSelectionAction"))
    setLabel1("Income Report");
else if (actionName.equals("SomeOtherReportSelectionAction"))
    setLabel1("Some Other Report Selection");

Then my struts.xml will have this.
 <action name="ReportSelectionAction"
class="com.generate.web.action.reports.ReportSelection">
    <result>/reports/IncomeReportselection_struts2.jsp</result>
    <result name="failure">login.jsp</result>
   </action>

 <action name="SomeOtherReportSelectionAction"
class="com.generate.web.action.reports.ReportSelection">
    <result>/reports/IncomeReportselection_struts2.jsp</result>
    <result name="failure">login.jsp</result>
   </action>

and in JSP IncomeReportSelection.jsp I can do <s:property value="label1"/>

Is this a good approach or is there a better way to achieve this?

Thanks

Re: retrieving action name in ActionClass

Posted by Chris Pratt <th...@gmail.com>.
But if all you want to do is be able to set a couple of labels from the
configuration.  You could also do something like:

<action name="ReportSelectionAction"
class="com.generate.web.action.reports.ReportSelection">
  <param name="label1">This is Label 1</param>
  <param name="labal2">This is Label Two</param>
  <result>/reports/IncomeReportselection_struts2.jsp</result>
  <result name="failure">login.jsp</result>
</action>

Then in your action if you have:

public class MyAction {
  private String label1;
  private String label2;

  public String getLabel1() {
    return label1;
  }

  public void setLabel1(String label1) {
    this.label1 = label1;
  }

}

Then all the configuration is in the configuration file and you don't have a
bunch of if/then/else blocks in your execute method.
  (*Chris*)


On Tue, Apr 21, 2009 at 10:51 AM, Bhaarat Sharma <bh...@gmail.com>wrote:

> yeah that will work.
>
> thanks!
>
> On Tue, Apr 21, 2009 at 1:37 PM, Martin Gainty <mg...@hotmail.com>
> wrote:
>
> >
> > ActionContext.getContext().getName()
> >
> >
> http://www.opensymphony.com/webwork/api/com/opensymphony/xwork/ActionContext.html
> >
> > ?
> > 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: Tue, 21 Apr 2009 13:14:46 -0400
> > > Subject: retrieving action name in ActionClass
> > > From: bhaarat.s@gmail.com
> > > To: user@struts.apache.org
> > >
> > > I have a JSP page that is very commonly used all throughout the
> > application
> > > (with minor tweaks).
> > >
> > > here is the snippet form struts.xml for it:
> > >
> > >  <action name="ReportSelectionAction"
> > > class="com.generate.web.action.reports.ReportSelection">
> > >     <result>/reports/IncomeReportselection_struts2.jsp</result>
> > >     <result name="failure">login.jsp</result>
> > >    </action>
> > >
> > > The action class ReportSelection has bunch of getters/setters and logic
> > in
> > > it.  The jsp that it goes to is IncomeReportselection_struts2.jsp.  The
> > JSP
> > > has some labels that are specific to 'IncomeReport' If I want to make
> > this
> > > jsp general, I want to change to labels to something more specific to
> > where
> > > the action came from.
> > >
> > > is there a way to retrieve the action name in the action class?? like
> in
> > the
> > > above example, is there a way to retrieve action name
> > > "ReportSelectionAction" in the "ReportSelection" class?
> > >
> > > Why I want to do that is that way I can set labels in the action class.
> > > something like
> > >
> > > If (actionName.equals("ReportSelectionAction"))
> > >     setLabel1("Income Report");
> > > else if (actionName.equals("SomeOtherReportSelectionAction"))
> > >     setLabel1("Some Other Report Selection");
> > >
> > > Then my struts.xml will have this.
> > >  <action name="ReportSelectionAction"
> > > class="com.generate.web.action.reports.ReportSelection">
> > >     <result>/reports/IncomeReportselection_struts2.jsp</result>
> > >     <result name="failure">login.jsp</result>
> > >    </action>
> > >
> > >  <action name="SomeOtherReportSelectionAction"
> > > class="com.generate.web.action.reports.ReportSelection">
> > >     <result>/reports/IncomeReportselection_struts2.jsp</result>
> > >     <result name="failure">login.jsp</result>
> > >    </action>
> > >
> > > and in JSP IncomeReportSelection.jsp I can do <s:property
> > value="label1"/>
> > >
> > > Is this a good approach or is there a better way to achieve this?
> > >
> > > Thanks
> >
> > _________________________________________________________________
> > Rediscover Hotmail®: Get quick friend updates right in your inbox.
> >
> >
> http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Updates2_042009
> >
>

Re: retrieving action name in ActionClass

Posted by Bhaarat Sharma <bh...@gmail.com>.
yeah that will work.

thanks!

On Tue, Apr 21, 2009 at 1:37 PM, Martin Gainty <mg...@hotmail.com> wrote:

>
> ActionContext.getContext().getName()
>
> http://www.opensymphony.com/webwork/api/com/opensymphony/xwork/ActionContext.html
>
> ?
> 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: Tue, 21 Apr 2009 13:14:46 -0400
> > Subject: retrieving action name in ActionClass
> > From: bhaarat.s@gmail.com
> > To: user@struts.apache.org
> >
> > I have a JSP page that is very commonly used all throughout the
> application
> > (with minor tweaks).
> >
> > here is the snippet form struts.xml for it:
> >
> >  <action name="ReportSelectionAction"
> > class="com.generate.web.action.reports.ReportSelection">
> >     <result>/reports/IncomeReportselection_struts2.jsp</result>
> >     <result name="failure">login.jsp</result>
> >    </action>
> >
> > The action class ReportSelection has bunch of getters/setters and logic
> in
> > it.  The jsp that it goes to is IncomeReportselection_struts2.jsp.  The
> JSP
> > has some labels that are specific to 'IncomeReport' If I want to make
> this
> > jsp general, I want to change to labels to something more specific to
> where
> > the action came from.
> >
> > is there a way to retrieve the action name in the action class?? like in
> the
> > above example, is there a way to retrieve action name
> > "ReportSelectionAction" in the "ReportSelection" class?
> >
> > Why I want to do that is that way I can set labels in the action class.
> > something like
> >
> > If (actionName.equals("ReportSelectionAction"))
> >     setLabel1("Income Report");
> > else if (actionName.equals("SomeOtherReportSelectionAction"))
> >     setLabel1("Some Other Report Selection");
> >
> > Then my struts.xml will have this.
> >  <action name="ReportSelectionAction"
> > class="com.generate.web.action.reports.ReportSelection">
> >     <result>/reports/IncomeReportselection_struts2.jsp</result>
> >     <result name="failure">login.jsp</result>
> >    </action>
> >
> >  <action name="SomeOtherReportSelectionAction"
> > class="com.generate.web.action.reports.ReportSelection">
> >     <result>/reports/IncomeReportselection_struts2.jsp</result>
> >     <result name="failure">login.jsp</result>
> >    </action>
> >
> > and in JSP IncomeReportSelection.jsp I can do <s:property
> value="label1"/>
> >
> > Is this a good approach or is there a better way to achieve this?
> >
> > Thanks
>
> _________________________________________________________________
> Rediscover Hotmail®: Get quick friend updates right in your inbox.
>
> http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Updates2_042009
>

RE: retrieving action name in ActionClass

Posted by Martin Gainty <mg...@hotmail.com>.
ActionContext.getContext().getName()
http://www.opensymphony.com/webwork/api/com/opensymphony/xwork/ActionContext.html

?
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: Tue, 21 Apr 2009 13:14:46 -0400
> Subject: retrieving action name in ActionClass
> From: bhaarat.s@gmail.com
> To: user@struts.apache.org
> 
> I have a JSP page that is very commonly used all throughout the application
> (with minor tweaks).
> 
> here is the snippet form struts.xml for it:
> 
>  <action name="ReportSelectionAction"
> class="com.generate.web.action.reports.ReportSelection">
>     <result>/reports/IncomeReportselection_struts2.jsp</result>
>     <result name="failure">login.jsp</result>
>    </action>
> 
> The action class ReportSelection has bunch of getters/setters and logic in
> it.  The jsp that it goes to is IncomeReportselection_struts2.jsp.  The JSP
> has some labels that are specific to 'IncomeReport' If I want to make this
> jsp general, I want to change to labels to something more specific to where
> the action came from.
> 
> is there a way to retrieve the action name in the action class?? like in the
> above example, is there a way to retrieve action name
> "ReportSelectionAction" in the "ReportSelection" class?
> 
> Why I want to do that is that way I can set labels in the action class.
> something like
> 
> If (actionName.equals("ReportSelectionAction"))
>     setLabel1("Income Report");
> else if (actionName.equals("SomeOtherReportSelectionAction"))
>     setLabel1("Some Other Report Selection");
> 
> Then my struts.xml will have this.
>  <action name="ReportSelectionAction"
> class="com.generate.web.action.reports.ReportSelection">
>     <result>/reports/IncomeReportselection_struts2.jsp</result>
>     <result name="failure">login.jsp</result>
>    </action>
> 
>  <action name="SomeOtherReportSelectionAction"
> class="com.generate.web.action.reports.ReportSelection">
>     <result>/reports/IncomeReportselection_struts2.jsp</result>
>     <result name="failure">login.jsp</result>
>    </action>
> 
> and in JSP IncomeReportSelection.jsp I can do <s:property value="label1"/>
> 
> Is this a good approach or is there a better way to achieve this?
> 
> Thanks

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