posts - 5,  comments - 7,  trackbacks - 0
        1. 1.如何結束session?   
        2. 你可以使用session的 invalidate方法 .   
        3. 下面是一個從action方法中結束session的例子: :   
        4. public String logout() {    
            FacesContext fc 
          = FacesContext.getCurrentInstance();    
            HttpSession session 
          = (HttpSession) fc.getExternalContext().getSession(false);    
            session.invalidate();    
            
          return "login_page";    
          }
             

           

        5. 下面的代碼片段示例了如何在JSP頁面中結束session:   
        6. <% session.invalidate(); %>    
          <c:redirect url="loginPage.jsf" />    
             

        7.   
        8. 2.如何在JSP頁面中訪問web.xml中的初始化參數?   
        9. 你可以使用預定義的JSF EL變量  initParam來訪問:   
        10. 例如,如果你有:   
        11.  

          <context-param>    
           
          <param-name>productId</param-name>    
           
          <param-value>2004Q4</param-value>    
          </context-param>    

           

        12. 你可以使用她 #{initParam['productId']}來訪問 .例如:   
        13. Product Id: <h:outputText value="#{initParam['productId']}"/>   
        14.   
        15.   
        16. 3.如何從java代碼中訪問web.xml 中的初始化參數?   
        17. 你可以使用externalContext的 getInitParameter 方法得到他們.例如 如果你的參數如下:   
        18.  

          <context-param>    
           
          <param-name>connectionString</param-name>    
           
          <param-value>jdbc:oracle:thin:scott/tiger@cartman:1521:O901DB</param-value>    
          </context-param>    

           

        19. 你可以使用下面代碼訪問connectionString :   
        20. FacesContext fc = FacesContext.getCurrentInstance();String connection = fc.getExternalContext().getInitParameter("connectionString");    
        21.   
        22.   
        23. 4.如何從backing bean中得到當前頁面的URL?   
        24. 你可以通過FacesContext得到一個Http Request對象的引用,如下:   
        25. FacesContext fc = FacesContext.getCurrentInstance();HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();    
        26. 然后使用普通的request方法來得到路徑信息.還可以使用另外一種方法:   
        27. context.getViewRoot().getViewId();   
        28. 將返回你當前JSP(JSF view IDs 基本上只是JSP path names)頁面的名字.   
        29.   
        30.   
        31. 5.如何添加上下文路徑到outputLink的URL中?   
        32. 在當前的JSF實現中,當在outputLink 中定義的路徑以'/'開始時,沒有添加上下文路徑到URL中,要彌補該問題請在URL中使用 #{facesContext.externalContext.requestContextPath} 前綴.例如:   
        33. <h:outputLink value="#{facesContext.externalContext.requestContextPath}/myPage.faces">   
        34.   
        35.   
        36. 6.如何使用URL字符串來傳遞參數到JSF程序中?   
        37. 如果你有下面的URL: http://your_server/your_app/product.jsf?id=777, 你可以使用下面的代碼來訪問所傳遞的參數:     
        38. FacesContext fc = FacesContext.getCurrentInstance();String id = (String) fc.getExternalContext().getRequestParameterMap().get("id");    
        39. 在JSF頁面上,你也可以使用預定義的變量訪問同樣的參數,例如:    
        40. <h:outputText value="#{param['id']}" />   
        41. 注意: 你必須直接調用該JSF頁面,并且使用servlet 映射 (mapping).   
        42.   
        43.   
        44. 7.如何在頁面重新載入的時候保留h:inputSecret中的密碼?   
        45. 設置redisplay=true, it is false by default.   
        46.     
        47.   
        48. 8.如何使用h:outputText輸出HTML標簽?   
        49.   
        50. h:outputText有一個  escape 屬性用來處理html 標簽. 默認值為true.這意味著所有特殊的符合都被轉義為'&'代碼. 請看下面示例:  <h:outputText value="<b>This is a text</b>"/> 打印的結果是:  <b>This is a text</b>  而 <h:outputText escape="false" value="<b>This is a text</b>"/>  打印的結果是:  This is a text  當用戶點擊Command Link后如何顯示確認對話框?   
        51. h:commandLink指定了 onclick 屬性為內部使用. 因此你不可以使用她了, 該問題已經在JSF1.2中修復了,對于JSF1.2以前的版本,你可以在onclick以前使用  onmousedown 事件  <script  language="javascript">  function ConfirmDelete(link) {    var delete = confirm('Do you want to Delete?');    if (delete == true) {      link.onclick();    }  }</script>   
        52. <h:commandLink action="delete" onmousedown="return ConfirmDelete(this);">  <h:outputText value="delete it"/></h:commandLink>   
        53.     
        54.   
        55. 9.在調用ValueChangeListener 方法后如何重新裝載頁面?   
        56. 在 ValueChangeListener的最后,調用  FacesContext.getCurrentInstance().renderResponse()   
        57. 如何實現"請等待..."頁面? 在客戶端實現可能很簡單.你可以包裝JSP頁面(或者你想要隱藏的一部分)到一個div中,然后你可以添加更多div,當用戶點擊提交按鈕時這些div出現.這些div可以包含gif動畫和其他內容. 場景:當用戶點擊按鈕,調用JS函數,該函數隱藏頁面并且顯示"請等待..."div.你可以使用CSS來自定義外觀:下面是一個正常工作的例子: <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>   
        58. <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>    
          <f:loadBundle basename="demo.bundle.Messages" var="Message"/>    
          <html>    
          <head>    
            
          <title>Input Name Page</title>    
            
          <script>    
              function gowait() {    
                document.getElementById("main").style.visibility="hidden";    
                document.getElementById("wait").style.visibility="visible";    
              }    
             
          </script>    
                 
           
          </head>    
           
          <body bgcolor="white">    
            
          <f:view>    
              
          <div id="main">    
                 
          <h1><h:outputText value="#{Message.inputname_header}"/></h1>    
                 
          <h:messages style="color: red"/>    
                 
          <h:form id="helloForm">    
                   
          <h:outputText value="#{Message.prompt}"/>    
                   
          <h:inputText id="userName" value="#{GetNameBean.userName}" required="true">    
                     
          <f:validateLength minimum="2" maximum="20"/>    
                   
          </h:inputText>    
                   
          <h:commandButton onclick="gowait()" id="submit"   
                         action
          ="#{GetNameBean.action}" value="Say Hello" />    
                 
          </h:form>    
              
          </div>    
              
          <div id="wait" style="visibility:hidden; position: absolute; top: 0; left: 0">    
                 
          <table width="100%" height ="300px">    
                   
          <tr>    
                     
          <td align="center" valign="middle">    
                       
          <h2>Please, wait</h2>    
                     
          </td>    
                   
          </tr>    
                 
          </table>    
              
          </div>    
            
          </f:view>    
           
          </body>    
          </html>     
             

          如果你想有一個動畫gif圖片在"請等待..."中,當表單提交后該圖片應該從新加載.因此,再一次指定圖片的id,并且添加經過一段時間延時后重新加載的代碼.下面是個例子: <script>   

           

           function gowait() {    
             document.getElementById("main").style.visibility="hidden";    
             document.getElementById("wait").style.visibility="visible";    
             window.setTimeout('showProgress()', 500);    
           }    
            function showProgress(){    
             var wg = document.getElementById("waitgif");    
             wg.src=wg.src;    
           }    
          </script>    
          .    
          <img id="waitgif" src="animated.gif">   
          posted on 2008-12-01 09:55 Vincent-chen 閱讀(303) 評論(0)  編輯  收藏 所屬分類: JSF
          主站蜘蛛池模板: 锦州市| 郸城县| 吴堡县| 连城县| 教育| 镇坪县| 汪清县| 比如县| 乾安县| 长垣县| 陆良县| 芒康县| 和平区| 岑溪市| 县级市| 红桥区| 浪卡子县| 天长市| 郯城县| 南安市| 姜堰市| 白河县| 博兴县| 武义县| 灯塔市| 雷波县| 东至县| 周至县| 上杭县| 乌恰县| 武城县| 高雄县| 东莞市| 基隆市| 南召县| 思南县| 阿克| 历史| 齐齐哈尔市| 辽宁省| 理塘县|