2015-06-25 42 views
0

我有一个复选框组件<f:attribute><p:ajax listener>如何获得<f:attribute>值<p:ajax listener>方法?

<h:selectManyCheckbox ...> 
    <p:ajax listener="#{locationHandler.setChangedSOI}" /> 
    <f:attribute name="Dummy" value="test" /> 
    ... 
</h:selectManyCheckbox> 

我试图让如下听者方法内的test<f:attribute>值:

public void setChangedSOI() throws Exception { 
    FacesContext context = FacesContext.getCurrentInstance(); 
    Map<String, String> map = context.getExternalContext().getRequestParameterMap(); 
    String r1 = map.get("Dummy"); 
    System.out.println(r1); 
} 

然而,印刷null。我怎么才能得到它?

回答

2

组件属性不作为HTTP请求参数传递。组件属性设置为.. uh,组件属性。即它们存储在UIComponent#getAttributes()中。您可以通过该地图抓住他们。

现在正确的问题显然是如何在ajax监听器方法中获得所需的UIComponent。有2种方式:

  1. 指定AjaxBehaviorEvent参数。它为此目的提供了一种getComponent()方法。

    public void setChangedSOI(AjaxBehaviorEvent event) { 
        UIComponent component = event.getComponent(); 
        String dummy = component.getAttributes().get("Dummy"); 
        // ... 
    } 
    
  2. 使用UIComponent#getCurrentComponent()的辅助方法。

    public void setChangedSOI() { 
        UIComponent component = UIComponent.getCurrentComponent(FacesContext.getCurrentInstance()); 
        String dummy = component.getAttributes().get("Dummy"); 
        // ... 
    } 
    
+0

BalusC嗨,使用你的第一选择,我得到以下错误,2015年6月25日下午1时26分09秒org.apache.catalina.core.StandardWrapperValve调用 重度:Servlet.service( )for servlet Spring MVC Dispatcher Servlet抛出异常 javax.el.MethodNotFoundException:/WEB-INF/certificates/locationList.xhtml @ 162,118 listener =“#{locationHandler.setChangedSOI}”:找不到方法:com.csc.exceed.certificate .web.LocationHandler @ 1ecd6fb.setChangedSOI() \t at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:109) – pkn1230

+0

是否有某些我们无法用Aja调用方法的问题xBehaviourEvent作为使用primefaces的参数? – pkn1230

+0

什么是Spring MVC调度程序servlet在JSF请求中执行的操作?你了解/知道你在做什么? http://stackoverflow.com/questions/18744910/using-jsf-as-view-technology-of-spring-mvc/ – BalusC

相关问题