【发布时间】:2014-05-12 16:11:13
【问题描述】:
我正在使用以下代码来编辑记录的值。并且代码运行良好。
<rich:popupPanel header="Edit Company Region" id="editCompanyRegionPane"
domElementAttachment="parent" width="230" height="115">
<h:form>
<h:panelGrid columns="3" id="editCompanyRegionGrid">
<h:inputHidden value="#{CompanyAdminPageModel.editCompanyRegion.companyRegionId}"
id="editcompanyRegionId">
</h:inputHidden>
<h:message for="editcompanyRegionId" />
<h:column>
<h:outputText value="Name " />
<h:inputText value="#{CompanyAdminPageModel.editCompanyRegion.name}"
id="editCompanyRegionName">
</h:inputText>
<h:message for="editCompanyRegionName" />
</h:column>
</h:panelGrid>
<h:commandButton value="Update"
action="#{CompanyAdminPageModel.companyRegionUpdate}" render="table"
oncomplete="if (#{facesContext.maximumSeverity==null}) {#{rich:component('editCompanyRegionPane')}.hide();}" />
<h:commandButton value="Cancel"
onclick="#{rich:component('editCompanyRegionPane')}.hide(); return false;" />
</h:form>
</rich:popupPanel>
我想在更新数据库中的值后在同一页面中显示一条消息。例如:当我点击更新按钮时,它会调用 Bean 类的方法,然后更新数据库中的值,关闭弹出面板后,它会在同一页面内显示一条消息(如:更新成功)。
请帮忙。
我使用了以下java代码:
public String updateUser(Long usrId, String firstName, String lastName,
String loginName, String emailAddr) {
AllCompanyDAO aDAO = new AllCompanyDAO();
FacesContext.getCurrentInstance().addMessage("test", new javax.faces.application.FacesMessage("Success"));
return aDAO.userUpdate(usrId, firstName, lastName, loginName, emailAddr);
}
并遵循jsf代码:
<div class="content container">
<div style="padding-left:220px;">
To see the relationships between users and regions <a href="#{appPath}/app/insertion/userRegionInfo.faces" >click here</a> <br/>
<h:message for="test"></h:message>
</div>
</div>
【问题讨论】:
-
您可以使用
FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage("Success"));向FacesContext 发送消息。并且只需一个h:message来显示消息。见FacesContext api -
你能告诉我,我应该在哪里以及如何在我的代码中使用它?
-
只需将其放在更新侦听器方法的末尾即可。如果更新成功,将消息添加到 FacesContext。该消息应显示在您拥有
h:message的位置 -
@peeskillet:我已经编辑了我的问题。请看一下。它现在以我真正想要的方式工作。请看一看。谢谢。
-
如果我使用 FacesContext.getCurrentInstance().addMessage(null, new javax.faces.application.FacesMessage("Success"));然后它在我想要的面板之外显示成功消息。我需要它显示在特定的 div 中。我该怎么做?