大家如果有什么好的方法,分享出来哦
jsf 本身很强大,很多功能都实现了,程序员只需要调用它的组件,BUT虽然jsf有很多组件,有时的确不满足当前需求,比如信息提示,下面列出最常用的3种。
1)直接alert (简单了吧,嘿嘿)
2)用模态窗口来输出信息 (这个有点难)
3)在页面的一个专门的div用ajax来输出信息
jsf从后台传给前台的信息有两种方式,在本文中用第二种方式
a)先把信息设置到jsf的Bean中,再在jsf页面中用el取出来就是
b)用jsf的message组件
后台
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("保存成功"));
页面
<rich:messages ></rich:messages>
好了,现在开始用richfaces来实现信息提示
通过自己的理解加g.cn 加 baidu.com 其实richfaces里用alert是最难的,所以把alert放在最后吧,倒是2),3)实现起来比较方便
1)先来模态窗口
首先是userBean
@ManagedBean(name = "userBean")
@SessionScoped
public class UserBean implements Serializable {
private String name;
private String password;
public void login(ActionEvent event){
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(name + " login 成功"));
}
public String getName() {
return name;
}
public void setName(String newValue) {
name = newValue;
}
public String getPassword() {
return password;
}
public void setPassword(String newValue) {
password = newValue;
}
}
然后是页面
<body>
<rich:modalPanel id="messagePanel" width="350" height="100" >
<f:facet name="header">
<h:panelGroup>
<h:outputText value="Modal Panel"></h:outputText>
</h:panelGroup>
</f:facet>
<f:facet name="controls">
<h:panelGroup>
<h:graphicImage value="/images/close.png" styleClass="hidelink" id="hidelink"/>
<rich:componentControl for="messagePanel" attachTo="hidelink" operation="hide" event="onclick"/>
</h:panelGroup>
</f:facet>
<h:panelGroup >
<rich:messages ></rich:messages>
</h:panelGroup>
</rich:modalPanel>
<h:form>
<h3>Please enter your name and password.</h3>
<table>
<tr>
<td>Name:</td>
<td><h:inputText value="#{userBean.name}"/></td>
</tr>
<tr>
<td>Password:</td>
</tr>
</table>
<p><a4j:commandButton value="Login" actionListener="#{userBean.login}" reRender="messagePanel" oncomplete="#{rich:component('messagePanel')}.show()"></a4j:commandButton></p>
</h:form>
</body>
效果图如下
but如果每个按钮都写oncomplete="#{rich:component('messagePanel')}.show()"成这样就太复杂了所以就有了升级版
<body>
<h:panelGroup id="messageGroup" >
<rich:modalPanel id="messagePanel" width="350" height="100" showWhenRendered="true" rendered="#{!empty facesContext.maximumSeverity}">
<f:facet name="header">
<h:panelGroup>
<h:outputText value="Modal Panel"></h:outputText>
</h:panelGroup>
</f:facet>
<f:facet name="controls">
<h:panelGroup>
<h:graphicImage value="/images/close.png" styleClass="hidelink" id="hidelink"/>
<rich:componentControl for="messagePanel" attachTo="hidelink" operation="hide" event="onclick"/>
</h:panelGroup>
</f:facet>
<h:panelGroup >
<rich:messages ></rich:messages>
</h:panelGroup>
</rich:modalPanel>
</h:panelGroup>
<h:form>
<h3>Please enter your name and password.</h3>
<table>
<tr>
<td>Name:</td>
<td><h:inputText value="#{userBean.name}"/></td>
</tr>
<tr>
<td>Password:</td>
</tr>
</table>
<p><a4j:commandButton value="Login" actionListener="#{userBean.login}" reRender="messageGroup" ></a4j:commandButton></p>
</h:form>
</body>
2)专门的div用ajax来输出信息,这个在richfaces里简直是太简单了
<body>
<h:form>
<h3>Please enter your name and password.</h3>
<table>
<tr>
<td>Name:</td>
<td><h:inputText value="#{userBean.name}"/></td>
</tr>
<tr>
<td>Password:</td>
</tr>
</table>
<p><a4j:commandButton value="ajaxLogin" actionListener="#{userBean.login}" ></a4j:commandButton></p>
<h:panelGroup >
<rich:messages ></rich:messages>
</h:panelGroup>
</h:form>
</body>
效果图为
先就写到这吧有时间了再写
- 大小: 13.1 KB
- 大小: 9.2 KB
分享到:
相关推荐
Richfaces标签 简介Richfaces标签相关内容 初学者认知
richfaces标签学习笔记richfaces标签学习笔记richfaces标签学习笔记richfaces标签学习笔记
教会如何使用richfaces,及richfaces应用
这是richfaces 3.3.1的用户手册PDF版
关于richfaces的一些比较好的资料,希望大家看了能有收获
Richfaces组件使用指南、richfaces手册(很详细、很全面的教程)
RichFaces组件简介,复合组件,日期控件,Ajax标签, 轻松实现。RichFaces组件简介,复合组件,日期控件,Ajax标签, 轻松实现。RichFaces组件简介,复合组件,日期控件,Ajax标签, 轻松实现。
RichFaces_3.3.3_TLD.chm
richfaces中文开发文档 纯中文 适合维护老项目的人
richfaces3.1.4版的demo,运行在jboss和tomcat5.5下
Richfaces ShowCase离线包,可直接在tomcat下部署,含在线演示例子。
richfaces JSF API Document
RichFaces4.5 JavaApi JSApi API文档 英文版
Richfaces3.3.3常用组件使用手册 便于学习Richfaces和a4j和jsf框架 很好很实用
richfaces4.0所需的jar包,richfaces4.0所需的jar包,richfaces4.0所需的jar包,
richfaces 最新在线demo下载
使用richfaces需要用到的jar包! commons-beanutils-1.7.0.jar,commons-codec-1.3.jar,commons-collections-3.2.jar,commons-digester-1.8.jar,commons-discovery-0.4.jar,commons-el-1.0.jar,commons-...
richfaces环境搭建所需要的jar richfaces-api-3.3.1.GA.jar richfaces-impl-3.3.1.GA.jar richfaces-ui-3.3.1.GA.jar 希望对搭建有帮助
richfaces-ui-3.1.2的组件。AJAX基于jsf。全程是JBoss RichFaces ,不知道为什么在Exadel上找不到免费下载,还不清楚和Exadel RichFaces在代码中的关系到了什么程度。
RichFaces是一个开源框架,它不借助于JavaScript而增加Ajax能力到存在的JSF应用程序中。