-
15. Re: Panelmenuitem actions in binding bean not responding
mancio791 Apr 7, 2012 5:24 AM (in response to mancio791)Here is my example, if anyone is interested...have fun !!
page.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:head>
<title>BaseModel</title>
</h:head>
<h:body>
<rich:panel header="Base Model Web Console">
<div id="divHeader">
<div align="center">
<img src="/BaseModelWeb/images/header.png" id="imgHeader" />
</div>
</div>
<rich:panel style="margin-top:10px;">
<h:panelGrid columns="2" width="100%" columnClasses="col">
<a4j:outputPanel>
<div id="divMenuLeft">
<h:form>
<rich:panelMenu style="width:200px" itemMode="server" groupMode="client"
groupExpandedLeftIcon="triangleUp"
groupCollapsedLeftIcon="triangleDown"
topGroupExpandedRightIcon="chevronUp"
topGroupCollapsedRightIcon="chevronDown"
itemLeftIcon="disc"
itemChangeListener="#{panelMenuBean.updateCurrent}"
binding="#{panelMenuBean.panelMenu}" />
</h:form>
</div>
</a4j:outputPanel>
<a4j:outputPanel>
<div id="divMainContent">
<ui:insert name="content">- default content -</ui:insert>
</div>
</a4j:outputPanel>
</h:panelGrid>
</rich:panel>
<rich:panel style="margin-top:10px;">
<div id="divFooter">
<h:outputText value="Footer"/>
</div>
</rich:panel>
</rich:panel>
</h:body>
</html>
PanelBaseModel.java (BBean)
package it.mmspace.base.web.beans.menu;
import it.mmspace.base.service.client.funzioni.FunzioneType;
import it.mmspace.base.service.client.funzioni.FunzioniRequestMessage;
import it.mmspace.base.service.client.funzioni.FunzioniRequestMessage.Licenza;
import it.mmspace.base.service.client.funzioni.FunzioniRequestMessage.Padre;
import it.mmspace.base.service.client.funzioni.FunzioniRequestMessage.Profilo;
import it.mmspace.base.service.client.funzioni.FunzioniResponseMessage;
import it.mmspace.base.service.client.funzioni.FunzioniResponseMessage.Funzioni;
import it.mmspace.base.web.beans.BaseBean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.el.MethodExpression;
import javax.faces.event.ActionEvent;
import javax.faces.event.MethodExpressionActionListener;
import org.richfaces.PanelMenuMode;
import org.richfaces.component.UIPanelMenu;
import org.richfaces.component.UIPanelMenuGroup;
import org.richfaces.component.UIPanelMenuItem;
import org.richfaces.event.ItemChangeEvent;
public class PanelMenuBean extends BaseBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private UIPanelMenu panelMenu = null;
private List<UIPanelMenuGroup> gruppi = new ArrayList<UIPanelMenuGroup>();
private String selectedMenuItem;
private static final String BM_LICENZA = "LCZ0002";
private static final String BM_PROFILO = "UANAG";
@PostConstruct
public void initialize() {
super.getLogger().info("PostConstruct - initialize() [request scope]");
try {
FunzioniRequestMessage req = _createFunzioniRequestMessage();
Licenza licenza = _createFunzioniRequestMessageLicenza();
Profilo profilo = _createFunzioniRequestMessageProfilo();
Padre padre = _createFunzioniRequestMessagePadre();
req.setLicenza(licenza);
req.setProfilo(profilo);
req.setPadre(padre); //null per gli item di primo livello
licenza.setCodice(BM_LICENZA);
profilo.setCodice(BM_PROFILO);
FunzioniResponseMessage resp = _portBMFunzioni.getAlberoFunzioni(req);
Funzioni funzz = resp.getFunzioni();
List<FunzioneType> ff = funzz.getFunzione();
for(FunzioneType f: ff) {
//per ogni primo livello recuperare separatamente i figli
UIPanelMenuGroup gruppo = addChildrenToMenuGroup(f);
gruppi.add(gruppo);
}
panelMenu = (UIPanelMenu)_getApplicationRef().createComponent(_getFacesCtx(),UIPanelMenu.COMPONENT_TYPE,"org.richfaces.PanelMenuRenderer");
panelMenu.getChildren().addAll(gruppi);
}catch(Throwable t) {
super.getLogger().error("Eccezione: "+t.getMessage(),t);
}
}
public void updateCurrent(ItemChangeEvent event) {
super.getLogger().debug("UUUUUU updateCurrent "+event.getNewItem().getId());
//catch selected menu item
selectedMenuItem = event.getNewItem().getId();
}
public String actionCurrent(ActionEvent event) {
super.getLogger().debug("AAAAA actionCurrent "+event.getComponent().getId());
super.getLogger().debug("AAAAA selectedMenuItem "+selectedMenuItem);
//TODO
return "base.example1";
}
public String actionCurrentItem() {
super.getLogger().debug("AAAAA selectedMenuItem "+selectedMenuItem);
//TODO
return "base.example1";
}
/*
* METODI PRIVATI
*/
private UIPanelMenuGroup addChildrenToMenuGroup(FunzioneType f) throws Throwable {
super.getLogger().info("addChildrenToMenuGroup ["+
f.getCodice()+"@"+f.getNome()+" - "+BM_PROFILO+"]");
UIPanelMenuGroup pmg = (UIPanelMenuGroup)_getApplicationRef().createComponent(
_getFacesCtx(),UIPanelMenuGroup.COMPONENT_TYPE,"org.richfaces.PanelMenuGroupRenderer");
pmg.setLabel(f.getNome());
pmg.setId(f.getCodice());
//super.getLogger().debug("[Gruppo Menu Item] "+pmg.getLabel()+ "(codice funzione "+pmg.getId()+")");
//recupero eventuali figli
FunzioniRequestMessage req = _createFunzioniRequestMessage();
Licenza licenza = _createFunzioniRequestMessageLicenza();
Profilo profilo = _createFunzioniRequestMessageProfilo();
Padre padre = _createFunzioniRequestMessagePadre();
req.setLicenza(licenza);
req.setProfilo(profilo);
req.setPadre(padre);
licenza.setCodice(f.getLicenza());
profilo.setCodice(BM_PROFILO);
padre.setCodice(f.getCodice());
FunzioniResponseMessage resp = _portBMFunzioni.getAlberoFunzioni(req);
Funzioni funzz = resp.getFunzioni();
List<FunzioneType> ff = funzz.getFunzione();
//super.getLogger().debug("Figli del singolo Menu Item: "+ff.size());
//figli del menuItemGroup pmg chiamante
List<UIPanelMenuItem> figli = new ArrayList<UIPanelMenuItem>();
for(FunzioneType fc: ff) {
//super.getLogger().debug("Figlio: "+fc.getCodice()+"@"+fc.getNome());
//recupero eventuali figli di menuItem
//super.getLogger().debug("Recupero eventuali figli del figlio");
UIPanelMenuGroup gruppoFiglio = addChildrenToMenuGroup(fc);
if(gruppoFiglio.getChildCount() > 0) {
//super.getLogger().debug("Figli presenti");
pmg.getChildren().add(gruppoFiglio);
}
else {
//add child to group
UIPanelMenuItem menuItem = (UIPanelMenuItem)_getApplicationRef().createComponent(
_getFacesCtx(),UIPanelMenuItem.COMPONENT_TYPE,"org.richfaces.PanelMenuItemRenderer");
menuItem.setLabel(fc.getNome());
menuItem.setId(fc.getCodice());
/*
MethodExpression actionExpr = _getApplicationRef().getExpressionFactory()
.createMethodExpression(_getFacesCtx().getELContext(),
"#{panelMenuBean.actionCurrent}",
Void.class,
new Class[] { ActionEvent.class });
menuItem.addActionListener(new MethodExpressionActionListener(actionExpr));
*/
MethodExpression actionItemExpr = _getApplicationRef().getExpressionFactory()
.createMethodExpression(_getFacesCtx().getELContext(),
"#{panelMenuBean.actionCurrentItem}",
Void.class,
new Class[] { });
menuItem.setActionExpression(actionItemExpr);
menuItem.setMode(PanelMenuMode.ajax);
pmg.getChildren().add(menuItem);
//super.getLogger().debug("Figlio aggiunto al gruppo del padre");
}
}
pmg.getChildren().addAll(figli);
return pmg;
}
public List<UIPanelMenuGroup> getGruppi() {
return gruppi;
}
public void setGruppi(List<UIPanelMenuGroup> gruppi) {
this.gruppi = gruppi;
}
public UIPanelMenu getPanelMenu() {
return panelMenu;
}
public void setPanelMenu(UIPanelMenu panelMenu) {
this.panelMenu = panelMenu;
}
public String getSelectedMenuItem() {
return selectedMenuItem;
}
public void setSelectedMenuItem(String selectedMenuItem) {
this.selectedMenuItem = selectedMenuItem;
}
}
second page to load from menu item action
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:body>
<ui:composition template="/pages/base/layout/layout2.xhtml">
<ui:define name="content">
<h:outputText value="Toro" />
</ui:define>
</ui:composition>
</h:body>
</html>
for any question i will reply as soon as possible ....