jeecms自定义标签
最近在研究jeecms,虽然已经有很多标签了,但是由于需要,需要增加新的标签。
比如增加一个标签,可以根据会员组id查出该组下所有的会员。
其中CmsUser  CmsUserDao 及CmsUserMng原系统已有,查询会员方法也有,因此只需编写一个FreeMarker标签类就行了。此标签类需要实现TemplateDirectiveModel接口。
public class CmsMemberListDirective implements TemplateDirectiveModel {
/**
* 模板名称
*/
public static final String TPL_NAME = "member_list";
/**
* @Fields GROUP_ID : 输入参数,会员组ID
*/
private static final String GROUP_ID = "groupId";
/**
* @Fields DISABLED : 输入参数,是否禁用
*/
private static final String DISABLED = "disabled";

public void execute(Environment env, Map params, TemplateModel[] arg2,
TemplateDirectiveBody body) throws TemplateException, IOException {
CmsSite site = FrontUtils.getSite(env);
Integer groupId = getId(params);
Boolean disabled = DirectiveUtils.getBool(DISABLED, params);
List list = cmsUserMng.getList(null, null, null, groupId, disabled, null, null);
Map paramWrap = new HashMap(
params);
paramWrap.put(OUT_LIST, DEFAULT_WRAPPER.wrap(list));
Map origMap = DirectiveUtils
.addParamsToVariable(env, paramWrap);
InvokeType type = DirectiveUtils.getInvokeType(params);
String listStyle = DirectiveUtils.getString(PARAM_STYLE_LIST, params);
if (InvokeType.sysDefined == type) {
if (StringUtils.isBlank(listStyle)) {
throw new ParamsRequiredException(PARAM_STYLE_LIST);
}
env.include(TPL_STYLE_LIST + listStyle + TPL_SUFFIX, UTF8, true);
} else if (InvokeType.userDefined == type) {
if (StringUtils.isBlank(listStyle)) {
throw new ParamsRequiredException(PARAM_STYLE_LIST);
}
FrontUtils.includeTpl(TPL_STYLE_LIST, site, env);
} else if (InvokeType.custom == type) {
FrontUtils.includeTpl(TPL_NAME, site, params, env);
} else if (InvokeType.body == type) {
body.render(env.getOut());
} else {
throw new RuntimeException("invoke type not handled: " + type);
}
DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap);

}

private Integer getId(Map params)
throws TemplateException {
Integer id = DirectiveUtils.getInt(GROUP_ID, params);
if (id != null) {
return id;
} else {
throw new ParamsRequiredException(GROUP_ID);
}
}
@Autowired
private CmsUserMng cmsUserMng;
}
写完后需要在在jeecms-context.xml文件中加入CmsChannelStatisticsDirective标签类的bean注入代码。


接着还要在在jeecms-servlet-front.xml文件中配置:





配完后重启项目,可以在栏目模板中使用标签了。

[@cms_member_list groupId = ‘1’]
 [#list tag_list as a]
 
  • ${a.username}
  • [/#list] [/@cms_member_list]
    
    
    
    暂无评论

    发送评论 编辑评论

    
    				
    |´・ω・)ノ
    ヾ(≧∇≦*)ゝ
    (☆ω☆)
    (╯‵□′)╯︵┴─┴
     ̄﹃ ̄
    (/ω\)
    ∠( ᐛ 」∠)_
    (๑•̀ㅁ•́ฅ)
    →_→
    ୧(๑•̀⌄•́๑)૭
    ٩(ˊᗜˋ*)و
    (ノ°ο°)ノ
    (´இ皿இ`)
    ⌇●﹏●⌇
    (ฅ´ω`ฅ)
    (╯°A°)╯︵○○○
    φ( ̄∇ ̄o)
    ヾ(´・ ・`。)ノ"
    ( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
    (ó﹏ò。)
    Σ(っ °Д °;)っ
    ( ,,´・ω・)ノ"(´っω・`。)
    ╮(╯▽╰)╭
    o(*////▽////*)q
    >﹏<
    ( ๑´•ω•) "(ㆆᴗㆆ)
    😂
    😀
    😅
    😊
    🙂
    🙃
    😌
    😍
    😘
    😜
    😝
    😏
    😒
    🙄
    😳
    😡
    😔
    😫
    😱
    😭
    💩
    👻
    🙌
    🖕
    👍
    👫
    👬
    👭
    🌚
    🌝
    🙈
    💊
    😶
    🙏
    🍦
    🍉
    😣
    Source: github.com/k4yt3x/flowerhd
    颜文字
    Emoji
    小恐龙
    花!
    上一篇
    下一篇