Hi,

i am looking at this code inside Component:

    public final ValueMap getMarkupAttributes()
    {
        MarkupStream markupStream = MarkupFragmentFinder.find(this);
        ValueMap attrs = new ValueMap( markupStream.getTag().getAttributes());
        attrs.makeImmutable();
        return attrs;
    }

and:

public final void renderComponent(final MarkupStream markupStream)
    {
        this.markupIndex = markupStream.getCurrentIndex();

        // Get mutable copy of next tag
        final ComponentTag openTag = markupStream.getTag();
        final ComponentTag tag = openTag.mutable();

        // Call any tag handler
        onComponentTag(tag);


What i would like to do is change this behaviour and let the Component creates a copy of there own Tag inside itself (at construct time)

so that getMarkupAttributes() is not immutable anymore.
you can just do:

mylabel.getMarkupAttributes().put("class", "mycssclass");

instead of making a attribute modifer object with attribtue "class" and value "mycssclass" and then add that as a behaviour/attributemodifier on the component.

so i want something like this: (all on Component)


    public Component(MarkupContainer<?> parent, final String id, final IModel<T> model)
    {
        if (parent == null)
        {
            if (!(this instanceof Page))
            {
                throw new WicketRuntimeException("component without a parent is not allowed.");
            }
        }
        this.parent = parent;
        setId(id);

        try
        {
            MarkupStream markupStream = MarkupFragmentFinder.find(this);
            tag = markupStream.getTag().mutable(); // GET the Tag out of the markup and make a copy.
        }
        catch(RuntimeException re)
        {
            throw new WicketRuntimeException("Couldn't find the markup of the component " + id + " in parent " + parent.getPageRelativePath ());
        }
         ........


   ComponentTag getTag()  // Return the tag. Maybe not needed this method..
   {
      return tag;
   }

    public final ValueMap getMarkupAttributes()
    {
        return tag.getAttributes(); // Directly return the mutable tags attributes
    }

    public final void renderComponent(final MarkupStream markupStream)
    {
        this.markupIndex = markupStream.getCurrentIndex();

        final ComponentTag tag = getTag(); // Just use the mutable tag attributes.

        // Call any tag handler
        onComponentTag(tag);
        .................


The only thing is that we then hold a reference to a Tag in every component..
We don't need some AttributeModifiers then because you can do that directly. And we don't generate constant copies..

what we also could do is not get a copy of the tag but just the attributes map.
Then we don't hold the complete xml tree as a copy in mem.

Then we just need to set those attributes in the component tag at render time.
i guess this would be even much better.

any other ideas?

johan











_______________________________________________
Wicket-develop mailing list
Wicket-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-develop

Reply via email to