Milad.KH
Milad.KH

Reputation: 11

Using two struts2 taglibs in each other

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

Answers (3)

Deepu
Deepu

Reputation: 21

you can also use

<s:property value="'url-'+'%{number}'"/>

Struts accepts OGNL expressions in the format %{yourAttribute}

Upvotes: 2

Milad.KH
Milad.KH

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

leonbloy
leonbloy

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

Related Questions