开发者

Modify Attribute of Wicket ComponentTag Parent

开发者 https://www.devze.com 2023-03-15 05:01 出处:网络
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 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开发者_Go百科 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


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.

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

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 );

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

0

精彩评论

暂无评论...
验证码 换一张
取 消