Hello Everybody,
I have just started to use StrutsMenu. Its really gr8 thing.
While development to adjust my requirement I have added few things which I
whould like to share with you all.
1) Generating MenuComponent Object dynamically.
MenuComponentBuilder is a utility class that can generate the
MenuComponent from any object. This will help to provide dynamic Menus in
web application.
[ attachments MenuComponentBuilder.java, Test program TestObj.java ]
2) Hook in MenuDisplayer.
I had a requirement by which on certain business conditions few
MenuComponets where not supposed to be shown to user. For this I have
- Added an iterface called MenuObjectValidator.
- Modified BaseMenu to store the object from which the MenuComponent is
generated.
- Modified UseMenuDisplayerTag to accpent implementation of
MenuObjectValidator and set on displayerInstance; and this instance should
call validate method on impl before processing a MenuComponent to be
displyed.
[ attachment : MenuObjectValidator.java ]
Please let me know your suggestions on it.
Regards,
Rahul Kulkarni
_________________________________________________________________
Stand out from the crowd. Make your own MMS cards. http://msn.migasia.cn/msn
Have some mobile masti!
MenuComponentBuilder.java
Description: Binary data
MenuObjectValidator.java
Description: Binary data
/*
* Copyright ©.
*/
package com.fgm.web.menu.util;
import java.io.*;
import java.util.*;
import com.fgm.web.menu.MenuComponent;
/**
*
* @author
Rahul Kulkarni
* @version $Revision$
*/
public class TestObj {
private String title;
private String toolTip;
private String id;
private List sub;
public TestObj(String id, String title, String toolTip) {
this.id = id;
this.title = title;
this.toolTip = toolTip;
}
public String getTitle() {
return title;
}
public String getToolTip() {
return toolTip;
}
public String getId() {
return id;
}
public List getSub() {
return sub;
}
public void addSub(TestObj o) {
if ( sub == null ) {
sub = new ArrayList();
}
sub.add(o);
}
public static void main(String[] args) {
TestObj root = new TestObj("1", "root", "root tooltip");
TestObj TestObj("1", "one", "one tooltip");
TestObj two = new TestObj("1", "two", "two tooltip");
TestObj three = new TestObj("1", "three", "three tooltip");
one.addSub(three);
root.addSub(one);
root.addSub(two);
MenuComponentBuilder mcb = new MenuComponentBuilder();
Map repo = new HashMap();
repo.put(mcb.OBJECT, root);
repo.put(mcb.NAME, "rootTree");
repo.put(mcb.TITLE, "getTitle");
repo.put(mcb.TOOLTIP, "getTitle");
repo.put(mcb.SUBELEMENTS, "getSub");
Map params = new HashMap();
params.put("id", "getId");
repo.put(mcb.LINK_PARAMS, params);
MenuComponent mc = mcb.buildMenuComponent(repo);
System.out.print("* MC " + mc.getMenuComponents().length);
}
}