2012-04-04 92 views
1

如何使用Primefaces和Ajax(或不使用)渲染部分xhtml頁面。其他一切正在工作,當用戶按下複選框時,顯示消息,但usernamecontent從不更新。在這種情況下如何刷新panelgrid?我完全新手使用AJAX,今天:)如何使用AJAX或JSF刷新頁面的一部分?

<h:outputLabel value="Do you want to create username?" for="description" /> 
    <p:selectBooleanCheckbox value="#{testController.selectedNew.asUser}"> 
    <p:ajax update="msg" listener="#{testController.selectedNew.addMessage()}"/> 
    <p:ajax update="usernamecontent"/> ------> **This is not working!** 
    </p:selectBooleanCheckbox> 

    <h:panelGrid columns="2" id="usernamecontent" rendered="#{testController.selected.asUser}"> 
    <h:outputLabel value="#{bundle.CreateUserLabel_userUsername}" for="username" /> 
    <p:inputText id="username" value="#{testController.selectedNew.userUsername.username}" title="#{bundle.CreateUsersTitle_username}" required="true" requiredMessage="#{bundle.CreateUserRequiredMessage_username}"/> 

    <h:outputLabel value="#{bundle.CreateUsersLabel_password}" for="password" /> 
    <p:inputText id="password" value="#{testController.selectedNew.userUsername.password}" title="#{bundle.CreateUserTitle_password}" required="true" requiredMessage="#{bundle.CreateUserRequiredMessage_password}"/> 
    </h:panelGrid> 

感謝 薩米

回答

1

usernamecontent組件開始通過自己在服務器端有條件地顯示。爲了能夠對組件進行ajax更新,您需要確保始終呈現相關組件,因爲它最終需要在客戶端更新它。

您需要將其包裝在始終呈現的其他組件中,以便JavaScript可以隨時訪問它以更新內容。

<h:panelGroup id="usernamecontent"> 
    <h:panelGrid columns="2" rendered="#{testController.selected.asUser}"> 
     ... 
    </h:panelGrid> 
</h:panelGroup> 
+0

就是這樣:)非常感謝,kiitos kiitos!順便說一句,你有很好的指導或書籍的想法鏈接什麼讀取jsf + ajax跳轉開始?你有這個想法:http://stackoverflow.com/questions/10003274/jpa-manytomany-in-case-of-users-and-groups/10003452#10003452 – Sami 2012-04-04 22:45:30

+0

不客氣。您可能會發現[JSF 2.0中的通信](http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html)有幫助。 – BalusC 2012-04-04 22:47:40