Turn: About Beetl integrated struts2 +convention plugin does not recognize the processing scheme of beetl template

Source: Internet
Author: User

Transfer from Jplus articles

today's first contact with this template engine, it feels very good, usually using spring MVC development, currently teach students to do a small project, using Struts+guice+mybatis, so want to try this template engine open the actual use of the situation.
because the current project fully adopts the 0 configuration scheme, there is a problem
according to the instructions of the Beetl user manual:
need to add Result-types in the Struts2 configuration file to do the following configuration
?
<package name= "Default" namespace= "/" extends= "Struts-default" > ... .
<result-types>
<result-type name= "Beetl" class= "Org.beetl.ext.struts2.Struts2BeetlActionResult" default= "true"/>
</result-types>
<action name= "HelloWorld" class= "example. HelloWorld "> <result>/hello.html</result>
</action> ... </package>

There is absolutely no problem in the general development process based on the struts profile, but if integration with convention will not fully enjoy the functionality of Beetl, unless the annotations are used to complete the complex configuration.
more convenient is the struts2 is open source, according to the source code of the general analysis of the main problem has two points

1. Add convention default result view type

<constant name= "Struts.convention.default.parent.package"    value= "Ssia"/><constant name= " Struts.convention.relative.result.types "value=" Dispatcher,velocity,freemarker,beetl "/><package name=" Ssia "Namespace="/"extends=" Convention-default ">    <result-types>        <result-type name=" Beetl "            class= "Org.beetl.ext.struts2.Struts2BeetlActionResult" default= "true"/>    </result-types></ Package>




2. Modify the Convention view File scan extension to use our own BTL file as a convention view
<bean type= "Org.apache.struts2.convention.ConventionsService" name= "Beetlservice" class= " Com.ssia.web.struts.plugin.convention.beetl.ConventionsBeetlService "/><constant name=" Struts.convention.conventionsService "value=" Beetlservice "/>public class Conventionsbeetlservice extends Conventionsserviceimpl {@Injectpublic Conventionsbeetlservice (        @Inject ("Struts.convention.result.path") String resultpath) {    super (Resultpath);} public map<string, Resulttypeconfig> getresulttypesbyextension ( Packageconfig packageconfig) {        map<string, resulttypeconfig> results = Packageconfig.getallresulttypeconfigs ();        map<string, resulttypeconfig> resultsbyextension = super.getresulttypesbyextension (packageConfig);        Resultsbyextension.put ("Btl", Results.get ("Beetl"));        return resultsbyextension;}    }




after the modification and configuration of the Struts2-convention plugin and the Beetl template engine will be able to work together, spring MVC does not appear in this kind of situation

Turn: About Beetl integrated struts2 +convention plugin does not recognize the processing scheme of beetl template

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.