views:

13

answers:

1

Hi,

I have a usecase where I want to set the value of a field which I keep in the session and have added to the . I keep 'myModel' in flowScope

Now I would like to set a String property of object myModel if it is empty, so I want to do something like this:

<on-render>
    <evaluate expression="if empty(flowScope.myModel.name)) 
           flowScope.myModel.name = myModel.suggestName()" />
</on-render>

where suggestName() is an instance-method of the class of myModel which returns a string SPEL tells me the following when evaluating the expression:

EL1041E:(pos 3): After parsing a valid expression,
there is still more data in the expression: 'empty'

So i guess SPEL does not know the function 'empty' like standard EL does (e.g. check for an empty string)

In the spring manual (6.5.9 Functions) I read that I could register my own functions. That way I could register an emptyString function and delegate it StringUtils.isEmpty()

How would I do that? Is it the right approach? I can read in the web-flow manual how to register an expressionParser implicitly but how to actually add the function to the StandardEvaluationContext is a mystery to me.

Any help is appreciated

+1  A: 

You should be able to execute methods on a String object, so try flowScope.myModel.name.isEmpty() or flowScope.myModel.name.length() == 0

If that fails flowScope.myModel.name == "" will have the same effect.

Stephen C
thanks, the == "" was so obvious :)
Hans Westerbeek