Java Mailing List Archive

http://www.gg3721.com/

Home » Struts Users Mailing List »

user Digest 30 Jan 2010 23:14:41 -0000 Issue 8997

user-digest-help

2010-01-30


Author LoginPost Reply

user Digest 30 Jan 2010 23:14:41 -0000 Issue 8997

Topics (messages 204895 through 204904):

Re: redirectAction not working
 204895 by: Pawe³ Wielgus

Re: Modifying action mapping per device type
 204896 by: Marcus Bond
 204899 by: Marcus Bond

Re: Boolean Type Conversion
 204897 by: Roger

Re: Different results with spring
 204898 by: Miguel

interceptor is not being called for all action
 204900 by: Jake Vang
 204901 by: Dave Newton
 204902 by: Jake Vang
 204903 by: Jake Vang
 204904 by: Jake Vang

Administrivia:

---------------------------------------------------------------------
To post to the list, e-mail: user@(protected)
To unsubscribe, e-mail: user-digest-unsubscribe@(protected)
For additional commands, e-mail: user-digest-help@(protected)

----------------------------------------------------------------------


Attachment: user_204895.ezm (zipped)
Hi Rob,
you might try ConfigBrowserPlugin,
see why here:
http://poulwiel.blogspot.com/2009/09/config-browser-plugin-in-struts2.html

Best greetings,
Paweł Wielgus.


2010/1/30 Robby Atchison <rob_26@(protected)>:
> Hello,
>
>
>
> I have the following configuration in a Struts.xml file.  The
> paramsPrepareParamsStack is the default interceptor stack.  AccountAction
> does not implement any interfaces.  Both BankcardAction and ECheckAction
> implement Preparable and ModelDriven.
>
>
>
>                <action name="account"
> class="com.epa.actions.AccountAction">
>
>            <result name="bankcard_browse"      type="redirectAction">
>
>                  <param name="action">bankcard_browse</param>
>
>            </result>
>
>            <result name="echeck_browse" type="redirectAction">
>
>                  <param name="action">echeck_browse</param>
>
>            </result>
>
>      </action>
>
>
>
>      <action name="bankcard_*" method="{1}"
> class="com.epa.actions.BankcardAction" >
>
>            <result name="success">bankcarddetail.tile</result>
>
>            <result name="input">bankcarddetail.tile</result>
>
>      </action>
>
>
>
>      <action name="echeck_*" method="{1}"
> class="com.epa.actions.ECheckAction" >
>
>            <result name="success">echeckdetail.tile</result>
>
>            <result name="input">echeckdetail.tile</result>
>
>      </action>
>
>
>
> Below is the execute method from AccountAction class..
>
>
>
>                public String execute() {
>
>            String actionName = "bankcard_browse";
>
>            if (StringUtils.equalsIgnoreCase(recordType, "EC")) {
>
>                  actionName = "echeck_browse";
>
>            }
>
>            return actionName;
>
>      }
>
>
>
> In my testing I get the error - No result defined for action
> com.epa.actions.AccountAction and result bankcard_browse. I can navigate
> straight to bankcard_browse (not going through AccountAction) without
> incident.  If I try to go to AccountAction first and redirect to
> bankcard_browse or echeck_browse I get the error. What am I doing wrong?
> I'm using Struts 2 version 2.1.8.1., Tiles 2.0.6, OGNL 2.7.3.    I hope I've
> included enough information.  Any help will be greatly appreciated as I've
> been struggling with this problem for too long.
>
>
>
> Best regards,
>
> Rob
>
> Rob_26@(protected)
>
>


Attachment: user_204896.ezm (zipped)
Hi Wes, thanks for the post.

