2012-01-28 8 views
1

私はPrimefaces 3.0.1を使用し、プログラムで塗りつぶされたモデルを持つメニューバーを構築します。 depotDetails.xhtmlのようなリンクが必要ですか?SetPropertyActionListenerを正しく追加する方法は?

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 IDが、私は私のメニュー項目のためにこれらのURLを使用する場合

item.setUrl("depotDetail.xhtml?id=1"); // that dont work 

はので、私はActionListenerを追加しようとしました。誰でも助けることができますか?

は、私は解決策を持って...しかし、それは正しい方法であるトーマス・

+0

item.setUrl( "depotDetail.xhtml?id = 1")とは何ですか? //それは動作しませんか? URLが呼び出されていないか、またはURLまたは不完全なURLが含まれていませんか? –

+0

あなたはitem.setUrl( "depotDetail.jsf?id = 1")を試してみましたか? ? – Daniel

+0

はい、私はそれを試したが、パラメータなしでdepotDetail.xhtmlを渡すだけです – thomas

答えて

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"); 
関連する問題