Yes I did it.

It runs as I told but does not change body

Martin Grigorov <mgrigo...@apache.org> wrote:

>Did you register this custom markup filter ?
>See org.apache.wicket.markup.MarkupParserFactory javadoc to see how to do
>it.
>
>On Fri, Mar 4, 2011 at 8:08 AM, Gonzalo Aguilar Delgado <
>gagui...@aguilardelgado.com> wrote:
>
>> Martin,
>>
>> I tried the filter and the filter runs quite well but no change on the
>> tag... Everything remains the same.
>>
>> Do you see something wrong? It also runs several times, not just one.
>> One for each component that has body in it's html. I suppose that is
>> normal Right? But how to know which one is the one that is going to be
>> rendered? The others are discarded...
>>
>> Thank you.
>>
>>
>> package com.level2.dojo.core.commons.filter;
>>
>> import java.text.ParseException;
>>
>> import org.apache.wicket.AttributeModifier;
>> import org.apache.wicket.Component;
>> import org.apache.wicket.RequestCycle;
>> import org.apache.wicket.behavior.AbstractBehavior;
>> import org.apache.wicket.behavior.IBehavior;
>> import org.apache.wicket.markup.ComponentTag;
>> import org.apache.wicket.markup.MarkupElement;
>> import org.apache.wicket.markup.parser.AbstractMarkupFilter;
>> import org.apache.wicket.model.Model;
>> import org.apache.wicket.request.IRequestCodingStrategy;
>> import org.slf4j.Logger;
>> import org.slf4j.LoggerFactory;
>>
>> public class DojoBodyMarkupFilter extends AbstractMarkupFilter {
>>        /** Logger */
>>        private static final Logger log =
>> LoggerFactory.getLogger(DojoBodyMarkupFilter.class);
>>
>>        /**
>>         * Behavior that adds a prefix to src, href and background
>> attributes to
>> make them
>>         * context-relative
>>         */
>>        public static final IBehavior RELATIVE_PATH_BEHAVIOR = new
>> AbstractBehavior()
>>        {
>>                private static final long serialVersionUID = 1L;
>>
>>                @Override
>>                public void onComponentTag(Component component,
>> ComponentTag tag)
>>                {
>>                        IRequestCodingStrategy coder =
>> RequestCycle.get()
>>                                .getProcessor()
>>                                .getRequestCodingStrategy();
>>
>>                        // Modify all relevant attributes
>>                                String attrName = "class";
>>                                String attrValue =
>> tag.getAttributes().getString(attrName);
>>                                attrValue = "mytest";
>>                                tag.getAttributes().put(attrName,
>> coder.rewriteStaticRelativeUrl(attrValue));
>>
>This rewrite is not needed. Just use the value.
>
>>                }
>>        };
>>
>>        public MarkupElement nextTag() throws ParseException {
>>                // Get next tag. Null, if no more tag available
>>                final ComponentTag tag =
>> (ComponentTag)getParent().nextTag();
>>                if (tag == null)
>>                {
>>                        return tag;
>>                }
>>
>>                // For all <wicket:link ..> tags which probably change
>> the
>>                // current autolink status.
>>                if (tag.getName().equals("body"))
>>                {
>>
>>                                // Beginning of the region
>>                                if (tag.isOpen() || tag.isOpenClose())
>>                                {
>>                                        if (tag.isOpen())
>>                                        {
>>                                                //
>>                                                log.debug("Tag: " +
>> tag.getName() + " Will add new class " +
>> tag.getId());
>>
>>  tag.addBehavior(RELATIVE_PATH_BEHAVIOR);
>>                                                tag.setModified(true);
>>                                        }
>>
>>                                }
>>                                else if (tag.isClose())
>>                                {
>>
>>                                }
>>                }
>>
>>                return tag;
>>        }
>>
>> }
>>
>>
>>
>>
>>
>> --
>>
>>
>>  Gonzalo Aguilar Delgado
>>  Consultor CRM - Ingeniero en
>> Informática
>>
>>        M. +34 607 81 42 76
>>
>>
>>
>> "No subestimes el poder de la gente estúpida en grupos grandes"
>>
>> El jue, 03-03-2011 a las 12:39 +0200, Martin Grigorov escribió:
>>
>> > Hi,
>> >
>> > you may use TransparentWebMarkupContainer for the body.
>> > Or create your own IMarkupFilter that adds a Behavior to the <body> open
>> > tag, and this behavior appends/sets the class attribute depending on the
>> > user session or whatever the Dojo theme depends on.
>> > See org.apache.wicket.markup.parser.filter.RelativePathPrefixHandler for
>> > example.
>> >
>> >
>> > On Thu, Mar 3, 2011 at 12:15 PM, Gonzalo Aguilar Delgado <
>> > gagui...@aguilardelgado.com> wrote:
>> >
>> > > Hello Matt,
>> > >
>> > > It does not work as I cannot override add method from
>> webmarkupcontainer.
>> > >
>> > > Even if it works I will have to add something to the htlm. Right?
>> > >
>> > >
>> > > Tnx again
>> > >
>> > > Matt Brictson <m...@55minutes.com> wrote:
>> > >
>> > > >Since isTransparentResolver() is going away in 1.5, the trick that I
>> found
>> > > is to create a normal WebMarkupContainer for the <body> element, then
>> > > override add(Component...) of the page to mimic the transparent
>> resolver
>> > > feature.
>> > > >
>> > > >Your pages can then contribute to the <body> element by adding
>> > > AttributeModifier, etc. to the WebMarkupContainer.
>> > > >
>> > > >See:
>> > > ><
>> > >
>> https://cwiki.apache.org/WICKET/migration-to-wicket-15.html#MigrationtoWicket1.5-MarkupContainer.isTransparentResolver%2528%2529removed
>> > > >
>> > > >
>> > > >Here's an example:
>> > > >
>> > > >public abstract class BasePage extends WebPage
>> > > >{
>> > > >    private WebMarkupContainer _body;
>> > > >
>> > > >    public BasePage(PageParameters params)
>> > > >    {
>> > > >        super(params);
>> > > >
>> > > >        // Allow subclasses to register CSS classes on the body tag
>> > > >        WebMarkupContainer body = new WebMarkupContainer("body");
>> > > >        body.setOutputMarkupId(true);
>> > > >        add(body);
>> > > >
>> > > >        // From now on add() will add to _body instead of page
>> > > >        this._body = body;
>> > > >    }
>> > > >
>> > > >    /**
>> > > >     * Return a component that represents the {@code <body>} of the
>> page.
>> > > >     * Use this to add CSS classes or set the markup ID for styling
>> > > purposes.
>> > > >     */
>> > > >    public WebMarkupContainer getBody()
>> > > >    {
>> > > >        return _body;
>> > > >    }
>> > > >
>> > > >    /**
>> > > >     * When subclasses of BasePage add components to the page, in
>> reality
>> > > >     * they need to be added as children of the {@code <body>}
>> container.
>> > > >     * This implementation ensures the page hierarchy is correctly
>> > > enforced.
>> > > >     *
>> > > >     * @return {@code this} to allow chaining
>> > > >     */
>> > > >    @Override
>> > > >    public BasePage add(Component... childs)
>> > > >    {
>> > > >        for(Component c : childs)
>> > > >        {
>> > > >            // Wicket automatically translates <head> into an
>> > > >            // HtmlHeaderContainer and adds it to the page. Make sure
>> this
>> > > >            // is registered as a direct child of the page itself, not
>> the
>> > > >            // body.
>> > > >            if(null == _body || c instanceof HtmlHeaderContainer)
>> > > >            {
>> > > >                super.add(c);
>> > > >            }
>> > > >            // Everything else goes into the <body>.
>> > > >            else
>> > > >            {
>> > > >                _body.add(c);
>> > > >            }
>> > > >        }
>> > > >        return this;
>> > > >    }
>> > > >}
>> > > >
>> > > >--
>> > > >Matt
>> > > >
>> > > >On Mar 2, 2011, at 11:35 AM, Gonzalo Aguilar Delgado wrote:
>> > > >
>> > > >> Hello,
>> > > >>
>> > > >> I'm building a wiJQuery equivalent for Dojo. And it seems to work
>> nice
>> > > >> with new wicket 1.5. HeaderContributions are really nice... Great
>> work!
>> > > >>
>> > > >> But I ran into problems when trying to setup the themes.
>> > > >>
>> > > >> I have to put something like this in the body:
>> > > >>
>> > > >> <body class="claro">
>> > > >>
>> > > >> </body>
>> > > >>
>> > > >> But I rode a lot and discovered that wicket no longer supports
>> > > >> contributing to body because onLoad handler as well others.
>> > > >>
>> > > >> Reading in forums I found the BodyTagAttributeModifier but you need
>> a
>> > > >> panel that I wont have.
>> > > >>
>> > > >> And the:
>> > > >>
>> > > >> <body wicket:id="body">
>> > > >>
>> > > >>        add(new WebMarkupContainer("body"){
>> > > >>            @Override
>> > > >>            public boolean isTransparentResolver() {
>> > > >>                return true;
>> > > >>            }
>> > > >>            @Override
>> > > >>            protected void onComponentTag(ComponentTag tag) {
>> > > >>                tag.put("class",  "somestyle");
>> > > >>            }
>> > > >>        });
>> > > >> It will not work because wicket:id attribute removed from body in
>> > > version 1.5.
>> > > >>
>> > > >>
>> > > >> So... What's they way to go?
>> > > >>
>> > > >>
>> > > >>
>> ---------------------------------------------------------------------
>> > > >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> > > >> For additional commands, e-mail: users-h...@wicket.apache.org
>> > > >>
>> > > >
>> > > >
>> > > >---------------------------------------------------------------------
>> > > >To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> > > >For additional commands, e-mail: users-h...@wicket.apache.org
>> > > >
>> > >
>>

Reply via email to