日期:2014-05-16 浏览次数:20423 次
import java.io.IOException; import java.lang.reflect.Field; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.TagSupport; public class RFTag extends TagSupport { private static final long serialVersionUID = -2360561035810220875L; private Object object; private String property; public Object getObject() { return object; } public void setObject(Object object) { this.object = object; } public String getProperty() { return property; } public void setProperty(String property) { this.property = property; } public int doStartTag() throws JspException { JspWriter out = this.pageContext.getOut(); try { if (object == null) { out.println(""); } else { //get the object of this field Field f = object.getClass().getDeclaredField(property); f.setAccessible(true); //get the value of this field Object value = f.get(object); out.println(value == null ? "" : value.toString()); } } catch (IOException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return SKIP_BODY; } }
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "web-jsptaglibrary_1_2.dtd" > <taglib> <tlib-version>1.0</tlib-version> <jsp-version>2.0</jsp-version> <short-name>foundTag</short-name> <uri>http://www.foundersoftware.com/founder/tags</uri> <tag> <name>page</name> <tag-class>com.founder.abgent.core.web.tag.PageTag</tag-class> <attribute> <name>action</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>param</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>color</name> <required>false</required> </attribute> </tag> <tag> <name>rf</name> <tag-class>com.founder.bcimp.core.web.tag.RFTag</tag-class> <attribute> <name>object</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>property</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> </taglib>
<%@ page language="java" contentType="text/html; charset=UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://www.foundersoftware.com/founder/tags" prefix="fs"%> <div> <c:if test="${not empty enterpriseCustomFieldList}"> <table> <tr> <td colspan="2"><fmt:message key="crs.compound.enterprise.custom.field" /></td> </tr> <c:forEach items="${enterpriseCustomFieldList}" var="enterpriseCustomField"> <tr> <th>${enterpriseCustomField.columnLabel }</th> <td><input type="text" name="${enterpriseCustomField.columnName}" maxlength="${enterpriseCustomField.length}" v