修改Wicket ComponentTag父级的属性 [英] Modify Attribute of Wicket ComponentTag Parent

查看:51
本文介绍了修改Wicket ComponentTag父级的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张小票.在此表单中,有一些输入标签.这些输入标签被放入div容器中.这些div容器可以制作"样式(即它们具有样式类).如果子输入的验证失败,我想访问div标记的这种样式.我试图通过行为来做到这一点,但是我无法访问div标签(它将是输入标签的父标签).有什么想法,如果验证失败,我该如何修改父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>

谢谢

推荐答案

首先,在Wicket中,您只能修改组件的标记.当然,页面上的所有内容都是某物或其他组件的标记,最糟糕的是您的 Page 类.

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.

但是您绝对不想修改页面类生成其输出的方式.这意味着您还必须使包含div成为组件.

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.

<div wicket:id="myInputContainer">
    <label>Field1</label> <input wicket:id="myInput" type="text"/>
</div>

由于不再需要容器需要的其他功能,因此在Java代码中使用 WebMarkupContainer 类.

And as there's no more functionality you need the container do, in the Java code use the WebMarkupContainer class.

WebMarkupcontainer cont = new WebMarkupContainer( "myInputcontainer" );
cont.add( new Textfield( "myInput" ) );
form.add( cont );

从这里很容易,您可以将行为 Behavior 附加到容器上,鲍勃是您的叔叔.

And from here it's easy, you can attach your Behavior to the container and Bob's your uncle.

这篇关于修改Wicket ComponentTag父级的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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