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  就不会有问题 !!! (不会自动更新部署新修改的代码)

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值