- 浏览: 733710 次
- 性别:
- 来自: 重庆
文章分类
- 全部博客 (194)
- Webservice (6)
- ExtJs (2)
- Work Summary (4)
- CoreJava (51)
- Spring (10)
- EJB (5)
- struts1.x (3)
- C/C++ (5)
- DatabaseManager (19)
- Hibernate (5)
- Crytology (1)
- Web Server (5)
- Software Manager (5)
- WebUi (39)
- Web page (2)
- android (5)
- struts2 (12)
- Java 导出 Excel (1)
- Spring 与struts2 和Hibernate 4.0注解解决方安 (1)
- Dwr (1)
- maven3 (4)
- Windows (3)
- 表格头部信息不动使用Jquery 外部框架 (1)
- 软件行业动态 (1)
- mybatis (1)
- C# (3)
- MySQL (4)
最新评论
-
July01:
最近了解到一款StratoIO打印控件,功能如下:1、Html ...
LODOP插件开发 -
an52036:
u010980147 写道您的代码确实能生成条形码,但是打印出 ...
Java 条形码生成(一维条形码) -
di1984HIT:
学习了,很好~~
Ant 打包war 生成文件内容build.xml -
lhb319lhb:
如果 ajax(jquery)更新了 iframe 的 src ...
jquery 修改iframe src -
calosteward:
感谢楼主,除了一维条码,有没有相关二维码的资源呢?______ ...
Java 条形码生成(一维条形码)
author liuqing
刘庆
标签原理这里就不做详细介绍了
1. 首先我们来读一读struts2 的源代码
public abstract class UIBean extends Component {
private static final Logger LOG = LoggerFactory.getLogger(UIBean.class); protected HttpServletRequest request; protected HttpServletResponse response; public UIBean(ValueStack stack, HttpServletRequest request, HttpServletResponse response) { super(stack); this.request = request; this.response = response; this.templateSuffix = ContextUtil.getTemplateSuffix(stack.getContext()); } // The templateSuffic to use, overrides the default one if not null. protected String templateSuffix; // The template to use, overrides the default one. protected String template; // templateDir and theme attributes //定义freemark.ftl文件夹 protected String templateDir; //对应根目录 protected String theme; // shortcut, sets label, name, and value protected String key; protected String id; protected String cssClass; protected String cssStyle; protected String cssErrorClass; protected String cssErrorStyle; protected String disabled; protected String label; protected String labelPosition; protected String labelSeparator; protected String requiredposition; protected String name; protected String required; protected String tabindex; protected String value; protected String title; // HTML scripting events attributes protected String onclick; protected String ondblclick; protected String onmousedown; protected String onmouseup; protected String onmouseover; protected String onmousemove; protected String onmouseout; protected String onfocus; protected String onblur; protected String onkeypress; protected String onkeydown; protected String onkeyup; protected String onselect; protected String onchange; // common html attributes protected String accesskey; // javascript tooltip attribute protected String tooltip; protected String tooltipConfig; protected String javascriptTooltip; protected String tooltipDelay; protected String tooltipCssClass; protected String tooltipIconPath; // dynamic attributes protected Map<String,Object> dynamicAttributes = new HashMap<String,Object>(); protected String defaultTemplateDir; protected String defaultUITheme; protected TemplateEngineManager templateEngineManager; //注入对应的目录文件夹内容 @Inject(StrutsConstants.STRUTS_UI_TEMPLATEDIR) public void setDefaultTemplateDir(String dir) { this.defaultTemplateDir = dir; }
定义基Bean
package org.cxkj.struts2.components;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.components.UIBean; import org.apache.struts2.views.annotations.StrutsTagAttribute; import com.opensymphony.xwork2.util.ValueStack; /** * * @author liuqing * @version 2.0 * 2011-3-8 * */ public abstract class HtmlBean extends UIBean { protected String width; protected String height; protected String align; public HtmlBean(ValueStack stack, HttpServletRequest request, HttpServletResponse response) { super(stack, request, response); } /* (non-Javadoc) * @see org.apache.struts2.components.UIBean#evaluateParams() */ @Override public void evaluateParams() { super.evaluateParams(); if (width != null) { addParameter("width", findString(width)); } if (height != null) { addParameter("height", findString(height)); } if (align != null) { addParameter("align", findString(align)); } } /** * @param width the width to set */ @StrutsTagAttribute(description="") public void setWidth(String width) { this.width = width; } /** * @param height the height to set */ @StrutsTagAttribute(description="") public void setHeight(String height) { this.height = height; } /** * @param align the align to set */ @StrutsTagAttribute(description="") public void setAlign(String align) { this.align = align; } }
添加时间控件
package org.cxkj.struts2.views.jsp.ui;
import org.apache.struts2.views.jsp.ui.AbstractUITag; import org.cxkj.struts2.components.HtmlBean; /** * * @author liuqing * @version 2.0 * 2011-3-8 * */ public abstract class HtmlDateboxTag extends AbstractUITag { protected String width; protected String height; protected String align; /* (non-Javadoc) * @see org.apache.struts2.views.jsp.ui.AbstractUITag#populateParams() */ @Override protected void populateParams() { super.populateParams(); HtmlBean html = (HtmlBean)this.component; html.setWidth(width); html.setHeight(height); html.setAlign(align); html.setDynamicAttributes(dynamicAttributes); } /** * @param width the width to set */ public void setWidth(String width) { this.width = width; } /** * @param height the height to set */ public void setHeight(String height) { this.height = height; } /** * @param align the align to set */ public void setAlign(String align) { this.align = align; } }
定义实现标签
package org.cxkj.struts2.views.jsp.ui;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.components.Component;
import org.cxkj.struts2.components.DateboxBean;
import com.opensymphony.xwork2.util.ValueStack;
/**
*
* @author liuqing
* @version 2.0
* 2011-3-8
*
*/
public class DateboxTag extends HtmlDateboxTag {
@Override
public Component getBean(ValueStack valueStack, HttpServletRequest request,
HttpServletResponse response) {
return new DateboxBean(valueStack,request,response);
}
}
定义freemarker 模板文件
<#--
/* * $Id: text.ftl 720258 2008-11-24 19:05:16Z musachy $ * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ --> <div style="margin:2px;text-align:<#rt/> <#if parameters.align??> ${parameters.align?html};"> <#rt/> </#if> <input type="text"<#rt/> name="${parameters.name?default("")?html}"<#rt/> class="easyui-datebox" <#rt/> <#if parameters.get("size")??> size="${parameters.get("size")?html}"<#rt/> </#if> <#if parameters.maxlength??> maxlength="${parameters.maxlength?html}"<#rt/> </#if> <#if parameters.nameValue??> value="<@s.property value="parameters.nameValue"/>"<#rt/> </#if> <#if parameters.disabled?default(false)> disabled="disabled"<#rt/> </#if> <#if parameters.readonly?default(false)> readonly="readonly"<#rt/> </#if> <#if parameters.tabindex??> tabindex="${parameters.tabindex?html}"<#rt/> </#if> <#if parameters.id??> id="${parameters.id?html}"<#rt/> </#if><#rt/> style="<#rt/> <#if parameters.width??> width:${parameters.width?html}px;<#rt/> <#else> width:160px;<#rt/> </#if><#rt/> <#if parameters.height??> height:${parameters.height?html}px;<#rt/> <#else> height:26px;<#rt/> </#if>" <#rt/> <#include "/${parameters.templateDir}/simple/css.ftl" /> <#if parameters.title??> title="${parameters.title?html}"<#rt/> </#if> <#include "/${parameters.templateDir}/simple/scripting-events.ftl" /> <#include "/${parameters.templateDir}/simple/common-attributes.ftl" /> <#include "/${parameters.templateDir}/simple/dynamic-attributes.ftl" /> /> </div>
添加tld 文件到WEB-INF目录下
OK<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"> <description><![CDATA["To make it easier to access dynamic data; the Apache Struts framework includes a library of custom tags. The tags interact with the framework's validation and internationalization features; to ensure that input is correct and output is localized. The Struts Tags can be used with JSP FreeMarker or Velocity."]]></description> <display-name>"Struts Tags"</display-name> <tlib-version>2.2.3</tlib-version> <short-name>sx</short-name> <uri>/struts-tags-cxkj</uri> <tag> <description><![CDATA[Execute an action from within a view]]></description> <name>datebox</name> <tag-class>org.cxkj.struts2.views.jsp.ui.DateboxTag</tag-class> <body-content>JSP</body-content> <attribute> <description><![CDATA[Whether the result of this action (probably a view) should be executed/rendered]]></description> <name>executeResult</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute> <attribute> <description><![CDATA[Whether the writer should be flush upon end of action component tag, default to true]]></description> <name>flush</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute> <attribute> <description><![CDATA[Deprecated. Use 'var' instead]]></description> <name>width</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute> <attribute> <description><![CDATA[Deprecated. Use 'var' instead]]></description> <name>height</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute> <attribute> <description><![CDATA[Deprecated. Use 'var' instead]]></description> <name>id</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute> <attribute> <description><![CDATA[Whether the request parameters are to be included when the action is invoked]]></description> <name>ignoreContextParams</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute> <attribute> <description><![CDATA[Name of the action to be executed (without the extension suffix eg. .action)]]></description> <name>name</name> <required>true</required> <rtexprvalue>false</rtexprvalue> </attribute> <attribute> <description><![CDATA[Namespace for action to call]]></description> <name>namespace</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute> <attribute> <description><![CDATA[Namespace for action to call]]></description> <name>value</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute> <attribute> <description><![CDATA[Namespace for action to call]]></description> <name>align</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute> <attribute> <description><![CDATA[Whether an exception should be rethrown, if the target action throws an exception]]></description> <name>rethrowException</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute> <attribute> <description><![CDATA[Name used to reference the value pushed into the Value Stack]]></description> <name>var</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute> <dynamic-attributes>false</dynamic-attributes> </tag> </taglib>
<%@taglib prefix="sx" uri="/struts-tags-cxkj" %> <sx:datebox name="umlj" width="400" height="80" align="right" value="%{'1008-10-23'}"> </sx:datebox>
评论
3 楼
mianhuaman
2014-01-20
可以放在webapp下不过那样就回到了原始标签的状态了用freemark 就没有真真的组件化了
2 楼
mianhuaman
2014-01-20
所有的freemark.ftl文件是放在src目录下的
你想想struts2 在webapp下有没有ftl文件。
以jar的形式发布不更好
你想想struts2 在webapp下有没有ftl文件。
以jar的形式发布不更好
1 楼
glyphvectory
2013-11-03
您好,看见你写的很乐观,不过我遇到一个问题,按你写的。
freemark的文件我放在那里了?我去设置了:默认目录,始终都不行都是:
/template/simple/cccc.ftl not found
我建了这个文件夹,放在。webapp下
能不能指教指教,谢谢
freemark的文件我放在那里了?我去设置了:默认目录,始终都不行都是:
/template/simple/cccc.ftl not found
我建了这个文件夹,放在。webapp下
能不能指教指教,谢谢
发表评论
-
struts2 注解参数配置
2012-04-15 21:08 4207author 刘庆 @Date 2010-10-2 ... -
Struts2 下载文件文名名中文问题
2012-02-10 11:23 956作者:liuqing strut.xml 文件配置 ... -
Struts2 <s:select 标答optgroup 的使用
2012-01-10 16:49 3731<s:select name="" ... -
Struts2 获得Servlet 对象
2011-12-28 13:08 1032@author liuqing @datetime 2010 ... -
Spring 与struts2 和Hibernate 4.0 + Dwr 注解解决方安
2011-12-11 17:39 36441. web.xml 注册文件 < ... -
Struts2 国际化
2011-10-01 14:01 1281作者:刘庆 struts2 在这里有观原理就不做介绍了哈 ... -
Struts s:property 标签的使用
2011-09-30 14:34 52761. <s:property value=&quo ... -
Struts 2 s:set 标签的使用
2011-09-29 16:12 12141@author liuqing 1. struts2 标签 ... -
Struts2 直接输出字符 type="stream"
2011-09-28 17:10 42391. 用json 不能解决的问题 有时我们用java ... -
freemark 学习笔记
2011-08-26 12:57 1367struts2 集成的 freemark 因为我们要自定义 ... -
自定义struts2 tag
2011-08-24 17:58 1866添加Bean对象 package com. ...
相关推荐
有对struts2标签和OGNL的总结。
本资源适合刚接触Struts和Ognl的小伙伴交流学习,欢迎吐槽。
Struts2 OGNL---标签详解析 都有实例 适合初学者
struts2的ognl
struts2标签使用例子 struts2标签使用例子 struts2标签使用例子struts2标签使用例子
Struts2的标签库及OGNL表达式语言
Struts2学习计划5---Struts2_OGNL(对象图导航语言)的学习
从官网checkout下来的源码,如果大家觉的区官网麻烦可以直接下载这个
struts2标签和OGNL表达式struts2标签和OGNL表达式
Struts2中ognl-2的源代码,从官网下载的
struts2 中 OGNL表达式的使用struts2 中 OGNL表达式的使用
-- 为修复struts2 s2-016、s2-017漏洞,重写DefaultActionMapper --> <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="myDefaultActionMapper" class=...
ognl与struts2_ognl
struts2中siterator 标签的使用详解 及 OGNL用法 struts2中siterator 标签的使用详解 及 OGNL用法
struts2中ognl表达式的用法,详细介绍了ognl表达式与struts2基本标签的结合。
主要是ognl的用法,很适合新手上路的,源代码很清晰可见,一看就懂
struts2中的OGNL struts2的新表单标志的使用 struts2与AJAX一 struts2与AJAX二 struts2与AJAX三 struts2中用Spring实现IOC struts2中的零配置与IOC struts2介绍之使用连接标签 struts2入门 struts2进阶学习一 struts...
整合多份struts2中关于ognl的学习资料
学习OGNL在Struts2中工作原理学习OGNL在Struts2中工作原理学习OGNL在Struts2中工作原理学习OGNL在Struts2中工作原理
struts2_ognl基本用法.docstruts2_ognl基本用法.docstruts2_ognl基本用法.docstruts2_ognl基本用法.docstruts2_ognl基本用法.docstruts2_ognl基本用法.docstruts2_ognl基本用法.docstruts2_ognl基本用法.docstruts2_...