包装带有自定义标签的Spring MVC选择标签时出现IlleagalStateException [英] IlleagalStateException when wrapping spring mvc select tag with custom tag

查看:233
本文介绍了包装带有自定义标签的Spring MVC选择标签时出现IlleagalStateException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本问题
在编写自己的自定义JSP标记以包装"春季MVC表单标记时,我遇到了一个问题.我已经成功包装了其他标签,但未与select和options标签卡在一起,这引发了IlleagalStateException.我调试了Spring代码,发现options标签寻找祖先选择标签.我正在使用标签文件执行此操作,因此spring select标签实际上位于其他标签文件中.我想这就是为什么找不到它的原因.

Basic problem
I've come across a bit of a problem while writing my own custom JSP tags to "wrap" the spring MVC form tags. I've wrapped other tags successfully but come unstuck with the select and options tags, this throws an IlleagalStateException. I've debugged the spring code and found that the options tag looks for an ancestor select tag. I'm doing this with tag files so the spring select tag is actually in a different tag file. I guess that's why it doesn't find it.

所以问题是我该怎么做才能解决这个问题?

So the questions is what can I do to get round this?

可能的解决方案
我曾尝试寻找解决方案,但发现所有其他人也遇到相同的问题,但都未发布解决方案.我曾考虑过不使用spring标签编写自己的select和options标签,但我真的不想复制它免费提供给您的绑定.我不介意更改为使用Java类而不是标记文件,但是我之前发现输出不会被评估为JSP,因此您无法输出其他JSP标记.

Possible solutions
I've tried looking for solutions but all I've found is other people having the same problem but no solution posted. I did ponder writing my own select and options tags without using the spring tags but I don't really want to have to replicate the binding that it gives you for free. I don't mind changing to use Java classes rather than tag files but I found previously that the output won't be evaluated as a JSP so you can't output another JSP tag.

这样做的原因
自从首次提出问题以来已经考虑了一周,现在我对要实现的目标更加清楚.

Reasons for doing this
Having thought about this for a week since first asking the question I am now clearer on what I want to achieve.

  • 为简化我的JSP中所需的标记
  • 编写通用代码(例如,form:输入后出错或从spring:message获得翻译)
  • 封装外观(CSS很长一段时间,但是通常您也需要更改标记)
  • 为了能够构建增强组件以扩展spring标签的功能(例如,将多选呈现为选择列表或将只读输入显示为文本标签)

我会很想听听人们的想法. 谢谢

I'll be interested to hear what people think. Thanks

推荐答案

我已经考虑了好一个星期,这是候选清单:

I've thought about this for a good week now and this is the shortlist:

  • 放弃并直接在我的JSP中使用spring标记
  • 完全不使用spring标签,并在我自己的标签中复制其逻辑
  • 可能会编写一个扩展或利用spring标记类的标记类
  • 扩展标签的范围,以包装选择标签和选项标签

鉴于要执行此操作的原因(我现在在问题中已经对此进行了澄清),我决定选择最后一个选项.我最初并不热衷于此,因为我认为我可能会获得数百个参数,但实际上还不错.标记文件旨在包装标记的通用位,所以这就是它们的用途.我还包装了自己的标签,因此有一个选择列表标签,该标签输出我的自定义选择标签,然后编写初始化它所需的JS.

Given the reasons for wanting to do this (which I have now clarified in the question), I've decided to go for the last option. I wasn't keen on this originally because I thought I might end up with hundreds of parameters but it's actually not too bad. The tag files are designed for wrapping common bits of markup so this is what they're for. I've also wrapped my own tag further so there is a picklist tag which outputs my custom select tag and then writes the JS needed to initialise it.

根据我想要实现的目标,这是我遇到的所有可能的解决方案中最好的.这就是我要解决的问题,但是如果其他人认为自己的解决方案更好,我仍然很想听听他们的解决方案.

I think this is the best of the possible solutions I've come across based on what I wanted to achieve. This is what I'm going with but I'd still be interested to hear of other peoples solutions if they think they have something better.

这篇关于包装带有自定义标签的Spring MVC选择标签时出现IlleagalStateException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