2013-03-11 36 views
0

單擊h:commandButton但希望更新id爲「contents」的div,但複雜的部分是h:commandButton在c:forEach中,因此存在多個h:commandButton s。我想要點擊任何一個命令按鈕時刷新div。有可能使用ajax或jQuery?單擊commandButton時更新div

1)

<h:form> 

<div id="contents"> 
<c:forEach var="p" items="#{statusBean.statusList}"> 
    <h:commandButton>Click Me</h:commandButton> 
    //content 
    </c:forEach>  
</div> 

</h:form> 
+0

發表您的facelet代碼。 – partlov 2013-03-11 19:33:38

+0

我已經包括了一些代碼的形式我Home.xhtml頁 – 2013-03-11 20:39:06

回答

3

首先你按鈕不是一個Ajax按鈕可言,所以加f:ajax裏面:我渲染孔形式

<h:commandButton value="Click Me"> 
    <f:ajax render="@form"/> 
</h:commandButton> 

注意,因爲你的DIV是實際上只在它內部標記。您無法使用JSF更新普通的HTML標籤。您可以將您的div更改爲h:panelGroup,但沒有必要在這個例子中。

+0

如果我要呈現不同的形式,而不是當前的形式,其中H:的commandButton所在,那麼什麼會我在寫渲染'attribute'? – 2013-03-11 20:52:29

+1

例如':form2'如果這是該形式的'id'。只需在該窗體上提供'id':''。 – partlov 2013-03-11 20:53:17