Struts2 - 使用 OGNL 从静态列表字符串属性设置属性不起作用 [英] Struts2 - Setting a property from a static list String property using OGNL not working

查看:34
本文介绍了Struts2 - 使用 OGNL 从静态列表字符串属性设置属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 struts2 框架设置隐藏的输入值.输入值是一个不变的值,所以我想通过静态引用来设置它,而不是担心在控制器中的多个位置设置它.

这里是列表定义:

 包 com.packagename.models;公共类 UsernameModel 实现了 Serializable、Comparable{.../*** <P>预定义用户名类型的静态容器.*/公共静态最终类用户名类型{public static final String ALIAS = "别名";public static final String ASSIGN_NUM = "分配编号";}...}

我意识到这可能超出了问题的范围,但是当我尝试像这样引用隐藏输入中的属性时,它会引发异常:

<s:hidden name="username_type" value="<s:property value="@com.packagename.models.UsernameModel.UsernameTypes@ALIAS"/>"></s:隐藏>

<块引用>

org.apache.jasper.JasperException:/WEB-INF/content/user/profile.jsp(第 185 行,第 64 列)未终止的

如果我从 s:hidden 输入中删除属性标签,异常就会消失,但在别名"字符串应该出现的位置不会出现任何文本.

-- 提前致谢

解决方案

你不能嵌套这样的标签.并且要引用内部类,您需要使用 $ 符号.

IMO 最好在类中直接使用那种静态变量,而不是从 JSP 中发送它们.

I'm trying to set a hidden input value using the struts2 framework. The input value is an unchanging value, so I'd like to set it via a static reference rather than worrying about setting it possibly in multiple places in the Controller.

Here is the list definition:

     package com.packagename.models;
     public class UsernameModel implements Serializable, Comparable<UsernameModel> {

          ...
          /**
          * <P>A static container of the predefined username types.
          */
          public static final class UsernameTypes {
           public static final String ALIAS = "Alias";
           public static final String ASSIGN_NUM = "Assignment Number";
          }
          ...
      }

I realize that this may be out of the scope of the question, but when I try to reference the property inside the hidden input like so it throws an exception:

<s:hidden name="username_type" value="<s:property value="@com.packagename.models.UsernameModel.UsernameTypes@ALIAS" />"></s:hidden>

org.apache.jasper.JasperException: /WEB-INF/content/user/profile.jsp (line: 185, column: 64) Unterminated <s:hidden tag

If I remove the property tag from the s:hidden input the exception goes away but no text appears where the "Alias" string should be.

-- Thanks in advance

解决方案

You cannot nest tags like that. And to reference inner class you need to use $ sign.

<s:hidden name="username_type"
          value="%{@com.packagename.models.UsernameModel$UsernameTypes@ALIAS}" />

IMO it is better to use that kind of static variables directly in class rather than send them from JSP.

这篇关于Struts2 - 使用 OGNL 从静态列表字符串属性设置属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