【问题标题】:Get value of a property inside jstl tag获取jstl标签内的属性值
【发布时间】:2014-07-02 12:07:18
【问题描述】:

我正在开发一个简单的标签库,以便集中创建表单组件。

在我的自定义标签中,我需要获取支持对象映射字段的值。

这是我将字段名称值传递给我的库的方式:

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

在我的标签库中,使用 spring 标签库中的&lt;form:hidden path="${field}.id" /&gt; 是可行的,但是不使用该库如何获得相同的值?我不想在我的表单中隐藏映射的输入类型,而只想检索该字段名称的值。

感谢任何提示。

【问题讨论】:

    标签: java spring spring-mvc jstl spring-tld


    【解决方案1】:

    你可以试试 spring:eval 标签

      <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]" />
    

    【讨论】:

    • 不行..Value变量文本值是gas.id,不是真实id
    • 这应该可行 :) +1 你认为不指定对象是否可行?
    • 不,我认为不指定对象是不可能的。看看 Spring Roo,它做了你想做的事:使用标签库来简化表单创建。 docs.spring.io/spring-roo/reference/html/…
    • 是从roo开始修改标签库的:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-27
    • 1970-01-01
    • 2020-11-27
    • 2010-09-10
    相关资源
    最近更新 更多