1

このように割り当てられたSpring MVCのモデルオブジェクトにアクセスしようとしています

@RequestMapping(value = "{id}", method = RequestMethod.GET)
public String getMethod(@PathVariable Long id, Model model) {
     model.addAttribute("attrib", attribute);
}

カスタム タグ ライブラリの属性オブジェクトにアクセスしようとしています。コードは次のとおりです。

    @Override
    public void doTag() throws JspException {
        final JspWriter writer = getJspContext().getOut();
        try {
            attribute = (Attribute)
                    getJspContext().getAttribute("attrib");
            if (attribute != null) {
                System.out.print(attribute.getId());
            }
            writer.println("sandeep");

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

しかし、属性は常にnullになります。カスタムtaglibから属性オブジェクトにアクセスする方法を誰か教えてください

4

1 に答える 1

0

以下に示すように、ExpressionEvaluationUtils の evaluate メソッドを使用してみてください。

ExpressionEvaluationUtils.evaluate("", "attrib", this.pageContext);

ここで JavaDoc を参照してください: http://static.springsource.org/spring-framework/docs/3.2.0.M2/api/org/springframework/web/util/ExpressionEvaluationUtils.html

于 2013-02-04T15:20:06.240 に答える