I'm new to Tapestry. I've been wanting to take a look at it for some time,
and have a bit of time here at the end of the year. I've started with
Howard's tutorial for Tap5 and got the first stage of that working easily.
So then I created another simple page, and linked to that. Still working
fine, so time to start getting into something 'real'. Since we use Spring
for all our projects here I figured that should be my next step. I created
an iBatis DAO that accesses one of our existing JNDI datasources, with the
intent of having my page retrieve data from it for displaying.

I followed the steps described here:
http://tapestry.apache.org/tapestry5/tapestry-spring/, but the dao is not
getting injected; I get a NPE when it comes time to access it. My logs show
the initialization completing correctly, with the Spring beans being
created. Is there anything missing fom this description to complete the
wiring?

I'm using Tapestry5.0.6, Spring2.0.1 (though I also tried 1.2.8),
iBatis2.3.0.677, running in Sun Appserver8.2

Here's my web.xml:

<web-app>
          <display-name>tapestry-tutorial1 Tapestry 5 Application</
display-name>
          <context-param>
              <!-- The only significant configuration for Tapestry 5, this
informs Tapestry
                   of where to look for pages, components and mixins. -->
              <param-name>tapestry.app-package</param-name>
              <param-value>org.apache.tapestry.tutorial</param-value>
          </context-param>

                  <context-param>
                        <param-name>contextConfigLocation</param-name>
                        <param-value>

classpath:org/apache/tapestry/tutorial/applicationContext.xml
                        </param-value>
                  </context-param>

          <filter>
              <filter-name>app</filter-name>
              <!--

<filter-class>org.apache.tapestry.TapestryFilter</filter-class>
               -->
               <filter-class>
org.apache.tapestry.spring.TapestrySpringFilter</filter-class>
          </filter>
          <filter-mapping>
              <filter-name>app</filter-name>
              <url-pattern>/*</url-pattern>
          </filter-mapping>

                  <listener>
                    <listener-class>
org.springframework.web.context.ContextLoaderListener</listener-class>
                  </listener>
</web-app>


org/apache/tapestry/tutorial/applicationContext.xml:

<beans xmlns="http://www.springframework.org/schema/beans";
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
            xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-2.0.xsd";>

      <import resource=
"classpath:org/apache/tapestry/tutorial/dao/applicationContext-jndi.xml"/>
      <import resource=
"classpath:org/apache/tapestry/tutorial/dao/ibatis/applicationContext.xml"
/>
</beans>


org/apache/tapestry/tutorial/dao/applicationContext-jndi.xml:

<beans xmlns="http://www.springframework.org/schema/beans";
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
            xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd";>

      <bean id="serviceDataSource" class=
"org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiName" value="srServiceDataSource"/>
      </bean>
</beans>


org/apache/tapestry/tutorial/dao/ibatis/applicationContext.xml:

<beans xmlns="http://www.springframework.org/schema/beans";
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
            xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd";>

      <bean id="sqlMapClient" class=
"org.springframework.orm.ibatis.SqlMapClientFactoryBean">
            <property name="configLocation" value=
"classpath:org/apache/tapestry/tutorial/dao/ibatis/sql-map-config.xml" />
            <property name="dataSource" ref="serviceDataSource" />
      </bean>

      <bean name="serviceDao" class=
"org.apache.tapestry.tutorial.dao.ibatis.ServiceDaoImpl">
            <property name="sqlMapClient" ref="sqlMapClient" />
      </bean>
</beans>


And in my page class:

public class Target
{
    @Inject
    @Service("serviceDao")
    private ServiceDao dao;

    public List<String> getOptions()
    {
        return dao.getOptions();               ///  NPE here!! getOptions()
in the dao returns a hard-coded list at this time
    }

    public void setDao(final ServiceDao _dao)
    {
        this.dao = _dao;
    }
    public ServiceDao getDao()
    {
        return dao;
    }
}

I haven't tried the alternate methods presented, but just by looking at
them I know that I will not be able to convince the other developers to
give Tapestry a try if it's necessary to go through that in order to use
Spring. Hopefully I'm just missing something simple and I'll be able to get
this method working. But I've been struggling with it for the better part
of 2 days now.

Dave

We must begin not just to act, but to think, for there is no better slave
than the one who believes his slavery to be freedom, and we are in
no greater peril than when we cannot see the chains on our minds
because there are yet no chains on our feet.
-- Michael Reid


This message contains information from Equifax Inc. which may be
confidential and privileged.  If you are not an intended recipient, please
refrain from any disclosure, copying, distribution or use of this
information and note that such actions are prohibited.  If you have
received this transmission in error, please notify by e-mail
[EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to