I like the idea of being able to decorate screens differently depending
on device without changing much existing code and I can see a use to
this for example for pages being given a different footer to provide
device specific links or adding side menus for devices with enough
screen space. (The main focus of my web pages are application GUI rather
than content). I do intend to look into sitemesh but I know nothing
about it as yet. However, what sitemesh (I don't think anyway) cannot do
is for example, for an old blackberry that does not support html tables
very well, allow me to render a list of results in a business card style
layout instead of a four column table - if it can then I'd be glad to
know how and investigate it's use further as it would solve some of the
problems I encounter.


Wes Wannemacher wrote:
> I admit that I haven't read the whole thread, so flame me if you
> covered the answer already, but...
>
> Have you looked at Sitemesh? I would suggest look at creating
> different decorators for each of the devices you want to support, then
> code your undecorated JSPs so that they can be decorated based on the
> device accessing it. Sitemesh has a ton of different ways you can pick
> the decorator, so I would imagine you'd be able to find a way to
> abstract the decorator picking logic outside of your business logic.
> Then, the advantage of the decorator pattern is that you can code your
> UI screens and business logic once and just have the screens decorated
> differently based on the abstracted decorator picking logic. (As a
> bonus, you can add new decorators for new devices without changing
> much)
>
> -Wes
>
>  



Attachment: user_204899.ezm (zipped)
Hi,

I am wanting to implement a site such that some actions may have a
different mapping depending upon the device used (e.g. regular browser /
mobile device etc.) but what I don't want to do is have to litter my
actions with this type of logic. It could be at the result mapping level
(i.e. in struts.xml) such that say a result of success would map to a
jsp of somePage.jsp for regular browsers and somePageMobile.jsp for a
mobile device (there will be more complications to this as I'd like to
be able to have fine grained control based on the user agent so there
may be many versions of a jsp such as somePageWinMobile6_5_htc.jsp).

There are couple of ways I can think of to do this, but they're ugly:
- JSP level logic to render the page differently - dont want it, I'd
rather individual jsp's for each supported device (or family) as this
allows developers who are working on targeting a site to a specific
device to concentrate on that device.
- Tiles template level logic - again not ideal as I would like to be
able to use specific templates for device types.

Better but not perfect would be some sort of post action result
modifying interceptor such that in the struts.xml I could define a
number of different result mappings such as success, success_winmob,
success_blackberry_storm and have the result string that has been
returned from the action (success) modified by some sort of interceptor
(e.g. appending the suffix prior to struts mapping it off to a view) -
the filter itself could be configured as to whether or not to alter
result strings based on the action and the user device. - Is it possible
to modify the result string post action but prior to struts resolving
the mapping? And if so would I have access to the the name of the action?

Any suggestions here are greatly appreciated!
Web technologies being used are Struts2, Tiles2 and JSP.

Regards,
Marcus


Attachment: user_204897.ezm (zipped)
On Friday 29 January 2010 22:30:34 Wes Wannemacher wrote:
> I don't know if I'd go too far creating a TypeConverter... Can you
> just do something like this -
>
> <s:if test="%{your.boolean.property}">Y</s:if><s:else>N</s:else>
>
> Really, you could probably create a .tag file out of it and reuse it
> easier than creating a Type Converter.
>
> -Wes
>
I can see that working to display, but when the user switches a field from "Y"
to "N" how do I get "false" automagically returned in the relevant list entry?


Attachment: user_204898.ezm (zipped)
On Fri, Jan 29, 2010 at 19:09, Miguel <miguelrvs@(protected):
> Hi,
> Thanks for answering!!
> I'll post my relevant configurations. I'm using spring 2.5.6 and struts 2.1.8.1.
> I have the spring plugin in the struts.conf, and my actions are
> correctly autowired by name.
> I also have an include in struts.conf where the relevant action is called.
> The thing here is I have two beans of the same type but configured to
> access different hibernate entity-names (a DAO), and in the part that
> misbehaves, i need to access the second one that has a different name,
> but is of the same type.
> When I make spring instanciate the action, the prepare() method in the
> action is called correctly, and it uses the autowired DAO, it gets the
> desired data but the details() method is not called and the result is
> automatically redirected to INPUT result.
> When I make struts (using the spring factory( instanciate the action,
> the prepare() method in the action is called correctly, and it uses
> the autowired DAO, it gets the desired data, the details() method is
> called and the result is shown correctlly.
>  Curiosly the browse method is correctly called en each config.
> The thing here is I have replicated some part of the system, and I
> have identical class names in different packages (the code in the
> classes is not the same), and those classes are called from different
> urls in struts.conf. The action has no validators but it's twin class
> in a different package does.
>
> struts.conf:
>        <constant name="struts.devMode" value="true" />
>        <constant name="struts.objectFactory"
> value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
>        <constant name="struts.freemarker.templatesCache" value="true" />
>
>    <package name="proyectox" extends="json-default" ><!-- struts-default -->
> <!-- Si no le pones este stack, pues no funciona...-->
>        <interceptors>
>                <interceptor name="strutsSpring"
> class="com.proyectox.ui.interceptor.HibernateOpenSessionInViewInterceptor"/>
>                <interceptor-stack name="strutsSpringPPPStack">
>                        <interceptor-ref name="strutsSpring"/>
>                        <interceptor-ref name="paramsPrepareParamsStack"/>
>                </interceptor-stack>
>        </interceptors>
>        <include file="com/fcm/sectorPrimario2009/sectorPrimario.struts.xml"/>
> ....
>
>
> com/fcm/sectorPrimario2009/sectorPrimario.struts.xml:
> <package name="receptorsectorprimario" extends="proyectox"
> namespace="/sectorprimario/receptor">
>
>                <action name="lista" method="browse"
> class="com.fcm.sectorPrimario2009.ui.ReceptorAction">
>                        <result>listaReceptor.jsp</result>
>                        <result name="error">listaReceptor.jsp</result>
>                        <interceptor-ref name="scope">
>                            <param name="session">contribuyente</param>
>                            <param name="autoCreateSession">true</param>
>                            <param name="key">contribuyenteActual</param>
>                        </interceptor-ref>
>                        <interceptor-ref name="strutsSpringPPPStack"/>
>                </action>
>
>                <action name="receptor_*" method="{1}"
> class="com.fcm.sectorPrimario2009.ui.ReceptorAction">
>                        <result>receptorDetail.jsp</result>
>                        <result name="detail">receptorDetail.jsp</result>
>                        <result name="input">receptorNuevo.jsp</result>
>                        <result name="modificar">receptorNuevo.jsp</result>
>                        <result name="borrar" type="redirectAction">
>                                <param name="actionName">lista</param>
>                        </result>
>                        <result name="error">/error.jsp</result>
>                        <interceptor-ref name="scope">
>                            <param name="session">contribuyente</param>
>                            <param name="autoCreateSession">true</param>
>                            <param name="key">contribuyenteActual</param>
>                        </interceptor-ref>
>                        <interceptor-ref name="scope">
>                            <param name="session">receptor</param>
>                            <param name="autoCreateSession">true</param>
>                            <param name="key">receptorActualSP</param>
>                        </interceptor-ref>
>            <interceptor-ref name="strutsSpringPPPStack"/>
>                </action>
> ...
>
>
> sectorPrimario.spring.xml:
>
> <beans xmlns="http://www.springframework.org/schema/beans"
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:jee="http://www.springframework.org/schema/jee"
>        xmlns:sec="http://www.springframework.org/schema/security"
> xmlns:tx="http://www.springframework.org/schema/tx"
>        xmlns:aop="http://www.springframework.org/schema/aop"
>        xsi:schemaLocation="http://www.springframework.org/schema/beans
>        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>        http://www.springframework.org/schema/jee
>        http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
>        http://www.springframework.org/schema/security
>        http://www.springframework.org/schema/security/spring-security-2.0.xsd
>        http://www.springframework.org/schema/tx
>    http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
>    http://www.springframework.org/schema/aop
>    http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
>        "
>        default-autowire="autodetect">
>
>        <bean id="receptorDAOSectorPrimario"
> class="com.fcm.sectorPrimario2009.dao.ReceptorDAOImpl">
>                <property name="sessionFactory" ref="sessionFactory" />
>                <property name="entityName" value="SP_Receptor"/>
>        </bean>
>
>
>        <bean id="cfdDAOSectorPrimario" class="com.proyectox.DAO.CfdDAOImpl">
>                <property name="sessionFactory" ref="sessionFactory" />
>                <property name="relName" value="SP_FACTURA"/>
>                <property name="toXML" ref="toXML" />
>                <property name="contribuyenteDAO" ref="contribuyenteDAO" />
>                <property name="impuestosDAO" ref="impuestosDAO" />
>                <property name="repository">
>                        <bean class="com.fcm.repository.Nom151RepositoryAdaptor">
>                                <property name="repository" ref="nom151Repository"/>
>                        </bean>
>                </property>
>        </bean>
>
>        <bean id="receptorSPAction"
> class="com.fcm.sectorPrimario2009.ui.ReceptorAction"
> scope="prototype">
>                <property name="receptorDAO"><ref
> local="receptorDAOSectorPrimario"/></property>
>        </bean>
>
>
> ReceptorAction.java
>
> public class ReceptorAction extends ActionSupport implements Preparable {
>        private static final long serialVersionUID = 4361713845701104303L;
> ...
>        public void prepare() throws Exception {
> //              msg = pais+" Pais: "+pais.getNombre()+" idobt: "+id;
>                if ((receptor == null && id != null) || (receptor != null && id !=
> null && receptor.getId() != id)){
>
>                        receptor = (ReceptorPrimario)receptorDAO.find(id);
>                }
>                else if (receptor == null && id == null){
>                        receptor = new ReceptorPrimario();
>                }
>
>        @(protected)
>        public String browse(){
> //              receptores = receptorDAO.findAll();
>                receptores = receptorDAO.findByContribuyente(contribuyente);
>                if (receptores == null ){
>                        msg ="Algo funciono mal";
>                        return ERROR;
>                        }
>                if(receptores.size() ==0){
>                        msg="No hay receptores";
>                        return SUCCESS;
>                }
>                return SUCCESS;
>        }
>
>        @(protected)
>        public String detail(){
>                if (receptor == null)
>                        return ERROR;
> //              msg = id.toString();
> //              msg = "detail de persona fisica "+receptor;
>                return "detail";
>        }
> ...
> }
>
>
> web.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns="http://java.sun.com/xml/ns/javaee"
> xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
> version="2.5">
>
>  <welcome-file-list>
>    <welcome-file>index.html</welcome-file>
>    <welcome-file>index.htm</welcome-file>
>    <welcome-file>index.jsp</welcome-file>
>    <welcome-file>default.html</welcome-file>
>    <welcome-file>default.htm</welcome-file>
>    <welcome-file>default.jsp</welcome-file>
>  </welcome-file-list>
>
>        <display-name>ProyectoX app</display-name>
>        <resource-ref>
>                <res-ref-name>jdbc/DB</res-ref-name>
>                <res-type>javax.sql.DataSource</res-type>
>                <res-auth>Container</res-auth>
>        </resource-ref>
>
>        <resource-ref>
>                <description>
>                        Resource reference to a factory for javax.mail.Session
>                        instances that may be used for sending electronic mail
>                        messages, preconfigured to connect to the appropriate SMTP
>                        server.
>                </description>
>                <res-ref-name>mail/Session</res-ref-name>
>                <res-type>javax.mail.Session</res-type>
>                <res-auth>Container</res-auth>
>        </resource-ref>
>
>        <context-param>
>                <param-name>contextConfigLocation</param-name>
>                <param-value>
>                        classpath:spring.cfg.xml
>                </param-value>
>        </context-param>
>    <context-param>
>        <param-name>log4jConfigLocation</param-name>
>        <param-value>/WEB-INF/classes/log4j.xml</param-value>
>    </context-param>
>
>    <filter>
>        <filter-name>springSecurityFilterChain</filter-name>
>        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
>    </filter>
>
>    <filter-mapping>
>      <filter-name>springSecurityFilterChain</filter-name>
>      <url-pattern>/*</url-pattern>
>    </filter-mapping>
>        <listener>
>                <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
>        </listener>
>    <listener>
>      <listener-class>org.springframework.security.ui.session.HttpSessionEventPublisher</listener-class>
>    </listener>
>        <filter>
>                <filter-name>struts2</filter-name>
>                <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
>        </filter>
>
>        <filter-mapping>
>                <filter-name>struts2</filter-name>
>                <url-pattern>/*</url-pattern>
>        </filter-mapping>
> </web-app>
>
> In past projects I have made the same trick of making spring
> instanciate actions, and this is the first time I have this behavior.
> In the other project, I use the same spring version, but struts 2.1.6,
> and the struts.conf has not includes. I'll test it without includes to
> see if the error appears or not.
>
> Thanks for your help.
>
>
> Si quieres ser más positivo, pierde un electrón
> Miguel Ruiz Velasco Sobrino
>
>
>
> On Fri, Jan 29, 2010 at 14:27, Wes Wannemacher <wesw@(protected):
>> What you are doing should work the way you expect... I use the Spring
>> integration all the time :)
>>
>> A few simple questions, do you have the spring-plugin installed? Do
>> you have the Spring ContextLoaderListener setup in the web.xml? Do you
>> have any non-default configuration settings in any of web.xml,
>> applicationContext.xml or struts.xml? Are you using any plugins other
>> than the Spring plugin? What version of Spring and Struts are you
>> using?
>>
>> -Wes
>>
>> On Fri, Jan 29, 2010 at 1:19 AM, Miguel <miguelrvs@(protected):
>>> Hello all,
>>> I have a problem when using spring and the spring aplication context.
>>> If I configure the action class directly from struts.conf, my action
>>> does just the correct behavior. (1)
>>> But if I configure the action in a spring file and in struts.conf put
>>> only the spring bean name everything gets piped to the input result
>>> (the prepare method is executed, but not the action method).(2)
>>> I would benefit if the second scenario worked, because in the spring
>>> configuration is quite complex and have more than one bean of the same
>>> type
>>>
>>> (1) <action name="receptor_*" method="{1}"
>>> class="com.fcm.sectorPrimario2009.ui.ReceptorAction"> (struts.conf)
>>>
>>> (2)  <action name="receptor_*" method="{1}" class="receptorSPAction">
>>> (struts.conf)
>>>
>>> <bean id="receptorSPAction"
>>> class="com.fcm.sectorPrimario2009.ui.ReceptorAction"
>>> scope="prototype"> (spring.xml)
>>>                <property name="receptorDAO"><ref
>>> local="receptorDAOSectorPrimario"/></property>
>>>        </bean>
>>>
>>> I hope someone can help me
>>>
>>>
>>>
>>>
>>> Si quieres ser más positivo, pierde un electrón
>>> Miguel Ruiz Velasco Sobrino
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>>> For additional commands, e-mail: user-help@(protected)
>>>
>>>
>>
>>
>>
>> --
>> Wes Wannemacher



Hello,
I have done further testing and the problem appears related to the
combination of spring-defined beans and struts wildcards.
The actions that don't have wildcards behave identically if they are
created and wired by the struts-spring factory or by spring itself,
but the actions that have wildcards fail, as if there is some
validation that redirects them allways to INPUT.
Both beans receptorDAO and receptorDAOSectorPrimario conform to the
same interface ReceptorDAO, so the only way to autowire the actions is
to declare them in the applicationContext in spring.

spring.xml:
 <bean id="receptorDAO" class="com.proyectox.DAO.ReceptorDAOImpl">
   <property name="sessionFactory" ref="sessionFactory" />
    </bean>
...
 <bean id="receptorDAOSectorPrimario"
class="com.fcm.sectorPrimario2009.dao.ReceptorDAOImpl">
   <property name="sessionFactory" ref="sessionFactory" />
   <property name="entityName" value="SP_Receptor"/>
...
<bean id="receptorSPAction"
class="com.fcm.sectorPrimario2009.ui.ReceptorAction"
scope="prototype">
   <property name="receptorDAO"><ref
local="receptorDAOSectorPrimario"/></property>

struts.xml:
<struts>

 <!--<constant name="struts.serve.static" value="false" /> para que
no sirva el css ni el js -->
 <constant name="struts.devMode" value="true" />
 <constant name="struts.objectFactory"
value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
 <constant name="struts.freemarker.templatesCache" value="true" />

  <package name="proyectox" extends="json-default" ><!-- struts-default -->
<!-- Si no le pones este stack, pues no funciona...-->
 <interceptors>
   <interceptor name="strutsSpring"
class="com.proyectox.ui.interceptor.HibernateOpenSessionInViewInterceptor"/>
   <interceptor-stack name="strutsSpringPPPStack">
     <interceptor-ref name="strutsSpring"/>
     <interceptor-ref name="paramsPrepareParamsStack"/>
   </interceptor-stack>
 </interceptors>
...
  <package name="receptorsectorprimario" extends="proyectox"
namespace="/sectorprimario/receptor">
   <action name="receptor_*" method="{1}" class="receptorSPAction">
     <result>receptorDetail.jsp</result>
     <result name="detail">receptorDetail.jsp</result>
     <result name="input">receptorNuevo.jsp</result>
     <result name="modificar">receptorNuevo.jsp</result>
     <result name="borrar" type="redirectAction">
       <param name="actionName">lista</param>
     </result>
     <result name="error">/error.jsp</result>
     <interceptor-ref name="scope">
        <param name="session">contribuyente</param>
        <param name="autoCreateSession">true</param>
        <param name="key">contribuyenteActual</param>
     </interceptor-ref>
     <interceptor-ref name="scope">
        <param name="session">receptor</param>
        <param name="autoCreateSession">true</param>
        <param name="key">receptorActualSP</param>
     </interceptor-ref>
       <interceptor-ref name="strutsSpringPPPStack"/>
   </action>

Currently I have changed the name of the property in the actions so it
matches the name in the application context, the struts autowire by
name work, but I someone has any pointer of what should I do to test
this condition, I'll gladly do it.


Si quieres ser más positivo, pierde un electrón
Miguel Ruiz Velasco Sobrino


Attachment: user_204900.ezm (zipped)
i have written an interceptor implementation, however, it seems i cannot get
it to work. i have followed the instructions at
http://struts.apache.org/2.x/docs/interceptors.html. i have also followed
the instructions at
http://struts.apache.org/2.x/docs/how-do-we-configure-an-interceptor-to-be-used-with-every-action.htmlto
use the interceptor with every action.

however, when any of my actions run, i never see the pre and post processing
logging messages (logging messages inside the intercept method). i do see
the logging messages from the init and destroy methods. this is not a
problem with logging (as for sanity checking, i also use System.out.println,
and have Tomcat running in console mode). i also have placed some break
points in the intercept(ActionInvocation) method, but these break points are
never reached.

this is my struts.xml.

<struts>
  <package name="default" extends="struts-default">
    <interceptors>
       <interceptor name="dummyInterceptor"
class="mypackage.DummyInterceptor"/>
       <interceptor-stack name="dummyStack">
          <interceptor-ref name="dummyInterceptor"/>
          <interceptor-ref name="defaultStack"/>
       </interceptor-stack>
    </interceptors>
    <default-interceptor-ref name="dummyStack"/>
  </package>
</struts>

this is my DummyInterceptor class.

public class DummyInterceptor implements Interceptor {
  private static final Log _log =
LogFactory.getLog(DummyInterceptor.class);
  public void destroy() {
    _log.debug("dummy interceptor destroyed called");
    System.out.println("dummy interceptor destroyed
called".toUpperCase());
  }
  public void init() {
    _log.debug("dummy interceptor init called");
    System.out.println("dummy interceptor init called".toUpperCase());
  }
  public String intercept(ActionInvocation actionInvocation) throws
Exception {
    _log.debug("dummy interceptor intercept pre processing");
    System.out.println("dummy interceptor intercept pre
processing".toUpperCase());

    String result = actionInvocation.invoke();

    _log.debug("dummy interceptor intercept post processing");
    System.out.println("dummy interceptor intercept post
processing".toUpperCase());
    return result;
  }
}

i am using annotations for my Action classes, so i do not define any
<action> elements in struts.xml (using the Struts2 Convention jar).

one very interesting thing i did was to get struts-default.xml out of the
struts2-core-2.1.8.1.jar. i then modified struts-default.xml by adding: 1) a
definition of my interceptor and 2) my interceptor onto the defaultStack.
when i did this, my interceptor does work as expected (i see logging output
from the intercept method, i can hit break points set inside this method)
for all my actions.

i wonder if there is some gotcha that i am missing here. is there something
extra that i have to do when mixing annotations with interceptors?

thanks.

Attachment: user_204901.ezm (zipped)
http://struts.apache.org/2.x/docs/convention-plugin.html#ConventionPlugin-XWorkpackages


----- Original Message ----
> From: Jake Vang <vangjake@(protected)>
> To: user@(protected)
> Sent: Sat, January 30, 2010 4:10:31 PM
> Subject: interceptor is not being called for all action
>
> i have written an interceptor implementation, however, it seems i cannot get
> it to work. i have followed the instructions at
> http://struts.apache.org/2.x/docs/interceptors.html. i have also followed
> the instructions at
> http://struts.apache.org/2.x/docs/how-do-we-configure-an-interceptor-to-be-used-with-every-action.htmlto
> use the interceptor with every action.
>
> however, when any of my actions run, i never see the pre and post processing
> logging messages (logging messages inside the intercept method). i do see
> the logging messages from the init and destroy methods. this is not a
> problem with logging (as for sanity checking, i also use System.out.println,
> and have Tomcat running in console mode). i also have placed some break
> points in the intercept(ActionInvocation) method, but these break points are
> never reached.
>
> this is my struts.xml.
>
>
>  
>      
>        
> class="mypackage.DummyInterceptor"/>
>        
>          
>          
>        
>      
>      
>  
>
>
> this is my DummyInterceptor class.
>
> public class DummyInterceptor implements Interceptor {
>   private static final Log _log =
> LogFactory.getLog(DummyInterceptor.class);
>   public void destroy() {
>      _log.debug("dummy interceptor destroyed called");
>      System.out.println("dummy interceptor destroyed
> called".toUpperCase());
>   }
>   public void init() {
>      _log.debug("dummy interceptor init called");
>      System.out.println("dummy interceptor init called".toUpperCase());
>   }
>   public String intercept(ActionInvocation actionInvocation) throws
> Exception {
>      _log.debug("dummy interceptor intercept pre processing");
>      System.out.println("dummy interceptor intercept pre
> processing".toUpperCase());
>
>      String result = actionInvocation.invoke();
>
>      _log.debug("dummy interceptor intercept post processing");
>      System.out.println("dummy interceptor intercept post
> processing".toUpperCase());
>      return result;
>   }
> }
>
> i am using annotations for my Action classes, so i do not define any
> elements in struts.xml (using the Struts2 Convention jar).
>
> one very interesting thing i did was to get struts-default.xml out of the
> struts2-core-2.1.8.1.jar. i then modified struts-default.xml by adding: 1) a
> definition of my interceptor and 2) my interceptor onto the defaultStack.
> when i did this, my interceptor does work as expected (i see logging output
> from the intercept method, i can hit break points set inside this method)
> for all my actions.
>
> i wonder if there is some gotcha that i am missing here. is there something
> extra that i have to do when mixing annotations with interceptors?
>
> thanks.



Attachment: user_204902.ezm (zipped)
what does that have to do with my problem? please enlighten.

On Sat, Jan 30, 2010 at 4:37 PM, Dave Newton <newton.dave@(protected):

>
> http://struts.apache.org/2.x/docs/convention-plugin.html#ConventionPlugin-XWorkpackages
>
>
> ----- Original Message ----
> > From: Jake Vang <vangjake@(protected)>
> > To: user@(protected)
> > Sent: Sat, January 30, 2010 4:10:31 PM
> > Subject: interceptor is not being called for all action
> >
> > i have written an interceptor implementation, however, it seems i cannot
> get
> > it to work. i have followed the instructions at
> > http://struts.apache.org/2.x/docs/interceptors.html. i have also
> followed
> > the instructions at
> >
> http://struts.apache.org/2.x/docs/how-do-we-configure-an-interceptor-to-be-used-with-every-action.htmlto
> > use the interceptor with every action.
> >
> > however, when any of my actions run, i never see the pre and post
> processing
> > logging messages (logging messages inside the intercept method). i do see
> > the logging messages from the init and destroy methods. this is not a
> > problem with logging (as for sanity checking, i also use
> System.out.println,
> > and have Tomcat running in console mode). i also have placed some break
> > points in the intercept(ActionInvocation) method, but these break points
> are
> > never reached.
> >
> > this is my struts.xml.
> >
> >
> >
> >
> >
> > class="mypackage.DummyInterceptor"/>
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > this is my DummyInterceptor class.
> >
> > public class DummyInterceptor implements Interceptor {
> >   private static final Log _log =
> > LogFactory.getLog(DummyInterceptor.class);
> >   public void destroy() {
> >      _log.debug("dummy interceptor destroyed called");
> >      System.out.println("dummy interceptor destroyed
> > called".toUpperCase());
> >   }
> >   public void init() {
> >      _log.debug("dummy interceptor init called");
> >      System.out.println("dummy interceptor init
> called".toUpperCase());
> >   }
> >   public String intercept(ActionInvocation actionInvocation) throws
> > Exception {
> >      _log.debug("dummy interceptor intercept pre processing");
> >      System.out.println("dummy interceptor intercept pre
> > processing".toUpperCase());
> >
> >      String result = actionInvocation.invoke();
> >
> >      _log.debug("dummy interceptor intercept post processing");
> >      System.out.println("dummy interceptor intercept post
> > processing".toUpperCase());
> >      return result;
> >   }
> > }
> >
> > i am using annotations for my Action classes, so i do not define any
> > elements in struts.xml (using the Struts2 Convention jar).
> >
> > one very interesting thing i did was to get struts-default.xml out of the
> > struts2-core-2.1.8.1.jar. i then modified struts-default.xml by adding:
> 1) a
> > definition of my interceptor and 2) my interceptor onto the defaultStack.
> > when i did this, my interceptor does work as expected (i see logging
> output
> > from the intercept method, i can hit break points set inside this method)
> > for all my actions.
> >
> > i wonder if there is some gotcha that i am missing here. is there
> something
> > extra that i have to do when mixing annotations with interceptors?
> >
> > thanks.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>

Attachment: user_204903.ezm (zipped)
i read that section on that page 10 times and i don't know how that relates
to my problem. there's simply not enough information. i guess it's pointing
me to something about namespaces, but, how do we get around this?

on the other hand, the rest of that page was informative on annotations and
the convention plugin. when i added
interceptorRefs={@(protected)
method, the web application won't start up.

ERROR
com.opensymphony.xwork2.util.logging.commons.CommonsLogger.error (CommonsLogger.java:27)
- Dispatcher initialization failed
...
Caused by: Unable to find interceptor class referenced by ref-name
dummyStack - [unknown location]

how hard can it be to get this to work? interestingly, if i do this,
interceptorRefs={@(protected)
(but then, my Interceptor is not called).

On Sat, Jan 30, 2010 at 4:37 PM, Dave Newton <newton.dave@(protected):

>
> http://struts.apache.org/2.x/docs/convention-plugin.html#ConventionPlugin-XWorkpackages
>
>
> ----- Original Message ----
> > From: Jake Vang <vangjake@(protected)>
> > To: user@(protected)
> > Sent: Sat, January 30, 2010 4:10:31 PM
> > Subject: interceptor is not being called for all action
> >
> > i have written an interceptor implementation, however, it seems i cannot
> get
> > it to work. i have followed the instructions at
> > http://struts.apache.org/2.x/docs/interceptors.html. i have also
> followed
> > the instructions at
> >
> http://struts.apache.org/2.x/docs/how-do-we-configure-an-interceptor-to-be-used-with-every-action.htmlto
> > use the interceptor with every action.
> >
> > however, when any of my actions run, i never see the pre and post
> processing
> > logging messages (logging messages inside the intercept method). i do see
> > the logging messages from the init and destroy methods. this is not a
> > problem with logging (as for sanity checking, i also use
> System.out.println,
> > and have Tomcat running in console mode). i also have placed some break
> > points in the intercept(ActionInvocation) method, but these break points
> are
> > never reached.
> >
> > this is my struts.xml.
> >
> >
> >
> >
> >
> > class="mypackage.DummyInterceptor"/>
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > this is my DummyInterceptor class.
> >
> > public class DummyInterceptor implements Interceptor {
> >   private static final Log _log =
> > LogFactory.getLog(DummyInterceptor.class);
> >   public void destroy() {
> >      _log.debug("dummy interceptor destroyed called");
> >      System.out.println("dummy interceptor destroyed
> > called".toUpperCase());
> >   }
> >   public void init() {
> >      _log.debug("dummy interceptor init called");
> >      System.out.println("dummy interceptor init
> called".toUpperCase());
> >   }
> >   public String intercept(ActionInvocation actionInvocation) throws
> > Exception {
> >      _log.debug("dummy interceptor intercept pre processing");
> >      System.out.println("dummy interceptor intercept pre
> > processing".toUpperCase());
> >
> >      String result = actionInvocation.invoke();
> >
> >      _log.debug("dummy interceptor intercept post processing");
> >      System.out.println("dummy interceptor intercept post
> > processing".toUpperCase());
> >      return result;
> >   }
> > }
> >
> > i am using annotations for my Action classes, so i do not define any
> > elements in struts.xml (using the Struts2 Convention jar).
> >
> > one very interesting thing i did was to get struts-default.xml out of the
> > struts2-core-2.1.8.1.jar. i then modified struts-default.xml by adding:
> 1) a
> > definition of my interceptor and 2) my interceptor onto the defaultStack.
> > when i did this, my interceptor does work as expected (i see logging
> output
> > from the intercept method, i can hit break points set inside this method)
> > for all my actions.
> >
> > i wonder if there is some gotcha that i am missing here. is there
> something
> > extra that i have to do when mixing annotations with interceptors?
> >
> > thanks.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>

Attachment: user_204904.ezm (zipped)
okay, after fiddling around for 2 hours, with the weak documentation out
there, i think i have it figured out. at least empirically, it works now.
just in case there are other users out there who are running into this
problem, let me explain what in the world i did. i know A LOT of other
people have run into this problem on how to get interceptors to work with
the convention plugin (googling). the shame is that although i saw a lot of
"thanks, i got it working", no one ever bothered to show how they got it to
work.

at any rate, if you read the original post by me, you will see how my
interceptor stack was defined in struts.xml. you will also see how i
implemented a dummy interceptor. i had to do two things to get my
interceptor working (called on my action).
1. add @ParentPackage("default") to my Action class
2. add @interceptorRefs={@(protected)
(in my Action class).

after i did this, my interceptor's intercept(ActionInvocation) method is
called when my Action is called.

here's how my dummy Action class looks like.

@ParentPackage("default")
public class DummyAction extends ActionSupport {
@Action(value="/dummy",
results={@(protected)")},
interceptorRefs={@(protected)")}
)
public String execute() {
return SUCCESS;
}
}

alright, so, now i'd like to know how to get this interceptor stack
(dummyStack) to work on all actions? in the link i posted, you can do so
using one single line in struts.xml (i.e. <default-interceptor-ref
name="dummyStack"/>). with the convention plugin + annotations, is such a
simple approach possible? or do i have to continuously add @ParentPackage
and @InterceptorRef annotations to the classes and methods i want to use the
stack?

i don't know why this is such a pain (but then again, i'm not a developer on
the struts2 project, so there may be a lot of complexities to get this
working elegantly that i'm unaware of).

On Sat, Jan 30, 2010 at 4:10 PM, Jake Vang <vangjake@(protected):

> i have written an interceptor implementation, however, it seems i cannot
> get it to work. i have followed the instructions at
> http://struts.apache.org/2.x/docs/interceptors.html. i have also followed
> the instructions at
> http://struts.apache.org/2.x/docs/how-do-we-configure-an-interceptor-to-be-used-with-every-action.htmlto use the interceptor with every action.
>
> however, when any of my actions run, i never see the pre and post
> processing logging messages (logging messages inside the intercept method).
> i do see the logging messages from the init and destroy methods. this is not
> a problem with logging (as for sanity checking, i also use
> System.out.println, and have Tomcat running in console mode). i also have
> placed some break points in the intercept(ActionInvocation) method, but
> these break points are never reached.
>
> this is my struts.xml.
>
> <struts>
>   <package name="default" extends="struts-default">
>      <interceptors>
>         <interceptor name="dummyInterceptor"
> class="mypackage.DummyInterceptor"/>
>         <interceptor-stack name="dummyStack">
>           <interceptor-ref name="dummyInterceptor"/>
>           <interceptor-ref name="defaultStack"/>
>         </interceptor-stack>
>      </interceptors>
>      <default-interceptor-ref name="dummyStack"/>
>   </package>
> </struts>
>
> this is my DummyInterceptor class.
>
> public class DummyInterceptor implements Interceptor {
>   private static final Log _log =
> LogFactory.getLog(DummyInterceptor.class);
>   public void destroy() {
>      _log.debug("dummy interceptor destroyed called");
>      System.out.println("dummy interceptor destroyed
> called".toUpperCase());
>   }
>   public void init() {
>      _log.debug("dummy interceptor init called");
>      System.out.println("dummy interceptor init called".toUpperCase());
>   }
>   public String intercept(ActionInvocation actionInvocation) throws
> Exception {
>      _log.debug("dummy interceptor intercept pre processing");
>      System.out.println("dummy interceptor intercept pre
> processing".toUpperCase());
>
>      String result = actionInvocation.invoke();
>
>      _log.debug("dummy interceptor intercept post processing");
>      System.out.println("dummy interceptor intercept post
> processing".toUpperCase());
>      return result;
>   }
> }
>
> i am using annotations for my Action classes, so i do not define any
> <action> elements in struts.xml (using the Struts2 Convention jar).
>
> one very interesting thing i did was to get struts-default.xml out of the
> struts2-core-2.1.8.1.jar. i then modified struts-default.xml by adding: 1) a
> definition of my interceptor and 2) my interceptor onto the defaultStack.
> when i did this, my interceptor does work as expected (i see logging output
> from the intercept method, i can hit break points set inside this method)
> for all my actions.
>
> i wonder if there is some gotcha that i am missing here. is there something
> extra that i have to do when mixing annotations with interceptors?
>
> thanks.
>
©2008 gg3721.com - Jax Systems, LLC, U.S.A.