首页 > Oracle融合中间件 > 如何在ADF Faces中使用JSTL函数

如何在ADF Faces中使用JSTL函数

概述

在ADF页面中,我们不可避免的会对数据库的数据根据相应的业务进行格式化,很多情况下我们可以通过使用JSTL函数来进行简易的处理。

实现

1. 在页面的头上加上

xmlns:fn="http://java.sun.com/jsp/jstl/functions"

Image[4]

2. 选择安装JSP标签库

Image(1)[4]

3.选择JSP库

Image(2)[4]

4.在页面中使用JSTL表达式了

例如:

   1: <af:column sortProperty="FirstName" sortable="false"

   2:            headerText="#{bindings.EmployeesVO1.hints.FirstName.label}"

   3:            id="c10">

   4:   <af:outputText value="#{row.FirstName}  #{fn:substring(row.FirstName,1,3)}" id="ot3"/>

   5: </af:column>

Fuction类源码:

   1: /*

   2:  * The contents of this file are subject to the terms

   3:  * of the Common Development and Distribution License

   4:  * (the "License").  You may not use this file except

   5:  * in compliance with the License.

   6:  *

   7:  * You can obtain a copy of the license at

   8:  * glassfish/bootstrap/legal/CDDLv1.0.txt or

   9:  * https://glassfish.dev.java.net/public/CDDLv1.0.html.

  10:  * See the License for the specific language governing

  11:  * permissions and limitations under the License.

  12:  *

  13:  * When distributing Covered Code, include this CDDL

  14:  * HEADER in each file and include the License file at

  15:  * glassfish/bootstrap/legal/CDDLv1.0.txt.  If applicable,

  16:  * add the following below this CDDL HEADER, with the

  17:  * fields enclosed by brackets "[]" replaced with your

  18:  * own identifying information: Portions Copyright [yyyy]

  19:  * [name of copyright owner]

  20:  *

  21:  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.

  22:  *

  23:  * Portions Copyright Apache Software Foundation.

  24:  */ 

  25:  

  26: package org.apache.taglibs.standard.functions;

  27:  

  28: import java.lang.reflect.Array;

  29: import java.util.Collection;

  30: import java.util.Enumeration;

  31: import java.util.Iterator;

  32: import java.util.Map;

  33: import java.util.StringTokenizer;

  34:  

  35: import javax.servlet.jsp.JspTagException;

  36:  

  37: import org.apache.taglibs.standard.resources.Resources;

  38: import org.apache.taglibs.standard.tag.common.core.Util;

  39:  

  40: /**

  41:  * <p>JSTL Functions</p>

  42:  * 

  43:  * @author Pierre Delisle

  44:  */

  45:  

  46: public class Functions {

  47:  

  48:     //*********************************************************************

  49:     // String capitalization

  50:  

  51:     /**

  52:      * Converts all of the characters of the input string to upper case.

  53:      */

  54:     public static String toUpperCase(String input) {

  55:         return input.toUpperCase();

  56:     }

  57:  

  58:     /**

  59:      * Converts all of the characters of the input string to lower case.

  60:      */

  61:     public static String toLowerCase(String input) {

  62:         return input.toLowerCase();

  63:     }

  64:     

  65:     //*********************************************************************

  66:     // Substring processing

  67:     

  68:     public static int indexOf(String input, String substring) {

  69:         if (input == null) input = "";

  70:         if (substring == null) substring = "";

  71:         return input.indexOf(substring);

  72:     }    

  73:  

  74:     public static boolean contains(String input, String substring) {

  75:         return indexOf(input, substring) != -1;

  76:     }    

  77:  

  78:     public static boolean containsIgnoreCase(String input, String substring) {

  79:         if (input == null) input = "";

  80:         if (substring == null) substring = "";        

  81:         String inputUC = input.toUpperCase();

  82:         String substringUC = substring.toUpperCase();

  83:         return indexOf(inputUC, substringUC) != -1;

  84:     }    

  85:  

  86:     public static boolean startsWith(String input, String substring) {

  87:         if (input == null) input = "";

  88:         if (substring == null) substring = "";

  89:         return input.startsWith(substring);

  90:     }    

  91:         

  92:     public static boolean endsWith(String input, String substring) {

  93:         if (input == null) input = "";

  94:         if (substring == null) substring = "";

  95:         int index = input.indexOf(substring);

  96:         if (index == -1) return false;

  97:         if (index == 0 && substring.length() == 0) return true;

  98:         return (index == input.length() - substring.length());

  99:     }  

 100:     

 101:     public static String substring(String input, int beginIndex, int endIndex) {

 102:         if (input == null) input = "";

 103:         if (beginIndex >= input.length()) return "";

 104:         if (beginIndex < 0) beginIndex = 0;

 105:         if (endIndex < 0 || endIndex > input.length()) endIndex = input.length();

 106:         if (endIndex < beginIndex) return "";

 107:         return input.substring(beginIndex, endIndex);

 108:     }    

 109:     

 110:     public static String substringAfter(String input, String substring) {

 111:         if (input == null) input = "";

 112:         if (input.length() == 0) return "";

 113:         if (substring == null) substring = "";

 114:         if (substring.length() == 0) return input;

 115:         

 116:         int index = input.indexOf(substring);

 117:         if (index == -1) {

 118:             return "";

 119:         } else {

 120:             return input.substring(index+substring.length());

 121:         }

 122:     }    

 123:         

 124:     public static String substringBefore(String input, String substring) {

 125:         if (input == null) input = "";

 126:         if (input.length() == 0) return "";

 127:         if (substring == null) substring = "";

 128:         if (substring.length() == 0) return "";

 129:  

 130:         int index = input.indexOf(substring);

 131:         if (index == -1) {

 132:             return "";

 133:         } else {

 134:             return input.substring(0, index);

 135:         }

 136:     }    

 137:  

 138:     //*********************************************************************

 139:     // Character replacement

 140:     

 141:     public static String escapeXml(String input) {

 142:         if (input == null) return "";

 143:         return Util.escapeXml(input);

 144:     }

 145:     

 146:     public static String trim(String input) {

 147:         if (input == null) return "";

 148:         return input.trim();

 149:     }    

 150:  

 151:     public static String replace(

 152:     String input, 

 153:     String substringBefore,

 154:     String substringAfter) 

 155:     {

 156:         if (input == null) input = "";

 157:         if (input.length() == 0) return "";

 158:         if (substringBefore == null) substringBefore = "";

 159:         if (substringBefore.length() == 0) return input;

 160:                 

 161:         StringBuffer buf = new StringBuffer(input.length());

 162:         int startIndex = 0;

 163:         int index;

 164:         while ((index = input.indexOf(substringBefore, startIndex)) != -1) {

 165:             buf.append(input.substring(startIndex, index)).append(substringAfter);

 166:             startIndex = index + substringBefore.length();

 167:         }

 168:         return buf.append(input.substring(startIndex)).toString();

 169:     }

 170:     

 171:     public static String[] split(

 172:     String input, 

 173:     String delimiters) 

 174:     {

 175:         String[] array;

 176:         if (input == null) input = "";

 177:         if (input.length() == 0) {

 178:             array = new String[1];

 179:             array[0] = "";

 180:             return array;

 181:         }

 182:         

 183:         if (delimiters == null) delimiters = "";

 184:  

 185:         StringTokenizer tok = new StringTokenizer(input, delimiters);

 186:         int count = tok.countTokens();

 187:         array = new String[count];

 188:         int i = 0;

 189:         while (tok.hasMoreTokens()) {

 190:             array[i++] = tok.nextToken();

 191:         }

 192:         return array;

 193:     }        

 194:         

 195:     //*********************************************************************

 196:     // Collections processing

 197:     

 198:     public static int length(Object obj) throws JspTagException {

 199:         if (obj == null) return 0;  

 200:         

 201:         if (obj instanceof String) return ((String)obj).length();

 202:         if (obj instanceof Collection) return ((Collection)obj).size();

 203:         if (obj instanceof Map) return ((Map)obj).size();

 204:         

 205:         int count = 0;

 206:         if (obj instanceof Iterator) {

 207:             Iterator iter = (Iterator)obj;

 208:             count = 0;

 209:             while (iter.hasNext()) {

 210:                 count++;

 211:                 iter.next();

 212:             }

 213:             return count;

 214:         }            

 215:         if (obj instanceof Enumeration) {

 216:             Enumeration enum_ = (Enumeration)obj;

 217:             count = 0;

 218:             while (enum_.hasMoreElements()) {

 219:                 count++;

 220:                 enum_.nextElement();

 221:             }

 222:             return count;

 223:         }

 224:         try {

 225:             count = Array.getLength(obj);

 226:             return count;

 227:         } catch (IllegalArgumentException ex) {}

 228:         throw new JspTagException(Resources.getMessage("FOREACH_BAD_ITEMS"));        

 229:     }      

 230:  

 231:     public static String join(String[] array, String separator) {

 232:         if (array == null) return "";         

 233:         if (separator == null) separator = "";

 234:         

 235:         StringBuffer buf = new StringBuffer();

 236:         for (int i=0; i<array.length; i++) {

 237:             buf.append(array[i]);

 238:             if (i < array.length-1) buf.append(separator);

 239:         }

 240:         

 241:         return buf.toString();

 242:     }

 243: }

 244:  

 245:  

 

 

关于作者:

昵称:dick.luo
档案信息:本人罗昌辉,英文名为Dick,目前就职于上海汉得信息技术股份有限公司中间件事业部,担任中间件技术顾问,专注于Oracle融合中间件产品在企业中的应用以及二次开发。
联系方式:你可以通过changhui.luo@gmail.com联系作者
点击查看dick.luo发表过的所有文章...
本文永久链接: http://blog.retailsolution.cn/archives/3013

 

 

对本文的评价:

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

 

 

  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
您必须在 登录 后才能发布评论.