我使用Primefaces 3.0.1并使用以编程方式填充的模型构建菜单栏。我需要一些像depotDetails.xhtml这样的链接? id = 1 但是如果我将这些URL用于我的menuitem
item.setUrl("depotDetail.xhtml?id=1"); // that dont work
所以我尝试添加一个ActionListener:
FacesContext facesContext = FacesContext.getCurrentInstance();
ValueExpression target = facesContext.getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{DepotBean.currentDepot}",String.class);
ValueExpression value = facesContext.getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "ehnemeneee",String.class);
ActionListener handler = new SetPropertyActionListenerImpl(target, value);
item.addActionListener(handler);
但那也行不通。有人可以帮忙吗?
Greets Thomas
答案 0 :(得分:0)
我有一个解决方案......但这是正确的方法吗?
// building the menu model ..
UIParameter param = null;
for(Depots testdepot: depotList){
param = new UIParameter();
param.setName("currentDepotId");
param.setValue(testdepot.getIdDepot());
item = new MenuItem();
item.setValue(testdepot.getDepotName());
// calling menuListener
item.addActionListener(new MenuListener());
item.setUpdate("messages");
item.setId("menuItemDepot"+testdepot.getIdDepot());
item.getChildren().add(param);
submenu.getChildren().add(item);
}
// MenuListener
public void processAction(ActionEvent event) throws AbortProcessingException {
FacesContext fc = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();
HttpSession session = (HttpSession) fc.getExternalContext().getSession(false);
// get param id
String name = (String) event.getComponent().getAttributes().get("currentDepotId");
// set session var
session.setAttribute("currentDepotId", name);
fc.getExternalContext().redirect(request.getContextPath() + "/userarea/depotDetail.xhtml");
}
// read the session in the depot bean
FacesContext fc = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) fc.getExternalContext().getSession(false);
String currentDepotId = session.getAttribute("currentDepotId");