2012-09-10 85 views
1

我正在編寫一個JSF頁面,但是,一個commandbutton在頁面加載時多次調用它的動作,但沒有人點擊它......這混亂了我的整個進度......一個命令按鈕動作自動執行多次加載

HTML:

<h:panelGrid columns="2" cellpadding="10"> 
<h:form> 
    <table> 
     <tr> 
      <td>姓名:</td> 
      <td><p:inplace editor="true"><p:inputText value="#{user.name}"/></p:inplace></td> 
     </tr> 
     <tr> 
      <td>聯繫方式:</td> 
      <td><p:inplace editor="true"><p:inputText value="#{user.phone}"/></p:inplace></td> 
     </tr> 
     <tr> 
      <td>性別:</td> 
      <td><h:outputText value="#{user.gender}"/></td> 
     </tr> 
     <tr> 
      <td>身份證號:</td> 
      <td><p:inplace editor="true"><p:inputText value="#{user.pid}"/></p:inplace></td> 
     </tr> 
     <tr> 
      <td style="position:absolute; right:30px;"><p:commandButton value="刪除" action="#{info.removeUser()}"/></td> 
     </tr> 
    </table> 

</h:form> 

的java:

public void removeUser(){ 
    System.out.println("Current tab:"+index +" Removed............"); 
    users.remove(Integer.parseInt(index)); 
} 

這裏的 「指數」 是當前選項卡中accordionPanel,這是一個字符串...

最前一頁時間在這裏提出的問題,也許我省略了一些信息來源...

回答

1

,如果你忘了申報p XML namespage在視圖中,可以發生。

xmlns:p="http://primefaces.org/ui" 

如果你忘了申報p XML命名空間,那麼所有p:xxx標籤被視爲純文本。屬性中的所有EL表達式都會立即執行,就像它們嵌入純文本中一樣。這還包括#{info.removeUser()}表達式。 「很多次」很可能與EL表達式在視圖中出現的量相同。

+0

我認爲我有p聲明...現在我把commandbutton放在頁面的另一個地方,它正常工作 – xlcm

+0

在JSF 2.1項目中使用JSF 2.2的xmlns時,也發生了這種情況。 –