javaspringspring-mvcjstlspring-tld

Get value of a property inside jstl tag


I'm developing a simple tag library in order to centralize the creation of form components.

In my custom tag I need to get the value of the backing object mapped field.

Here is how I pass the field name value to my library:

<jsp:directive.attribute name="field" type="java.lang.String" required="true" rtexprvalue="true" description="The field exposed from the form backing object" />

Inside my tag library, using <form:hidden path="${field}.id" /> from spring tag library works, but how can I get same value not using that library? I do not want to have an input type hidden mapped in my form, but only retrieve the value of that field name.

Thanks for any hints.


Solution

  • You can try the spring:eval tag

      <jsp:directive.attribute name="object" type="java.lang.Object" required="true" description="The form backing object" />
      <jsp:directive.attribute name="field" type="java.lang.String" required="true" description="The field name" />
    
      <spring:eval expression="object[field]" />