And instead of bl.add(new SimpleAttributeModifier("class", "clazz"));
you could do tag.put("class", "clazz");. Or remove the attribute
altogether (tag.remove("class")) if it's only a dummy.

Eelco

On Tue, May 27, 2008 at 12:42 AM, Alex Parvulescu
<[EMAIL PROTECTED]> wrote:
> thanks Eelco,
> the problem is fixed!
>
> if anybody's interested:
> the visitor:
> public class ReadOnlyReplacingVisitor implements IVisitor {
>
> public Object component(Component component) {
>    if (component instanceof DropDownChoice || component instanceof
> TextField) {
>        String id = component.getId();
>        // the label keep the old component's value
>        InfoLabel lbl = new InfoLabel(id, component.getModel());
>        // a little css sugar ;)
>        lbl.add(new SimpleAttributeModifier("class", "clazz"));
>        component.replaceWith(lbl);
>    }
> }
> }
>
> and the new component:
> public class InfoLabel extends Label {
>
>    public InfoLabel(String id) {
>        super(id);
>    }
>
>    public InfoLabel(String id, IModel model) {
>        super(id, model);
>    }
>
>    public InfoLabel(String id, String label) {
>        super(id, label);
>    }
>
>    @Override
>    protected void onComponentTag(ComponentTag tag) {
>        super.onComponentTag(tag);
>        tag.setName("span");
>    }
> }
>
>
> On Tue, May 27, 2008 at 10:02 AM, Eelco Hillenius <[EMAIL PROTECTED]>
> wrote:
>
>> > I have a visitor that replaces components(TextField, DropDownChoice) on a
>> > page with read-only values (labels)
>> >
>> > this visitor doesn't work properly, it doesn't replace the entire
>> component,
>> > it only inserts the text between the component's tags
>> >  so that <input type="text" wicket:id="t1"/> becomes <input
>> > type="text">replaced</input>
>> >
>> > and now some code:
>> >
>> > the visitor:
>> > public class ReadOnlyReplacingVisitor implements IVisitor {
>> >
>> > public Object component(Component component) {
>> >    if (component instanceof DropDownChoice || component instanceof
>> > TextField) {
>> >        String id = component.getId();
>> >        component.replaceWith(new Label(id, "replaced"));
>> >    }
>> > }
>> >
>> > }
>> >
>> > the page:
>> >
>> > for wicket 1.2.6 i have :
>> >    @Override
>> >    protected void onAttach() {
>> >        visitChildren(new ReadOnlyReplacingVisitor());
>> >    }
>> >
>> > wicket 1.3.3:
>> >    @Override
>> >    protected void onBeforeRender() {
>> >        super.onBeforeRender();
>> >        visitChildren(new ReadOnlyReplacingVisitor());
>> >    }
>> >
>> > i tried to replace the simple Label component with a custom panel,but the
>> > outcome is the same
>> > this goes for DDCs as well.
>> >
>> > any ideas?
>>
>> Well, a label only replaces it's body, while what you want is change
>> the tag, right? One way to achieve that is to create a component that
>> does this (overwrite onComponentTag and use setName on the tag to
>> change the tag, and maybe change the attributes). I didn't actually
>> try this, but I think this should work.
>>
>> Eelco
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to