[Freemarker]-call freemarker's FTL template method using struts component

Source: Internet
Author: User

The component tag in struts can be used to call the FTL template file of freemarker. The parameter passing using the component tag can be written as follows:

Using the property method:

    <s:component template="gridComponent.ftl" templateDir="/WEB-INF/template">           <s:param name="grid" value="userss"></s:param>    </s:component>

 

Use the get/set attribute method of the request:

    <s:component template="gridComponent.ftl" templateDir="/WEB-INF/template">           <s:param name="grid" value="#request.users"></s:param>    </s:component>

 

The following describes how to use FTL read parameters:

<#assign s=JspTaglibs["/struts-tags"] /><#assign req = parameters.grid /><#list req as item>    ${item["userName"]}</#list>

 

Common struts action:

Package COM. obs. actions. admin; import Java. util. list; import Org. apache. struts2.servletactioncontext; import Org. springframework. stereotype. controller; import COM. obs. actions. baseadminactionsupport; import COM. obs. actions. bean. user; import COM. obs. util. common; @ controller @ suppresswarnings ("serial")/* @ namespace ("/admin") @ results ({@ result (name = "success ", location = "/WEB-INF/View/admin/user. JSP ")}) */public class useraction extends baseadminactionsupport {private list <user> userss; public list <user> getuserss () {return userss ;} public void setuserss (list <user> userss) {This. userss = userss;}/*** by default, the page executes action */@ override Public String execute () throws exception {// obtain the list of all users <COM. obs. service. bean. user> userlist = super. userservice. findusers (); // copy bean list <user> Users = Common. copyproperties (userlist, user. class); userss = users; // set the action bean to the page servletactioncontext. getrequest (). setattribute ("users", users); Return success ;}}

 

Userss is property, and users is the attribute of request.

[Freemarker]-call freemarker's FTL template method using struts component

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.