JSF参数传递方式之一:f:param标签

[color=black][size=large]页面到Bean的参数传递[/size][/color]
页面中设置参数:

<h:form>
<h:commandLink value="Test2" action="#{paramBean.test}">
<f:param name="name" value="zhang"></f:param>
<f:param name="id" value="123456"></f:param>
</h:commandLink>
</h:form>


[color=red]注意:这里只能使用h:commandLink标签,而不能使用h:commandButton标签![/color]
后台取参数:
(1) 通过Request对象取值
HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
request.getParameter("name");

(2)通过RequestParameterMap取值
Map varMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
varMap.get("id");

(3)通过配置文件进行Bean的属性值注入,在Bean的方法中直接使用属性
<managed-bean>
<managed-bean-name>paramBean</managed-bean-name>
<managed-bean-class>com.spg.bean.ParamBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>id</property-name>
<property-class>java.lang.String</property-class>
<value>#{param.id} </value>
</managed-property>
</managed-bean>

[color=black][size=large]页面到页面的参数传递[/size][/color]
页面中设置参数:
(1)
<h:outputLink value="param2.jsf">
<h:outputText value="Test4"></h:outputText>
<f:param name="name" value="chen"></f:param>
<f:param name="id" value="123456"></f:param>
</h:outputLink>

(2)
<h:outputLink value="param2.jsf?name=chen&id=123456">
<h:outputText value="Test4"></h:outputText>
</h:outputLink>

[color=red]注意:以上两种方法,不能同时使用![/color]
页面中取参数:
(1) 使用JSF的值表达式
<h:outputText value="#{param.name}"></h:outputText>	
<h:outputText value="#{param.id}"></h:outputText>

(2) 使用JSP的表达式
<%=request.getParameter("name")%>
<%=request.getParameter("id")%>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值