修改 Wicket ComponentTag 父级的属性
我有一个检票表格。在此表单中有一些输入标签。这些输入标签被放入 div 容器中。这些 div 容器“制作”样式(即它们具有样式类)。 如果子输入验证失败,我想访问这种样式的 div 标签。我尝试使用 Behavior 来执行此操作,但无法访问 div 标签(这将是输入标签的父标签)。如果验证失败,我有什么想法可以修改父 div 标签的样式吗?
<div style="myStyle">
<label>Field1</label> <input type="text"/>
</div>
谢谢
I have a Wicket Form. Within this form there are a few input tags. These input tags are put into div containers. These div containers "make" the style (i.e. they have style classes).
I want to access this style of the div tag, if the validation of the child input fails. I tried to do this with a Behavior, but I cannot access the div tag (which would be the parent of the input tag). Any ideas how I can modify the style of the parent div tag if validation fails?
<div style="myStyle">
<label>Field1</label> <input type="text"/>
</div>
THanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先要做的事情是:在 Wicket 中您只能修改组件的标记。当然,页面上的所有内容都是某个组件的标记,最坏的情况是您的
Page
类。但您绝对不想修改页面类生成其输出的方式。这意味着您也必须使包含的 div 成为一个组件。
由于容器不再需要任何功能,因此在 Java 代码中使用
WebMarkupContainer
类。从这里开始就很简单了,您可以将您的行为附加到容器,而鲍勃是您的叔叔。
First things first: in Wicket you can only modify the markup of a component. Of course everything on your page is the markup of a component of something or other, at worst your
Page
class.But you definitely don't want to modify the way your page class generates its output. Which means that you have to make your containing div a component too.
And as there's no more functionality you need the container do, in the Java code use the
WebMarkupContainer
class.And from here it's easy, you can attach your
Behavior
to the container and Bob's your uncle.