ognl

Strange OGNL behaviour when using #this in s:select

拟墨画扇 提交于 2020-01-14 14:26:48
问题 Consider the following where availableExclusions is an array of Date objects. <s:select listValue="(new java.text.SimpleDateFormat('MM/dd/yyyy')).format(new java.util.Date(#this[0].time))" size="25" id="inputExclusionDates" name="available" list="availableExclusions" multiple="true" cssClass="multi-select" /> I created the above in response to this question How would I format a list of dates within a struts 2 select tag? (and I also recommended that the other solution may be the better way to

How to include HTML in OGNL expression language in Struts 2

雨燕双飞 提交于 2020-01-14 02:48:21
问题 I am working on struts 2. I was doing a projection of a collection in my JSP page using OGNL expression language. I have 1 list based collection in my action class, that I am accessing on JSP page like this: <s:iterator value="lsEmp.{name + '<b>---</b>' + address}"> //lsEmp is a list based collection <s:property /><br> </s:iterator> I want the output like this: rajiv --- N.Delhi nakul --- Mumbai vinay --- Banglore //"---" being bold . But my <b></b> tag in <s:iterator value=""> is not getting

Prevent getText() evaluating EL expressions

血红的双手。 提交于 2020-01-14 01:36:23
问题 In Struts2 backend, I have an action class instance variable, eg: keyName . A dynamic key returned to view(JSP). This keyName variable is set using a request parameter using POST method. Depending on the request parameter value, the keyName will vary. In JSP, I am using <s:property value="getText(keyName)" /> to show the label corresponding to the key given by keyName variable. When I send an EL expression for example ${90-40} to keyName this expression is being evaluated and resulting in

How to test bean property in Struts 2?

雨燕双飞 提交于 2020-01-13 19:36:50
问题 I have a class like this: public class Foo { public boolean isValid() { return false; } } In my JSP file I want to use the isValid method in a test condition: <s:bean name="com.Foo" var="bar"></s:bean> <s:if test="%{bar.valid == false}"> <p>hello</p> </s:if> but it doesn't work. What did I do wrong? 回答1: Context variables are referenced by # , but you've used a name bar without number sign. <s:if test="%{#bar.valid == false}"> <p>hello</p> </s:if> Look at the Variable References of the OGNL

How to test bean property in Struts 2?

こ雲淡風輕ζ 提交于 2020-01-13 19:35:35
问题 I have a class like this: public class Foo { public boolean isValid() { return false; } } In my JSP file I want to use the isValid method in a test condition: <s:bean name="com.Foo" var="bar"></s:bean> <s:if test="%{bar.valid == false}"> <p>hello</p> </s:if> but it doesn't work. What did I do wrong? 回答1: Context variables are referenced by # , but you've used a name bar without number sign. <s:if test="%{#bar.valid == false}"> <p>hello</p> </s:if> Look at the Variable References of the OGNL

To access the index value of struts iterator in scriptlet array index

三世轮回 提交于 2020-01-13 09:55:07
问题 I am a newbie in web development. Using Struts2, I have a comma separated String of my images captions. While iterating the images to render on JSP I need to display caption along with specific images and could not get any specific tag to split caption String over delimiter and to access specific caption. I am trying the below code and don't know what to use in place of something to get the current iteration index in iterator. <s:iterator value="images" status="incr"> <%= ((String)request

“Select” not populated from List<String> in struts

混江龙づ霸主 提交于 2020-01-11 10:13:13
问题 I have the following sources: struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> <constant name="struts.devMode" value="true" /> <constant name="struts.custom.i18n.resources" value="ApplicationResources" /> <package name="vislabWebShop" extends="struts-default"> <action name=

“Select” not populated from List<String> in struts

試著忘記壹切 提交于 2020-01-11 10:11:59
问题 I have the following sources: struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> <constant name="struts.devMode" value="true" /> <constant name="struts.custom.i18n.resources" value="ApplicationResources" /> <package name="vislabWebShop" extends="struts-default"> <action name=

el表达式跟ognl表达式的区别

本秂侑毒 提交于 2020-01-09 20:20:21
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 1.区别 用法区别: OGNL是通常要结合Struts 2的标志一起使用,如<s:property value="#xx" /> struts页面中不能单独使用,el可以单独使用 ${sessionScope.username} 页面取值区别: 用于按request > session > application顺序访问其属性(attribute) #attr.userName相当于按顺序在以上三个范围(scope)内读取userName属性,直到找到为 2.ognl讲解 OGNL 是 Struts 2默认的表达式语言。是Object Graphic Navigation Language(对象图导航语言)的缩写,它是一个开源项目。 1.#符号的用途一般有三种。 1)访问非根对象属性,例如示例中的#session.msg表达式,由于Struts 2中值栈被视为根对象,所以访问其他非根对象时,需要加#前缀。实际上 ,#相当于ActionContext.getContext(); ;#session.msg表达式相当于ActionContext.getContext().getSession(). getAttribute(”msg”) 。 2)用于过滤和投影(projecting)集合,如示例中的persons.

struts2的OGNL表达式

这一生的挚爱 提交于 2020-01-09 20:20:10
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 一、 sturts2OGNL表达式,即 Object Graph Navigation Language,对象图形化导航语言。是一门方便操作对象属性的表达式语言。具有以下特点: 1、支持对象方法调用和值的访问。如user.getUsername(),#user.name 2、支持赋值和计算操作。如 price = 100,num = 2,则caculatePrice()值为200 3、支持访问OGNL上下文(OGNL context)和ActionContext 4、支持对集合对象的操作 二、OGNL表达式的使用 OGNL常和Struts2标签结合使用,非常灵活,可以用 "%"、"#"、"$"来操作。 1、#的使用方式,#相当于ActionContext.getContext(); #request.username 相当于 request.getAttribute("username"); #session.username 相当于 session.getAttribute("username"); #application.username相当于 application.getAttribute("username"); #还可以用于构造map:如#{"1","a","2","b","3","c"} 2、%