Modify Attribute of Wicket ComponentTag Parent

纵然是瞬间 提交于 2020-01-05 02:53:29

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/6459481/modify-attribute-of-wicket-componenttag-parent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!