博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于Struts2.0 标签中采用%{} 的处理原理
阅读量:2455 次
发布时间:2019-05-10

本文共 2435 字,大约阅读时间需要 8 分钟。

 项目中采用struts2.0时,常常使用计算表单式的处理源码原理解析:

例如:

 <s:set var="hasDeductAmount" value =" %{bill.supplier.moneyPool>#amount?#amount:bill.supplier.moneyPool}"> </s:set>

上面的绿色为:value中值的表达式表示的值栈表达式为:去除%{}的表达式

bill.supplier.moneyPool>#amount?#amount:bill.supplier.moneyPool
备注: (1)原理看下面的源代码即可理解:
           (2)#表示OGNL的表达式
 
<input name="billCon.amount" type="text" class="inputbg" value="<s:property value='#hasDeductAmount'/>" />

Struts2.0中的每一个标签的都是以组件形式展示:

Component源代码如下:

 

/**     * Finds a value from the OGNL stack based on the given expression.     * Will always evaluate expr against stack except when expr     * is null. If altsyntax (%{...}) is applied, simply strip it off.     *     * @param expr  the expression. Returns null if expr is null.     * @return the value, null if not found.     */    protected Object findValue(String expr) {        if (expr == null) {            return null;        }        //获取OGNL的表达式        expr = stripExpressionIfAltSyntax(expr);        //从值栈获取表达式的数据对象        return getStack().findValue(expr, throwExceptionOnELFailure);    }     /**     * If altsyntax (%{...}) is applied, simply strip the "%{" and "}" off.      * @param expr the expression (must be not null)     * @return the stripped expression if altSyntax is enabled. Otherwise     * the parameter expression is returned as is.     */ protected String stripExpressionIfAltSyntax(String expr) {  return stripExpressionIfAltSyntax(stack, expr); }     /**     * If altsyntax (%{...}) is applied, simply strip the "%{" and "}" off.     * @param stack the ValueStack where the context value is searched for.      * @param expr the expression (must be not null)     * @return the stripped expression if altSyntax is enabled. Otherwise     * the parameter expression is returned as is.     */ public static String stripExpressionIfAltSyntax(ValueStack stack, String expr) {  if (altSyntax(stack)) {            // does the expression start with %{ and end with }? if so, just cut it off!            if (expr.startsWith("%{") && expr.endsWith("}")) {                return expr.substring(2, expr.length() - 1);            }        }  return expr; }

 转自:

 

HTML标签的属性可以被赋值为一个静态的值或一个OGNL表达式。如果你在赋值时使用了一个OGNL表达式并把它用"%{"和"}"括了起来,这个表达式将会被求值。

比如,

      1、下面的label属性将被赋值字符串“useName”:

           label="useName"

      2、而下面这个表达式使用了一个OGNL表达式userName,label属性的值将等于某一个动作类中的userName属性值:

           label="%{useName}"

       3、下面这个表达式将把label属性赋值为会话属性userName的值:

           label="%{#session.userName}"

       4、这个value属性将被赋值为6:

           value="%{1 + 5}"

转载地址:http://abdhb.baihongyu.com/

你可能感兴趣的文章
开源项目是什么_在开源项目之前要了解什么
查看>>
项目中最困难的部分_微服务最难的部分是什么? 您的资料
查看>>
公众号后台接管技术支持_哪些技术有望接管开源?
查看>>
只想在老家找份工作很难吗_当您只想完成工作时,为什么公开工作会很困难
查看>>
vco为什么低频下起振困难_为什么开放如此困难?
查看>>
tar.gz文件怎么解压缩_如何解压缩tar.gz文件
查看>>
雨果vs.杰基尔:比较领先的静态网站生成器
查看>>
网络监控工具 开源_在不到一个月的时间内,我如何使用开源工具成为网络漫画家
查看>>
git 代理 git_生日快乐,Git
查看>>
会议指南二维码生成_包装和准备技术会议的指南
查看>>
3d打印机打印obj格式_购买3D打印机如何为您省钱
查看>>
某软件公司绩效考核绩效考核_我们(认为我们)对绩效考核所了解的
查看>>
linux开源软件_为什么要使用Linux和开源软件?
查看>>
您第一次上网的速度是多少?
查看>>
java图形界面重写坐标_重写自由软件和计算机图形的历史
查看>>
如何在Raspberry Pi上安装Fedora 25
查看>>
自动化脚本上传图片怎么办_一切都自动化后我们将怎么办?
查看>>
spark运行pi_如何使用甜蜜的橙色Pi起床并运行
查看>>
r语言中的shiny教程_如何使用Shiny在R中编写Web应用程序
查看>>
技术社区_如何加入技术社区
查看>>