Using two struts2 taglibs in each other
I want to use two struts taglib 开发者_如何学Cin 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
you can also use
<s:property value="'url-'+'%{number}'"/>
Struts accepts OGNL expressions in the format %{yourAttribute}
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.
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"/>
精彩评论