当前位置: 代码迷 >> JavaScript >> JSF2.0札记
  详细解决方案

JSF2.0札记

热度:669   发布时间:2012-08-29 08:40:14.0
JSF2.0笔记

1. Get ContextPath in JSF

In jsp/jsf/html file you can get contextpath using:
?? #{facesContext.externalContext.requestContextPath}
And in bean you can get context path using:
?? FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath()

?

NOTE :Most of the JSF components are fully aware of their context paths, so you don't need to explicitly include them. I know that the graphicImage tag is one of them. So you're actually being more clever than you need to be.

?

We can get remote address and port if you have HttpServletRequest object something like below:
?? ((HttpServletRequest ) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getRemoteAddr() ;
?? ((HttpServletRequest ) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getRemoteHost() ;
?? ((HttpServletRequest ) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getRemotePort();

?

2. URL 传递参数到 JSF 程序中

如果你有下面的URL:?http://your_server/your_app/product.jsf?id=777,? 你可以使用下面的代码来访问所传递的参数 :???

FacesContext?fc?=?FacesContext.getCurrentInstance();
?String?id?=?(String)?fc.getExternalContext().getRequestParameterMap().get("id");

?

JSF 页面上 , 你也可以使用预定义的变量 param 访问同样的参数 , 例如 :??

? <h:outputText?value="#{param ['id']}"?/>

?

3. Managed?Bean 中调用另一个 Managed?Bean

FacesContext?facesContext?=?FacesContext.getCurrentInstance();
TestHandler?ush?=?(TestHandler)?facesContext.getApplication().getVariableResolver().resolveVariable(facesContext,??? "testHandler");

?

?

4. Maven开发使用jetty插件 部署JSF2.0的问题:

mvn jetty:run? jetty中使用jetty测试JSF2.0存在问题: Managed Bean中@ManagedBean\@SessionScoped等注解不会生效――原因是没有扫描在/target/目录下的class文件导致(maven项目编译后的class等输出都在target目录中)。

?

如果使用mvn jetty:run-war? 就不会有问题 !!! (不会自动更新部署新修改的代码)

有时间做个详细的描述......

?