You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by pg...@free.fr on 2008/11/10 17:54:03 UTC

CSS navigation menu & autolink

Hello all,

I'm really new in the object world in general and using Wicket  
particularly, so please excuse if I'm missing something... I've  
googled around but maybe I didn't use the good keywords.


So here's my question !

I'm building a navigation menu for my web application. There are 3  
different levels, the higher one is linking to different Wicket pages.  
My top level menu is html coded like this :

<ul>
	<li>Menu Item 1</li>
	<li class="current">Menu Item 2</li>
	<li>Menu Item 3</li>
</ul>

Notice the class="current" on the selected page.

I've already created the following code (see below), but was wondering  
if there are any means to use the Wicket autolink feature ? It would  
be far more simplier... The difficulty I see is to modify the <li> tag  
on the selected link ? Thanks for advices !



// LayoutAuthenticated.html
...
	<ul wicket:id="menu1a">
		<li wicket:id="menu1aItem"><a>Libellé menu1</a></li>
	</ul>
...



// LayoutAuthenticated.java

	protected MenuItem menu1aOpt1;
	protected MenuItem menu1aOpt2;
	protected MenuItem menu1aOpt3;

	public LayoutAuthenticated() {
...
		List<MenuItem> menu1aList = new ArrayList<MenuItem>();
		menu1aList.add(menu1aOpt1 = new MenuItem("menu1aItem", true,  
"menu1a.Opt1", Opt1.class));
		menu1aList.add(menu1aOpt2 = new MenuItem("menu1aItem", true,  
"menu1a.Opt2", Opt2.class));
		menu1aList.add(menu1aOpt3 = new MenuItem("menu1aItem", true,  
"menu1a.Opt3", Opt3.class));
		add(new ListView<MenuItem>("menu1a", menu1aList) {
			@Override
			protected void populateItem(ListItem<MenuItem> item) {
				item.add(item.getModelObject());
			}
		});
...
	}



// MenuItem.html

<wicket:panel>
<li wicket:id="menuItem"><a wicket:id="link"><span wicket:id="label"  
/></a></li>
</wicket:panel>



// MenuItem.java

	private String keyLabel;
	private Class lienClass;
	private WebMarkupContainer menuItem;
	private BookmarkablePageLinkWithoutDisabledMarkup link;

	public MenuItem(String wicketId, boolean isActive, String keyLabel,  
Class lienClass) {
		super(wicketId);

		setLienClass(lienClass);
		setKeyLabel(keyLabel);

		setRenderBodyOnly(true);
		add(menuItem = new WebMarkupContainer("menuItem"));
		menuItem.add(link = new  
BookmarkablePageLinkWithoutDisabledMarkup("link", lienClass));
		Label label;
		link.add(label = new Label("label", new ResourceModel(keyLabel)));
		label.setRenderBodyOnly(true);
	}

	public void setLienClass(Class lienClass) {
		this.lienClass = lienClass;
	}

	public void setKeyLabel(String keyLabel) {
		this.keyLabel = keyLabel;
	}

	public void setActive() {
		menuItem.add(new SimpleAttributeModifier("class",""));
		link.setEnabled(true);
	}

	public void setInActive() {
		menuItem.add(new SimpleAttributeModifier("class","current"));
		link.setEnabled(false);
	}



// BookmarkablePageLinkWithoutDisabledMarkup.java
// (just to keep my <a> tag on selected links)

	public <C extends Page> BookmarkablePageLinkWithoutDisabledMarkup(String id,
			Class<C> pageClass) {
		super(id, pageClass);
	}

	@Override
	protected void disableLink(ComponentTag tag) {
		tag.remove("href");
	}



// Opt1.java

public class Opt1 extends LayoutAuthenticated {
	public Opt1() {
		menu1aOpt1.setInActive();
	}
}



// Opt2.java

public class Opt2 extends LayoutAuthenticated {
	public Opt2() {
		menu1aOpt2.setInActive();
	}
}



// Opt3.java

public class Opt3 extends LayoutAuthenticated {
	public Opt3() {
		menu1aOpt3.setInActive();
	}
}



// Wicket application init()
// (don't need the default <em> tags around the selected link label)

...
		getMarkupSettings().setDefaultBeforeDisabledLink("");
		getMarkupSettings().setDefaultAfterDisabledLink("");
...


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


Re: CSS navigation menu & autolink

Posted by Pierre Goiffon <pg...@free.fr>.
No answers...

The question is how to make automatic linking have an effect on the A 
tag and its container LI tag, knowing that both of them are part of a 
custom wicket component.

Anyone ?


