2014-11-05 98 views
0

示例頁面。 JSF 2 + f:ajax +監聽器不叫

<tr:outputText value="#{my.name}" id="name"/> 
<tr:commandButton text="Click" action="#{my.doaction}" id="test1"> 
<f:ajax event="click" listener="#{my.myajax}" render="name"></f:ajax> 
</tr:commandButton> 
</tr:form> 
</ui:define> 
</ui:composition> 

管理豆...範圍請求

@PostConstruct 
public void init(){ 
    _name = "default"; 
} 

public void doaction(){ 
    System.out.println("In doaction"); 
} 

public void myajax(AjaxBehaviorEvent ae) throws javax.faces.event.AbortProcessingException{ 
    _name = "Ajax"; 
} 

public void myajax() throws javax.faces.event.AbortProcessingException{ 
    _name = "Ajax"; 
} 

我使用特立尼達按鈕。 jsf 2.我的監聽器沒有被調用。沒有一個myajax(AjaxBehaviorEvent ae) myajax() 被調用。但是我的doaction方法正在被調用。 我在想什麼。 ?

請大家幫忙。

注意:我的facesconfig在下面。是否指定2.2並使用trinidad 2.0和myfaces 2.0創建此問題?

<faces-config 
xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd" 
version="2.2"> 
<application> 
<default-render-kit-id>org.apache.myfaces.trinidad.core</default-render-kit-id> 
</application> 
</faces-config> 
+0

是不是叫*? (設置斷點!)還是沒有存儲的值?取決於trinidads命令按鈕的工作方式,它可能會在單擊之後簡單地導致重新加載,再次調用'init()',導致bean爲'RequestScoped',並在第二個請求中覆蓋name屬性。 – dognose 2014-11-05 18:52:25

+0

我確實在ajax方法中都放了一個斷點,其中沒有一個是被打的.. – sam 2014-11-05 19:37:11

回答

0

您不能將在ajax中調用的操作與在h:commandButton中刷新頁面的操作混合在一起。

你必須選擇。

你試過這樣嗎?

<tr:commandButton text="Click" id="test1"> 
    <f:ajax event="click" listener="#{my.doaction}" render="name" /> 
    <f:ajax event="click" listener="#{my.myajax}" render="name" /> 
</tr:commandButton>