Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment:

Update formatting and nomenclature

...

To

...

access

...

the

...

ValueStack

...

from

...

third-party

...

JSP

...

taglibs,

...

expose

...

property

...

values

...

to

...

JSP

...

using

...

the

...

<saf:set

...

tag.

{:=
Code Block
xml:title
Set
a
request
scoped
parameter
'a'
to
list
of
integers
}
<saf:set name="'a'" value="{ 1, 2, 3, 4 }" scope="request"/>
{code}

After

...

setting

...

parameters,

...

third-party

...

JSP

...

taglibs

...

can

...

access

...

variables

...

or

...

use

...

JSP

...

2.0

...

EL

...

(Expression

...

Language).

...

This

...

is

...

convenient

...

as

...

short

...

hand

...

EL

...

expression

...

syntax

...


$

...

{expression}

can be used in a text or inside of tag attributes:

Code Block
xml
xml

}}
{{}}

 can be used in a text or inside of tag attributes:
{code:xml}
a[0] = ${a[0]}

<sample:tag value="${a[1]}"/>
{code}

In

...

practice,

...

several variables must be exposed to make effective use of third party taglibs like DisplayTag. Unfortunately, this approach leads to a lot of <ww:set/>

...

tags.

what made me investigate how to make access to ValueStack and OGNL more transparent. {note:title=Why
Note
titleWhy
can't
we
just
replace
EL
with
OGNL?
}

Unfortunately,

it

isn't

that

simple.

I've

we tinkered

with

{{

JSPFactory.setDefault()

}}

to

wrap

around

{{

getPageContext()

}}

and

create

{{

ExpressionEvaluator

}}

that

would

use

OGNL.

This

strategy works

in

practice,

but

code

generated

by

Jasper2

doesn't

call

{{

JSPFactory.getPageContext().getExpressionEvaluator()

}}

but

goes

directly

to

static

method

that

is

hardwired

to

Jakarta

Commons-EL

implementation.

Even

if it would work it

if this approach did work, it wouldn't

be

_

clean

_

as

{{

JSPFactory.setDefault()

}}

should

only

be

called

by

JSP

implementation.

{note}

There

...

is

...

a

...

simple,

...

if

...

not

...

elegant,

...

solution

...

available

...

in

...

JSP

...

2.0

...

EL,

...

for

...

exposing

...

ValueStack

...

to

...

OGNL.

...

It

...

is

...

possible

...

to

...

create

...

custom

...

functions

...

that

...

can

...

be

...

called

...

from

...

EL

...

expressions.

...

Functions

...

have

...

to

...

be

...

'public

...

static'

...

and

...

specified

...

in

...

a

...

TLD

...

file.

...


To

...

use

...

a

...

function,

...

import

...

the

...

TLD

...

in

...

a

...

JSP

...

file

...

where

...

you've

...

want

...

to

...

use

...

a

...

function.

...

For

...

example,

...

you

...

could

...

access

...

Action

...

properties

...

by

...

evaluating

...

OGNL

...

expression

...

by

...

a

...

function

...

'vs'

...

(for

...

valuestack)

...

in

...

EL.

Code Block
xml
xml

{code:xml}
<%@ taglib uri="/WEB-INF/tld/wwel.tld" prefix="x" %>

a[0] = ${x:vs('a[0]')}
a[0] * 4 = ${x:vs('a[0] * 4')}

Current action name: ${x:name()}
Top of ValueStack: ${x:top()}
{code}

To

...

use

...

this

...

code

...

you've

...

got

...

to

...

add

...

wwel.tld

...

and

...

Functions.java

...

to

...

your

...

webapp

...

project.

Tip
Help Wanted
Help Wanted

If someone were interested, it would be helpful for a developer (like you!) to define a set of functions that we could include in a future release of the framework.

Code Block
xml
xml
titlewwel.tld

I would urge webworkers to define a set of functions that would be usable to wide community and include this in some future Webwork release.
{code:xml|title=wwel.tld}
<?xml version="1.0"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
	version="2.0">

<description>
This taglib enables access to the ValueStack
from JSP 2.0 Expression Language
</description>

<tlib-version>1.0</tlib-version>

<short-name>wwel</short-name>

<function>
	<name>vs</name>
	<function-class>com.nmote.wwel.Functions</function-class>
	<function-signature>
		java.lang.Object findOnValueStack(java.lang.String)
	</function-signature>
</function>

<function>
	<name>name</name>
	<function-class>com.nmote.wwel.Functions</function-class>
	<function-signature>
		java.lang.Object getActionName()
	</function-signature>
</function>

<function>
	<name>top</name>
	<function-class>com.nmote.wwel.Functions</function-class>
	<function-signature>
		java.lang.Object getTopOfValueStack()
	</function-signature>
</function>

</taglib>
{code}
{code:java|title=
Code Block
java
java
titleFunctions.java
}
package com.nmote.wwel;

import com.opensymphony.xwork.ActionContext;

/**
 * Utility functions for accessing value stack and action context
 * from JSP 2.0 EL taglibs.
 */
public class Functions {

	public static Object findOnValueStack(String expr) {
		ActionContext a = ActionContext.getContext();
		Object value = a.getValueStack().findValue(expr);
		return value;
	}

	public static Object getTopOfValueStack() {
		ActionContext a = ActionContext.getContext();
		Object value = a.getValueStack().peek();
		return value;
	}

	public static Object getActionName() {
		ActionContext a = ActionContext.getContext();
		Object value = a.getName();
		return value;
	}
}
{code}