首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

jsf 有关问题集锦 转

2012-11-06 
jsf 问题集锦 转1.如何结束session? ?? 你可以使用session的?invalidate方法?. ?? 下面是一个从action方法

jsf 问题集锦 转

  1. 1.如何结束session? ?? 你可以使用session的?invalidate方法?. ??
  2. 下面是一个从action方法中结束session的例子:?: ?? public?String?logout()?{ ??
  3. ??FacesContext?fc?=?FacesContext.getCurrentInstance(); ?? ??HttpSession?session?=?(HttpSession)?fc.getExternalContext().getSession(false); ??
  4. ??session.invalidate(); ?? ??return?"login_page"; ??
  5. }? ?? 下面的代码片段示例了如何在JSP页面中结束session: ??
  6. <%?session.invalidate();?%> ?? <c:redirect?url="loginPage.jsf"?/> ??
  7. ?? ??
  8. 2.如何在JSP页面中访问web.xml中的初始化参数? ?? 你可以使用预定义的JSF?EL变量??initParam来访问: ??
  9. 例如,如果你有: ?? <context-param> ??
  10. ?<param-name>productId</param-name> ?? ?<param-value>2004Q4</param-value> ??
  11. </context-param> ?? 你可以使用她?#{initParam['productId']}来访问?.例如: ??
  12. Product?Id:?<h:outputText?value="#{initParam['productId']}"/> ?? ??
  13. ?? 3.如何从java代码中访问web.xml?中的初始化参数? ??
  14. 你可以使用externalContext的?getInitParameter?方法得到他们.例如?如果你的参数如下: ?? <context-param> ??
  15. ?<param-name>connectionString</param-name> ?? ?<param-value>jdbc:oracle:thin:scott/tiger@cartman:1521:O901DB</param-value> ??
  16. </context-param> ?? 你可以使用下面代码访问connectionString?: ??
  17. FacesContext?fc?=?FacesContext.getCurrentInstance();String?connection?=?fc.getExternalContext().getInitParameter("connectionString");? ?? ??
  18. ?? 4.如何从backing?bean中得到当前页面的URL? ??
  19. 你可以通过FacesContext得到一个Http?Request对象的引用,如下: ?? FacesContext?fc?=?FacesContext.getCurrentInstance();HttpServletRequest?request?=?(HttpServletRequest)?fc.getExternalContext().getRequest();? ??
  20. 然后使用普通的request方法来得到路径信息.还可以使用另外一种方法: ?? context.getViewRoot().getViewId(); ??
  21. 将返回你当前JSP(JSF?view?IDs?基本上只是JSP?path?names)页面的名字. ?? ??
  22. ?? 5.如何添加上下文路径到outputLink的URL中? ??
  23. 在当前的JSF实现中,当在outputLink?中定义的路径以'/'开始时,没有添加上下文路径到URL中,要弥补该问题请在URL中使用?#{facesContext.externalContext.requestContextPath}?前缀.例如: ?? <h:outputLink?value="#{facesContext.externalContext.requestContextPath}/myPage.faces"> ??
  24. ?? ??
  25. 6.如何使用URL字符串来传递参数到JSF程序中? ?? 如果你有下面的URL:?http://your_server/your_app/product.jsf?id=777,?你可以使用下面的代码来访问所传递的参数:?? ??
  26. FacesContext?fc?=?FacesContext.getCurrentInstance();String?id?=?(String)?fc.getExternalContext().getRequestParameterMap().get("id");? ?? 在JSF页面上,你也可以使用预定义的变量访问同样的参数,例如:? ??
  27. <h:outputText?value="#{param['id']}"?/> ?? 注意:?你必须直接调用该JSF页面,并且使用servlet?映射?(mapping). ??
  28. ?? ??
  29. 7.如何在页面重新载入的时候保留h:inputSecret中的密码? ?? 设置redisplay=true,?it?is?false?by?default. ??
  30. ? ?? ??
  31. 8.如何使用h:outputText输出HTML标签? ?? ??
  32. 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后如何显示确认对话框? ?? 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> ??
  33. <h:commandLink?action="delete"?onmousedown="return?ConfirmDelete(this);">??<h:outputText?value="delete?it"/></h:commandLink> ?? ? ??
  34. ?? 9.在调用ValueChangeListener?方法后如何重新装载页面? ??
  35. 在?ValueChangeListener的最后,调用??FacesContext.getCurrentInstance().renderResponse() ?? 如何实现"请等待..."页面??在客户端实现可能很简单.你可以包装JSP页面(或者你想要隐藏的一部分)到一个div中,然后你可以添加更多div,当用户点击提交按钮时这些div出现.这些div可以包含gif动画和其他内容.?场景:当用户点击按钮,调用JS函数,该函数隐藏页面并且显示"请等待..."div.你可以使用CSS来自定义外观:下面是一个正常工作的例子:?<%@?taglib?uri="http://java.sun.com/jsf/html"?prefix="h"?%> ??
  36. <%@?taglib?uri="http://java.sun.com/jsf/core"?prefix="f"?%> ?? <f:loadBundle?basename="demo.bundle.Messages"?var="Message"/> ??
  37. <html> ?? <head> ??
  38. ??<title>Input?Name?Page</title> ?? ??<script> ??
  39. ????function?gowait()?{ ?? ??????document.getElementById("main").style.visibility="hidden"; ??
  40. ??????document.getElementById("wait").style.visibility="visible"; ?? ????} ??
  41. ???</script> ?? ??? ??
  42. ?</head> ?? ?<body?bgcolor="white"> ??
  43. ??<f:view> ?? ????<div?id="main"> ??
  44. ???????<h1><h:outputText?value="#{Message.inputname_header}"/></h1> ?? ???????<h:messages?style="color:?red"/> ??
  45. ???????<h:form?id="helloForm"> ?? ?????????<h:outputText?value="#{Message.prompt}"/> ??
  46. ?????????<h:inputText?id="userName"?value="#{GetNameBean.userName}"?required="true"> ?? ???????????<f:validateLength?minimum="2"?maximum="20"/> ??
  47. ?????????</h:inputText> ?? ?????????<h:commandButton?onclick="gowait()"?id="submit"??
  48. ???????????????action="#{GetNameBean.action}"?value="Say?Hello"?/> ?? ???????</h:form> ??
  49. ????</div> ?? ????<div?id="wait"?style="visibility:hidden;?position:?absolute;?top:?0;?left:?0"> ??
  50. ???????<table?width="100%"?height?="300px"> ?? ?????????<tr> ??
  51. ???????????<td?align="center"?valign="middle"> ?? ?????????????<h2>Please,?wait...</h2> ??
  52. ???????????</td> ?? ?????????</tr> ??
  53. ???????</table> ?? ????</div> ??
  54. ??</f:view> ?? ?</body> ??
  55. </html>? ?? ??
  56. 如果你想有一个动画gif图片在"请等待..."中,当表单提交后该图片应该从新加载.因此,再一次指定图片的id,并且添加经过一段时间延时后重新加载的代码.下面是个例子:?<script> ?? ?function?gowait()?{ ??
  57. ???document.getElementById("main").style.visibility="hidden"; ?? ???document.getElementById("wait").style.visibility="visible"; ??
  58. ???window.setTimeout('showProgress()',?500); ?? ?} ??
  59. ??function?showProgress(){ ?? ???var?wg?=?document.getElementById("waitgif"); ??
  60. ???wg.src=wg.src; ?? ?} ??
  61. </script> ?? .... ??
  62. <img?id="waitgif"?src="animated.gif"> ??

转自于

http://zengjinliang.iteye.com/blog/110596

热点排行