JSTL: Work with conditional statements

Hallo everybody!

I'd have the following question:

If I need to have a condition whithin my JSP, I can write, e.g.:

<c:if test="${pageContext.request.method=='POST'}">

Here I access some class variable, it is clear.

But what if a condition concerns a result of a method call on an object? E.g., I need to check if pageConfig.isReadonly("commodity_group")

is true or false?

Obvously, <c:if test="${pageConfig.isReadonly("commodity_group")}">

does not work.

I can't find a way to do it...

Andrew

[743 byte] By [Adry1a] at [2007-10-3 2:00:49]
# 1

There isn't a direct way in EL. EL can only call getters/setters.

It can not call any bean methods that take parameters

You can hack it a little if your pageConfig bean has two attributes instead of one.

public class PageConfig{

String field;

public String getField(){return field;}

public void setField(String field){this.field = field;}

public boolean isReadOnly(){ return isReadOnly(field) }

public boolean isReadOnly(String field){

//your implementation

}

}

And then

<c:set target="pageConfig" property="field" value="commodity_group"/>

<c:if test="${pageConfig.readOnly}">

...

</c:if>

An alternative in an EL container is to use a custom function.

evnafetsa at 2007-7-14 18:59:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...