You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by César Alberto Barrera <ab...@gmail.com> on 2011/06/22 20:32:23 UTC
Different menu path in a MenuPanel
Hello!
I have a special menu to build, my HomePage has many links example and I can
go to distinct Page
HomePage link to Page1, Page 5
In Page 1 has link to Page 2, Page3
Page2 -> links to Page 3, Page 4
Page3 -> links to Page 2, Page 4
In Page 5 has link to Page 6, Page 7
Page7 -> links to Page 8
Page6 -> links to Page 9
And the combinations going on.
So, I need to build a MenuPanel to take track from the user selection of
page to permit the user return easy to whatever page.
Example of navigation:
The user starts in HomePage, then Click Page1, the menu is (HomePage | Page1
<-- disabled but showed in the menu to show the position)
latter the user clicks Page2 now the menu change to (HomePage | Page1 |
Page2 <-- disabled )
I have solved this with a Session and a Menu List saving the PageParameters to
reproduce the same page, my user can go to HomePage, Page1 or clic the link
Page3 or Page4, so the menu change
to (HomePage | Page1 | Page2 | Page3 )
My problem is that if my user open a new browser tab, the menu in session is
the same so I need to take track of the new tab.
How can I take track of the browser tab, window etc, to get better listMenu.
I can't do a map of menu because Page4 may be can render page N accord to
user properties
May be I need to get the window# or tab and save it with the listMenu.
My test code
public class SiSession extends WebSession
{
private static final long serialVersionUID = 6953907625762546748L;
private ArrayList<Menu> listMenu = new ArrayList<Menu>();
public ArrayList<Menu> getListMenu() {
return listMenu;
}
public void setListMenu(ArrayList<Menu> lista) {
this.listMenu = lista;
}
}
LayoutPage
public abstract class LayoutPage extends WebPage {
public LayoutPage(Class clase, String nombre, PageParameters parametros){
MenuPanel mp = new MenuPanel("menu", clase, nombre, parametros);
add(mp);
}
}
public class MenuPanel extends Panel {
public MenuPanel(String id, Class<? extends Page> paginaActual, String
nombre, PageParameters parametros){
super(id);
SiSession sesion = (SiSession) getSession();
ArrayList<Menu> lista = sesion.getListMenu();
int index = lista.lastIndexOf(new Menu(paginaActual));
if(index >= 0){
lista = new ArrayList(lista.subList(0, index));
}
ista.add(new Menu(nombre, paginaActual, parametros));
ListView<Menu> listaMenu = new ListView<Menu>("listaMenu", lista) {
@Override
protected void populateItem(ListItem<Menu> item) {
BookmarkablePageLink link = new BookmarkablePageLink<Void>("url",
item.getModelObject().getClase());
link.add(new Label("etiqueta", item.getModelObject().getNombre()));
item.add(link);
}
};
add(listaMenu);
}
}
public class Menu implements IClusterable {
private String nombre;
private Class<? extends Page> clase;
private PageParameters parameters;
private Image imagen;
public Menu(Class clase){
setClase(clase);
}
public Menu(String nombre, Class clase){
setNombre(nombre);
setClase(clase);
}
public Menu(String nombre, Class clase, PageParameters parameters){
setNombre(nombre);
setClase(clase);
setParameters(parameters);
}
...getters & setters
}
all my Pages are like this
public class UnoPage extends LayoutPage {
public UnoPage(){
super(UnoPage.class, "Uno", null);
Link link = new Link("dosPageLink"){
@Override
public void onClick() {
setResponsePage(DosPage.class);
}
};
add(link);
}
}
Thank you!
--
César Alberto Barrera <abarrera at gmail dot com>