简体   繁体   English

如何用AJAX或JSF刷新部分页面?

[英]How to refresh part of the page with AJAX or JSF?

How to render part by part xhtml-page with Primefaces and Ajax (or without).如何使用 Primefaces 和 Ajax(或不使用)逐部分呈现 xhtml 页面。 Everything else is working, when the user press the checkbox, message is shown, but usernamecontent is never updated.其他一切正常,当用户按下复选框时,会显示消息,但用户名内容永远不会更新。 How to refresh panelgrid in that case?在这种情况下如何刷新 panelgrid? I am totally newbie with AJAX, started today:)我完全是 AJAX 的新手,今天开始:)

<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>

Thanks Sami谢谢萨米

Your usernamecontent component is by itself conditionally rendered in the server side.您的usernamecontent组件本身在服务器端有条件地呈现。 In order to be able to ajax-update components, you need to ensure that the component in question is always rendered, because it's in the end the JavaScript which needs to update it in the client side.为了能够 ajax 更新组件,您需要确保始终呈现有问题的组件,因为它最终需要在客户端更新它的 JavaScript。

You need to wrap it in another component which is always rendered, so that JavaScript can always access it in order to update the content.您需要将它包装在另一个始终呈现的组件中,以便 JavaScript 始终可以访问它以更新内容。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM