i once thought of building menus but realized that the problem with menu is
that there are a million types based on different styles and javascripts out
there. compiling a factory of them is work indeed and the API will just
swell your wicket project. :)
I have a simple implementation like this dat just gives me peace for basic
navigation uses across all my projects
In HTML, there is a constant set of tags, the most popular on the web for
menus
<div class="menuCSS" wicket:id="menuContainer">
<ul>
<!-- CSS Tabs -->
<li wicket:id="menuList">
<a wicket:id="menuListItem">
<span wicket:id="menuName">Home</span>
</a>
</li>
</ul>
</div>
Because most menus on the web are based on this structure, you now leave the
user to implement their own "menuCSS" styles in thier CSS resource,
then I have these sets of code
The Model
public class MenuXItem implements Serializable, Comparable{
private String tooltip;
private String description;
private Class page;
private boolean externalLink;
private String externalUrl;
private int position;
//constructors
//getter
//setter
public int compareTo(Object o) {
if(o instanceof MenuXItem){
MenuXItem m = ((MenuXItem)o) ;
if( m.getPosition()> position)
return -1;
if(m.getPosition() < position)
return 1;
return 0;
}else
throw new ClassCastException();
}
}
class MainMenuModel extends LoadableDetachableModel{
protected Object load() {
List<MenuXItem> menuList = new ArrayList<MenuXItem>();
menuList.add(new MenuXItem("Home Page",HomePage.class,1));
menuList.add(new MenuXItem("Page 2",Page2.class,2));
menuList.add(new MenuXItem("Page 3",Page3.class,3));
menuList.add(new MenuXItem("Page 4",Page4.class,4));
return menuList;
}
}
The View
final ListView view = new ListView("menuList", new MainMenuModel()) {
protected void populateItem(ListItem listItem) {
final MenuXItem xitem = (MenuXItem) listItem.getModelObject
();
ExternalLink xLink = null;
BookmarkablePageLink page1 = null;
if(xitem.isExternalLink()){
xlink = new ExternalLink("menuListItem",
xitem.getExternalUrl());
xlink.add(xitem.getDescription());
listItem.add(xlink);
}
else{
page1 = new BookmarkablePageLink("menuListItem",
xitem.getPage());
Label lname = new Label("menuName", xitem.getDescription());
page1.add(lname);
if (xitem.getPage().equals(this.getClass())) {
page1.add(new AttributeModifier("class", true, new
Model("current")));
}
listItem.add(page1);
}
listItem.setOutputMarkupId(true);
}
};
Integrating this with YUI was easy at least for the non nested cases
On 8/10/07, David Leangen <[EMAIL PROTECTED]> wrote:
>
>
> > > Is there no menu component available somewhere? I looked
> > > around in wicket and extensions, but didn't see one...
>
> > Nope. There was one wicket-stuff project a while ago, but that wasn't
> > too great (I'm guilty).
>
> Ah! That's where I met you before... in a Crappy Code prison cell...
>
>
> > I think it would be great to build a component around the YUI menu[1],
> > but we need a couple (or at least one) volunteer to work on that, and
> > people who are going to use it (dogfood, eating) so that it can
> > quickly reach a useful state. Unfortunately, I can't spent to much
> > time on it myself at this time. Volunteers?
>
> Yeah, well, I still need to get back to my YUI autocomplete, so maybe
> when I do that, I'll have some time.
>
> I'm also CC'ing the ops4j list, because I think somebody there was once
> working on YUI menu stuff, though I don't know the status of that.
>
>
> Cheers,
> Dave
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>