Som" name="description" /> Som" />
70941

Variable in an attribute in Struts custom tag

Question:

I am trying to use a variable inside a custom Struts tag something like follows -

for(String currentMacro : (List<String>)(request.getAttribute("individualMacros"))) { name = currentMacro.<some-operation> <html:mce name = "hmtl_<%= name %>" />

Something like this. But <%=name%> is not replaced with the variable value. It works when I am using the variable with a pure HTML tags.

Is there any any way to accomplish this in this case?

Thanks.

Answer1:

Use JSP EL (assuming JSP 2.0, and you put "name" into scope). You could also check to the if the TLD allows rtexprs.

<html:mce name="html_${name}"/>

But why use scriptlets? There's rarely (ever?) a good reason.

Answer2:

Since we are taking about a custom tag, my guess is that in the <a href="http://java.sun.com/products/jsp/tutorial/TagLibraries9.html" rel="nofollow">TLD</a> file there isn't the rtexprvalue option set to true for that particular tag attribute:

<attribute> <name>name</name> <rtexprvalue>true</rtexprvalue> ....... </attribute>

The rtexprvalue specifies that the attribute value may be dynamically evaluated at runtime.

If set to "false" it means that the attribute has a static value which is evaluated at <a href="http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPIntro4.html" rel="nofollow">translation</a>; if set to "true" it means the value can be determined dynamically at runtime. Default is "false".

If the scriptlet does not work, it most likely means rtexprvalue is false. If you don't have the liberty to change that, then expressions won't work on that particular attribute.

Recommend

  • Process.StartTime Access Denied
  • Difficulties implementing the Hysteresis step of Canny Algorithm in Halide without define_extern fun
  • Using Python objects in C++
  • How to make Javascript generated checkboxes persist?
  • Avoiding dependencies is exploding the number of projects in my VS solution
  • How to exclude files in a custom clean task?
  • UI-GRID column summation on checkbox change
  • textIndicatorPrecision in dojox.dgauges using dojo
  • Replacing script src using jquery not executed
  • keeping track of nested ng-repeat index's
  • MySQL multiple IN conditions to subquery with same table
  • Using an STL Iterator without initialising it
  • CSS how to fix an element to scroll horizontally with the page but not vertically?
  • What is the reason that Policy.getPolicy() is considered as it will retain a static reference to the
  • Want to understand iframe breakout code
  • Is it possible to get the word under the mouse cursor in a ``?
  • Can my PDF ping my server when it is opened?
  • BeautifulSoup difference between findAll and findChildren
  • Two Tables Serving as one Model in Rails
  • NHibernate manually control fetching
  • Using $compile in a directive triggers AngularJS infinite digest error
  • Updating Dojo provide
  • C# fibonacci function returning errors
  • Approximate Order-Preserving Huffman Code
  • How to get current document uri in XSLT?
  • Convert Type Decimal to Hex (string) in .NET 3.5
  • What is the purpose of TaskExecutor in spring?
  • Is it possible to access block's scope in method?
  • AES padding and writing the ciphertext to a disk file
  • Updating server-side rendering client-side
  • How to extract text from Word files using C#?
  • ILMerge & Keep Assembly Name
  • Large data - storage and query
  • WOWZA + RTMP + HTML5 Playback?
  • SVN: Merging two branches together
  • bootstrap to use multiple ng-app
  • How to get icons for entities from eclipse?
  • Proper way to use connect-multiparty with express.js?
  • Load html files in TinyMce
  • JaxB to read class hierarchy