首页
论坛
图书
开发资料
在线文档
网址
下载
联系我们
 新闻│Java│JavaScript│Eclipse│Eclipse 英文│J2EE│J2ME│J2SE│JSP│Netbeans│Hibernate│JBuilder│Spring│Struts
站内搜索: 请输入搜索关键词

当前页面: 开发资料首页 → Java 专题 → JSF实例学习--组件显示(隐藏)与数据排序

JSF实例学习--组件显示(隐藏)与数据排序

摘要: JSF实例学习--组件显示(隐藏)与数据排序

</td> </tr> <tr> <td height="35" valign="top" class="ArticleTeitle">

JSF中处理组件的显示和隐藏、数据的排序等相对其它框架非常容易和直接了当, 常被教科书作为实例分析和讲解。下面这个实例来自名为《 Mastering JavaServer Faces中文版》的书(略有改动),通过组件的显示(或隐藏)及数据的排序来讲解JSF中UI组件的用法。
先看看它的界面共三个(1)index.jsp,


(2)ModifyInvoice.jsp,这个修改发票界面有一个显示(隐藏)按钮,点击时可显示(或隐藏)部分组件。

<table width="656" border="0"> <tr> <td width="370"></td> <td width="276" valign="top"> </td> </tr> </table>

(3)ViewInvoices.jsp,显示全部发票的列表。并可以按发票序号和数额排序。

主要看看这个页面中,当点击发票的发票序号时如何正确返回到ModifyInvoice.jsp页面(在我们自己的实践当中一定要遇到的问题啊,通常的做法是超链接当中带参数)。当然首先要在faces-config.xml文件中定义导航法则:

/ViewInvoices.jsp

modifyInvoice
/ModifyInvoice.jsp

从源码可以知道这个页面通过一个 标记来显示所有发票。



...
value="#{invoice.invoiceNumber}" action="#{viewInvoicesPage.modifyInvoice}">


.....

从上看出,当我们点击发票的序号时,JSF调用viewInvoicesPage.modifyInvoice方法。

 public String modifyInvoice() {

        FacesContext facesContext = FacesContext.getCurrentInstance();

       

        UIViewRoot root = facesContext.getViewRoot();

        UIData table = (UIData) root.findComponent("invoiceForm").findComponent("table");

        InvoiceBean invoice = (InvoiceBean) table.getRowData();

        ValueBinding binding = facesContext.getApplication().createValueBinding("#{modifyInvoicePage}");

        ModifyInvoicePage detailPage = (ModifyInvoicePage) binding.getValue(facesContext);

   

        detailPage.setInvoice(invoice);

       

        return "modifyInvoice";

    }

如此看来,当用 标记显示数据时,聪明的JSF用getRowData()可以知道你点击了那一行(即那一个发票号,这实际上是JSF将标记转为HTML链接时自动加上了行索引),再将这一行数据传给 ModifyInvoice.jsp页。


function TempSave(ElementID) { CommentsPersistDiv.setAttribute("CommentContent",document.getElementById(ElementID).value); CommentsPersistDiv.save("CommentXMLStore"); } function Restore(ElementID) { CommentsPersistDiv.load("CommentXMLStore"); document.getElementById(ElementID).value=CommentsPersistDiv.getAttribute("CommentContent"); } </td> </tr> <tr>


↑返回目录
前一篇: JSF验证信息中文化
后一篇: 在JSF中JSP扮演的角色

首页 | 全站 Sitemap | 联系我们 | 设为首页 | 收藏本站
版权所有 Copyright © 2006-2007, Java 编程资料牛鼻站, All rights reserved