English 中文(简体)
作为共同财产,通过共同财产法
原标题:Passing a enum value as a tag attribute in JSP

我有一套习惯的SAP标签,正使用一个直径。 这种做法是使用需要这一列举的其他类别的结果。 问题在于,我不知道如何在EL中分配一个总价值:

<mytaglib:mytag enumParam="${now what do I type here?}" />

我迄今发现的唯一工作是使大巴拉姆成为一种愤怒,并将其转化为理想的价值:

<mytaglib:mytag enumParam="3" />

I believe there must be a better way to do it. Please help.

最佳回答

EL allows the use of Enums!

There are three ways to set a tag attribute value using either an rvalue or lvalue expression:
[..]

仅有案文:

<some:tag Value=“hutext”/>

这一表述称为字面表达。 在这种情况下,属性价值被胁迫为属性的预期类型。 限定值的表述有特别的同税规则。 See Literal expressions for more information. 当某一方的归属具有重大类型时,必须用字面表示。 例如,标签可使用“手法”一词指苏伊特语。 字面被胁迫到苏伊特,属地得到价值。

rel=“nofollow noreferer” http://download.oracle.com/javaee/5/tutorial/doc/bnahq.html

http://www.ohchr.org。

public Enum Color{ 
   RED, BLUE, GREEN 
}

<>strong>JSP/ Tag file

<mytaglib:mytag enumParam="${ RED }" />

同Tomcat 7.0.22和Jety 6.1.26进行了测试。

问题回答

EL不支持进入Enums。 您应考虑使用方言。

<>>Example:

public Enum Color{ 
   READ, BLUE, GREEN 
}

您可以向您的习俗界转达如下:

<mytaglib:mytag enumParam="RED" />
OR
<mytaglib:mytag enumParam="${obj.color}" />

在你们的习俗中,你获得了这样的巨大价值:

Color.valueOf("RED");




相关问题
Finding the Highest Value in an Enumeration

I m writing a method which determines the highest value in a .NET enumeration so I can create a BitArray with one bit for each enum value: pressedKeys = new BitArray(highestValueInEnum<Keys>());...

Conversion of Enum to Enumerable

To convert Enum to Enumerable ,I use public enum Flags { Trivial=1, Minor, Major, Critical } IEnumerable<int> n = Enumerable.Range((int)Flags.Trivial, (...

Subclass check, is operator or enum check

A couple of friends was discussing the use of inheritance and how to check if a subclass is of a specific type and we decided to post it here on Stack. The debate was about if you should implement a ...

Enum scoping issues

I try to keep things as local as possible, so I put enums at class scope, even if they are shared between two classes (I put it in the class that "goes better" with it.) This has worked out great, but ...

How do I sort enum members alphabetically in Java?

I have an enum class like the following: public enum Letter { OMEGA_LETTER("Omega"), GAMMA_LETTER("Gamma"), BETA_LETTER("Beta"), ALPHA_LETTER("Alpha"), private final String ...

C++ enum value initialization

I have an enum declared in my code as: enum REMOTE_CONN { REMOTE_CONN_DEFAULT = 0, REMOTE_CONN_EX_MAN = 10000, REMOTE_CONN_SD_ANNOUNCE, REMOTE_CONN_SD_IO, REMOTE_CONN_AL, ...

WCF: Enforce equal DataContracts on both sides

I m wondering if it is possible to have WCF make sure that the DataContracts on both sides of a connection are exactly the same (and throw an exception when trying to connect if they are not). For ...

热门标签