views:

137

answers:

2

Hi

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

A: 

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.

leonbloy
Unfortunately the number is generated in an iterator.and when I use something like your second solution (as I wrote in my question), I got this error:"According to TLD or attribute directive in tag file, attribute values does not accept any expressions."
Milad.KH
Ah, OGNL is a pain... You have the "number" available in the value stack, so that `<s:property value="number"/>` outputs it ? Then, you might try with `<s:property value="buildUrlWithNumber(%{number})"/>` (or #number , I never remember)
leonbloy
A: 

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"/>
Milad.KH