On Fri, Jan 29, 2010 at 19:09, Miguel <miguel...@gmail.com> wrote:
> 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();
>                }
>
>       �...@org.apache.struts2.interceptor.validation.skipvalidation
>        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;
>        }
>
>       �...@org.apache.struts2.interceptor.validation.skipvalidation
>        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 <w...@wantii.com> wrote:
>> 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 <miguel...@gmail.com> wrote:
>>> 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-unsubscr...@struts.apache.org
>>> For additional commands, e-mail: user-h...@struts.apache.org
>>>
>>>
>>
>>
>>
>> --
>> 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

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

Reply via email to