You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Vladimir Kovalyuk <ko...@gmail.com> on 2009/07/20 13:31:03 UTC

how to strip wicket tags for particular component

I'm trying to convert main menu into components to control visibility of
items depending on the user logged in and the context.
I use borders to wrap menu item into <li> tags.

The problem is that the rendered markup contains additional <wicket:border>
and <wicket:body> tags. They breaks the menu and it is eventually displayed
as the simple list.

Stripping wicket tags at the application level would obviously solve the
problem. But I'd like to keep wicket tags for most markup and strip only for
menu.

Can I override Border class somehow and strip wicket tags manually?

Re: how to strip wicket tags for particular component

Posted by Vladimir K <ko...@gmail.com>.
For now I use the following workaround

public class CleanBorder extends Border {
	private boolean savedStripWicketTags; 

	public CleanBorder(String id) {
		super(id);
		setRenderBodyOnly(true);
		getBodyContainer().setRenderBodyOnly(true);
	}

	public CleanBorder(String id, IModel<?> model) {
		super(id, model);
		setRenderBodyOnly(true);
		getBodyContainer().setRenderBodyOnly(true);
	}
	
	@Override
	protected void onAfterRender() {
		super.onAfterRender();
	
Application.get().getMarkupSettings().setStripWicketTags(savedStripWicketTags);
	}
	
	@Override
	protected void onBeforeRender() {
		savedStripWicketTags =
Application.get().getMarkupSettings().getStripWicketTags();
		Application.get().getMarkupSettings().setStripWicketTags(true);
		super.onBeforeRender();
	}


that looks like a hack. I would prefer a settings on the MarkupContainer
that by default uses the application settings but in case of border can be
overridden.


Vladimir K wrote:
> 
> I'm trying to convert main menu into components to control visibility of
> items depending on the user logged in and the context.
> I use borders to wrap menu item into <li> tags.
> 
> The problem is that the rendered markup contains additional
> <wicket:border>
> and <wicket:body> tags. They breaks the menu and it is eventually
> displayed
> as the simple list.
> 
> Stripping wicket tags at the application level would obviously solve the
> problem. But I'd like to keep wicket tags for most markup and strip only
> for
> menu.
> 
> Can I override Border class somehow and strip wicket tags manually?
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-strip-wicket-tags-for-particular-component-tp24568122p24568909.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: how to strip wicket tags for particular component

Posted by Erik van Oosten <e....@grons.nl>.
Turning the 2 lines around might give better results.

Regards,
    Erik.


Mathias Nilsson wrote:
> What about
>
> @Override
>     	        	public void onComponentTag( ComponentTag tag){ 
>     	        	     tag.remove( "wicket:id" );
>     	        	     super.onComponentTag(tag);
>     	        	} 
>   

-- 
Erik van Oosten
http://day-to-day-stuff.blogspot.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: how to strip wicket tags for particular component

Posted by Mathias Nilsson <wi...@gmail.com>.
What about

@Override
    	        	public void onComponentTag( ComponentTag tag){ 
    	        	     tag.remove( "wicket:id" );
    	        	     super.onComponentTag(tag);
    	        	} 
-- 
View this message in context: http://www.nabble.com/how-to-strip-wicket-tags-for-particular-component-tp24568122p24571367.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: how to strip wicket tags for particular component

Posted by Vladimir K <ko...@gmail.com>.
It is possible to override onRender method. It turned out that it is not
final.

	@Override
	protected void onRender(MarkupStream markupStream) {
		Application.get().getMarkupSettings().setStripWicketTags(true);
		try {
			super.onRender(markupStream);
		} finally {
			Application.get().getMarkupSettings().setStripWicketTags(
					MyApplication.STRIP_WICKET_TAGS_IN_DEVELOPMENT_MODE);
		}
	}

But I don't find appropriate method to override to let children render
wicket tags.

-- 
View this message in context: http://www.nabble.com/how-to-strip-wicket-tags-for-particular-component-tp24568122p24569807.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: how to strip wicket tags for particular component

Posted by Vladimir K <ko...@gmail.com>.
it seems that onAfterRender is not the appropriate place to restore settings
... :(


Vladimir K wrote:
> 
> Mathias,
> 
> I just posted right after your post :) Anyway thanks.
> 
> The problem is that you can not restore origianal settings when the body
> of the border is being rendered. At lease it is difficult to figure out
> what workaround I could employ.
> 
> Thankfully I don't have to care about that in my case so I use it.
> 
> 
> Mathias Nilsson wrote:
>> 
>> This may not be the best solution but it should work
>> 
>> DateTextField  dateField = new DateTextField("date", new Model<Date>(new
>> Date())){
>>     	        	@Override
>>     	        	protected void onBeforeRender() {
>>     	        		
>>     	        	
>> Application.get().getMarkupSettings().setStripWicketTags(true);
>>     	        		super.onBeforeRender();
>>     	        	}
>>     	        	@Override
>>     	        	protected void onAfterRender() {
>>     	        	
>> Application.get().getMarkupSettings().setStripWicketTags(false);
>>     	        		super.onAfterRender();
>>     	        	}
>> 
>>     	        }; 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/how-to-strip-wicket-tags-for-particular-component-tp24568122p24569561.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: how to strip wicket tags for particular component

Posted by Vladimir K <ko...@gmail.com>.
Mathias,

I just posted right after your post :) Anyway thanks.

The problem is that you can not restore origianal settings when the body of
the border is being rendered. At lease it is difficult to figure out what
workaround I could employ.

Thankfully I haven't to care about that in my case so I use it.


Mathias Nilsson wrote:
> 
> This may not be the best solution but it should work
> 
> DateTextField  dateField = new DateTextField("date", new Model<Date>(new
> Date())){
>     	        	@Override
>     	        	protected void onBeforeRender() {
>     	        		
>     	        	
> Application.get().getMarkupSettings().setStripWicketTags(true);
>     	        		super.onBeforeRender();
>     	        	}
>     	        	@Override
>     	        	protected void onAfterRender() {
>     	        	
> Application.get().getMarkupSettings().setStripWicketTags(false);
>     	        		super.onAfterRender();
>     	        	}
> 
>     	        }; 
> 

-- 
View this message in context: http://www.nabble.com/how-to-strip-wicket-tags-for-particular-component-tp24568122p24568972.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: how to strip wicket tags for particular component

Posted by Mathias Nilsson <wi...@gmail.com>.
This may not be the best solution but it should work

DateTextField  dateField = new DateTextField("date", new Model<Date>(new
Date())){
    	        	@Override
    	        	protected void onBeforeRender() {
    	        		
    	        	
Application.get().getMarkupSettings().setStripWicketTags(true);
    	        		super.onBeforeRender();
    	        	}
    	        	@Override
    	        	protected void onAfterRender() {
    	        	
Application.get().getMarkupSettings().setStripWicketTags(false);
    	        		super.onAfterRender();
    	        	}

    	        }; 
-- 
View this message in context: http://www.nabble.com/how-to-strip-wicket-tags-for-particular-component-tp24568122p24568890.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org