Tiles 找不到 Spring 中定义的 Tiles ViewPreparer

发布于 2024-10-20 09:08:31 字数 2528 浏览 2 评论 0原文

编辑:我相信tilesConfigurer的SpringBeanPreparerFactory属性负责确保准备器可用于tile......但看起来它可能不起作用。 tilesConfigurer 的默认值是“BasicPreparerFactory”,我在服务器日志中看到了对此的引用,我想也许不知何故该属性没有正确设置,而是使用默认值 BasicPreparerFactor 。

I'我对这个完全不知所措……任何想法或建议将不胜感激。

我只是想使用在我的 Spring 配置中定义的 Tiles ViewPreparer ...就是这样!但无论出于何种原因,我的 ViewPreparer 的“执行”方法从未被调用。 ViewPreparer 是由 Spring 构建的,并且我的图块正在渲染,但准备器从未执行。就像 Tiles 和 Spring 之间应该有一个断开的链接一样......我说我在tiles.xml中使用“testPreparer”,它是“applicationContext.xml”中定义的一个bean,但tiles的行为就像我一样根本没有定义准备者。 这是我的一个很好的描述本质上是在尝试做。

/WEB-INF/tiles.xml:

<tiles-definitions>

  <definition name="test.tile" template="testtile.jsp" preparer="testPreparer">
  </definition>

</tiles-definitions> 

applicationContext.xml

  <bean id="tilesConfigurer"
    class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
      <list>
        <value>/WEB-INF/tiles.xml</value>
      </list>
    </property>
    <property name="preparerFactoryClass"
      value="org.springframework.web.servlet.view.tiles2.SpringBeanPreparerFactory" />
  </bean>

  <bean id="testPreparer" class="TestPreparer"></bean>

TestPreparer.java

import org.apache.tiles.AttributeContext;
import org.apache.tiles.context.TilesRequestContext;
import org.apache.tiles.preparer.PreparerException;
import org.apache.tiles.preparer.ViewPreparer;


public class TestPreparer implements ViewPreparer {

    public void execute(TilesRequestContext arg0, AttributeContext arg1)
            throws PreparerException {
        System.out.println("I executed");

    }

}

struts.xml:

  <package name="apps-default" extends="struts-default"
    abstract="true">
    <result-types>
      <result-type name="tiles"
        class="org.apache.struts2.views.tiles.TilesResult" />
      </result-types>
    <interceptors>
      ...
    </interceptors>

   <default-interceptor-ref name="defaultAppStack"/>

  <package name="testPackage" extends="apps-default" namespace="/test">
    <action name="create" class="testAction" method="create">
      <result type="tiles">test.tile</result>
    </action>
  </package>

EDIT: I believe it is the SpringBeanPreparerFactory property of tilesConfigurer that is responsible for making sure the preparers are available for tiles ... but it appears that it may not be working. The default for tilesConfigurer is "BasicPreparerFactory", and I see a reference to that in the server logs, I'm thinking that maybe somehow that property is not being set correctly and it's using the default, BasicPreparerFactor instead.

I'm at a complete loss with this one... ANY thoughts or advice would be appreciated.

I am simply trying to use a Tiles ViewPreparer which is defined in my Spring configuration ... that's it! But for whatever reason, the "execute" method of my ViewPreparer is just never called. The ViewPreparer IS being constructed by Spring, and my tile is being rendered, but the preparer never executes. It's like there is a broken link between Tiles and Spring that should be there ... I say I'm using "testPreparer" in tiles.xml, which is a bean defined in "applicationContext.xml", but tiles is behaving like I didn't define a preparer at all. Here's a good description of what I'm essentially trying to do.

/WEB-INF/tiles.xml:

<tiles-definitions>

  <definition name="test.tile" template="testtile.jsp" preparer="testPreparer">
  </definition>

</tiles-definitions> 

applicationContext.xml

  <bean id="tilesConfigurer"
    class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
      <list>
        <value>/WEB-INF/tiles.xml</value>
      </list>
    </property>
    <property name="preparerFactoryClass"
      value="org.springframework.web.servlet.view.tiles2.SpringBeanPreparerFactory" />
  </bean>

  <bean id="testPreparer" class="TestPreparer"></bean>

TestPreparer.java

import org.apache.tiles.AttributeContext;
import org.apache.tiles.context.TilesRequestContext;
import org.apache.tiles.preparer.PreparerException;
import org.apache.tiles.preparer.ViewPreparer;


public class TestPreparer implements ViewPreparer {

    public void execute(TilesRequestContext arg0, AttributeContext arg1)
            throws PreparerException {
        System.out.println("I executed");

    }

}

struts.xml:

  <package name="apps-default" extends="struts-default"
    abstract="true">
    <result-types>
      <result-type name="tiles"
        class="org.apache.struts2.views.tiles.TilesResult" />
      </result-types>
    <interceptors>
      ...
    </interceptors>

   <default-interceptor-ref name="defaultAppStack"/>

  <package name="testPackage" extends="apps-default" namespace="/test">
    <action name="create" class="testAction" method="create">
      <result type="tiles">test.tile</result>
    </action>
  </package>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

追星践月 2024-10-27 09:08:31

好的,问题解决了。事实证明,这是因为我的 web.xml 中有以下条目:

<listener>
    <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>

无论出于何种原因,这本质上破坏/干扰了我在 applicationContext.xml 中定义的内容。我必须做更多的调查才能弄清楚冲突到底是什么,但不用说删除该条目就解决了问题。

抱歉,我花了两天时间试图解决这个问题,我想在这里写下我的问题可以帮助我思考它。哦,好吧,至少这会记录在此处,以防其他人遇到同样的问题!

OK, problem solved. As it turns out, it was because I had the following entry in my web.xml:

<listener>
    <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>

For whatever reason, that was essentially breaking/interfering with what I defined in applicationContext.xml. I'd have to do more investigation to figure out what exactly the conflict was, but needless to say removing that entry solved the issue.

Sorry, I spent the last 2 days trying to figure this out, and I guess writing my problem on here helped me think through it. Oh well, at least this will be documented out here on S.O. in case anyone else every runs into the same issue!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文