Как правильно добавить SetPropertyActionListener? - PullRequest
1 голос
/ 28 января 2012

Я использую Primefaces 3.0.1 и создаю строку меню с программно заполненной моделью. Мне нужны некоторые ссылки, такие как depotDetails.xhtml? id = 1 Но если я использую эти URL для моего меню

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);

но это также не работает. Кто-нибудь может помочь?

Привет, Томас

1 Ответ

0 голосов
/ 28 января 2012

У меня есть решение ... но это правильный путь?

// 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");
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...