You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Ryan LaHue <ry...@gmail.com> on 2009/05/12 17:33:05 UTC

Behavior to replace the contents between open and close ComponentTag tags

Can I remove/replace the contents between an open and close tags in the
onComponentTag(component, tag) method of AbstractBehavior?
I'm able to change the tag from an <input>, <select> or <textarea> to <span>
as I wanted, but I am unable to remove the guts of the previous form
component.  When I do this with a <select> it leaves behind all the <option>
tags.

Here's what I have so far.  I am able to update the attributes of the tag
itself, but I can't seem to remove/replace the text between open and close
tags:

     public void onComponentTag(final Component component, final
ComponentTag tag) {
      if (!component.isEnabled()) {
        tag.setName("span");
        tag.put("value", component.getDefaultModelObjectAsString()); //This
only updates the "value" attribute of the tag, not the contents
      }

I am trying to find a non-intrusive way to replace disabled components with
labels.  I started working on a Visitor but it does not seem to work since
my page uses multiple ajax refreshes of various subsections of a form -- the
Visitor works better for full page refreshes.

I was about to subclass the various form elements (TextField, TextArea,
DropDownChioce, etc) and then override their onBeforeRender methods to
replace the components with labels if they were disabled, but I'm wondering
if I can achieve this with a behavior instead.