pgoiffon.wicket@free.fr wrote:
> Hello all,
>
> I'm really new in the object world in general and using Wicket 
> particularly, so please excuse if I'm missing something... I've 
> googled around but maybe I didn't use the good keywords.
>
>
> So here's my question !
>
> I'm building a navigation menu for my web application. There are 3 
> different levels, the higher one is linking to different Wicket pages. 
> My top level menu is html coded like this :
>
> <ul>
>     <li>Menu Item 1</li>
>     <li class="current">Menu Item 2</li>
>     <li>Menu Item 3</li>
> </ul>
>
> Notice the class="current" on the selected page.
>
> I've already created the following code (see below), but was wondering 
> if there are any means to use the Wicket autolink feature ? It would 
> be far more simplier... The difficulty I see is to modify the <li> tag 
> on the selected link ? Thanks for advices !
>
>
>
> // LayoutAuthenticated.html
> ...
>     <ul wicket:id="menu1a">
>         <li wicket:id="menu1aItem"><a>Libellé menu1</a></li>
>     </ul>
> ...
>
>
>
> // LayoutAuthenticated.java
>
>     protected MenuItem menu1aOpt1;
>     protected MenuItem menu1aOpt2;
>     protected MenuItem menu1aOpt3;
>
>     public LayoutAuthenticated() {
> ...
>         List<MenuItem> menu1aList = new ArrayList<MenuItem>();
>         menu1aList.add(menu1aOpt1 = new MenuItem("menu1aItem", true, 
> "menu1a.Opt1", Opt1.class));
>         menu1aList.add(menu1aOpt2 = new MenuItem("menu1aItem", true, 
> "menu1a.Opt2", Opt2.class));
>         menu1aList.add(menu1aOpt3 = new MenuItem("menu1aItem", true, 
> "menu1a.Opt3", Opt3.class));
>         add(new ListView<MenuItem>("menu1a", menu1aList) {
>             @Override
>             protected void populateItem(ListItem<MenuItem> item) {
>                 item.add(item.getModelObject());
>             }
>         });
> ...
>     }
>
>
>
> // MenuItem.html
>
> <wicket:panel>
> <li wicket:id="menuItem"><a wicket:id="link"><span wicket:id="label" 
> /></a></li>
> </wicket:panel>
>
>
>
> // MenuItem.java
>
>     private String keyLabel;
>     private Class lienClass;
>     private WebMarkupContainer menuItem;
>     private BookmarkablePageLinkWithoutDisabledMarkup link;
>
>     public MenuItem(String wicketId, boolean isActive, String 
> keyLabel, Class lienClass) {
>         super(wicketId);
>
>         setLienClass(lienClass);
>         setKeyLabel(keyLabel);
>
>         setRenderBodyOnly(true);
>         add(menuItem = new WebMarkupContainer("menuItem"));
>         menuItem.add(link = new 
> BookmarkablePageLinkWithoutDisabledMarkup("link", lienClass));
>         Label label;
>         link.add(label = new Label("label", new 
> ResourceModel(keyLabel)));
>         label.setRenderBodyOnly(true);
>     }
>
>     public void setLienClass(Class lienClass) {
>         this.lienClass = lienClass;
>     }
>
>     public void setKeyLabel(String keyLabel) {
>         this.keyLabel = keyLabel;
>     }
>
>     public void setActive() {
>         menuItem.add(new SimpleAttributeModifier("class",""));
>         link.setEnabled(true);
>     }
>
>     public void setInActive() {
>         menuItem.add(new SimpleAttributeModifier("class","current"));
>         link.setEnabled(false);
>     }
>
>
>
> // BookmarkablePageLinkWithoutDisabledMarkup.java
> // (just to keep my <a> tag on selected links)
>
>     public <C extends Page> 
> BookmarkablePageLinkWithoutDisabledMarkup(String id,
>             Class<C> pageClass) {
>         super(id, pageClass);
>     }
>
>     @Override
>     protected void disableLink(ComponentTag tag) {
>         tag.remove("href");
>     }
>
>
>
> // Opt1.java
>
> public class Opt1 extends LayoutAuthenticated {
>     public Opt1() {
>         menu1aOpt1.setInActive();
>     }
> }
>
>
>
> // Opt2.java
>
> public class Opt2 extends LayoutAuthenticated {
>     public Opt2() {
>         menu1aOpt2.setInActive();
>     }
> }
>
>
>
> // Opt3.java
>
> public class Opt3 extends LayoutAuthenticated {
>     public Opt3() {
>         menu1aOpt3.setInActive();
>     }
> }
>
>
>
> // Wicket application init()
> // (don't need the default <em> tags around the selected link label)
>
> ...
>         getMarkupSettings().setDefaultBeforeDisabledLink("");
>         getMarkupSettings().setDefaultAfterDisabledLink("");
> ...
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


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