Reputation: 11
I want to use two struts taglib in each other, something like this:
< s:property value="url-< s:property value="number"/>"/>
or
< s:property value="url-${number}"/>
but I got the following error in the second one:
According to TLD or attribute directive in tag file, attribute values does not accept any expressions.
Anybody has a solution ?
Thanks
Upvotes: 0
Views: 1036
Reputation: 21
you can also use
<s:property value="'url-'+'%{number}'"/>
Struts accepts OGNL expressions in the format %{yourAttribute}
Upvotes: 2
Reputation: 11
The Solution was too easy!
As our friend leonbloy said, number is now in value stack when it generated in an iterator. so I should just write it's name:
<s:property value="url-number"/>
Upvotes: 0
Reputation: 75986
If the "number
" value is fixed (at the moment of the jsp generation; i.e., it is not set in the jsp, or changed in an iterator), you'd better refactor it to a method in your action. For example, if the "number
" is a property in your action:
public String getUrlWithNumber() {
return "url-" + String.valueOf(getNumber());
}
<s:property value="urlWithNumber"/>
elsewhere you could try something as (untested)
public String buildUrlWithNumber(int number) {
return "url-" + String.valueOf(number);
}
<s:property value="buildUrlWithNumber(${number})"/>
or something like that.
Upvotes: 0