JSF参数传递方式之二:Backing Bean 与 h:inputHidden标签

JSF参数传递方式之二:Backing Bean 与 h:inputHidden标签

Backing Bean
Java代码 复制代码
  1. importjavax.faces.component.UIInput;
  2. importjavax.faces.component.UIOutput;
  3. publicclassBackingBean
  4. {
  5. privateUIOutputidComponent;
  6. publicUIOutputgetIdComponent()
  7. {
  8. returnidComponent;
  9. }
  10. publicvoidsetIdComponent(UIOutputidComponent)
  11. {
  12. this.idComponent=idComponent;
  13. }
  14. }
import javax.faces.component.UIInput;
import javax.faces.component.UIOutput;

public class BackingBean
{

    private UIOutput idComponent;

    public UIOutput getIdComponent()
    {
        return idComponent;
    }

    public void setIdComponent(UIOutput idComponent)
    {
        this.idComponent = idComponent;
    }


}

页面到Bean的参数传递
页面中设置参数:
Java代码 复制代码
  1. <h:form>
  2. <h:inputHiddenvalue="123456"binding="#{backingBean.idComponent}"></h:inputHidden>
  3. <h:commandButtonvalue="登录"action="#{paramBean.login}"></h:commandButton>
  4. </h:form>
<h:form>
			<h:inputHidden value="123456" binding="#{backingBean.idComponent}"></h:inputHidden>
			<h:commandButton value="登录" action="#{paramBean.login}"></h:commandButton>
		</h:form>

后台取参数:
Java代码 复制代码
  1. FacesContextcontext=FacesContext.getCurrentInstance();
  2. BackingBeanbackBean=(BackingBean)context.getApplication().getVariableResolver().resolveVariable(context,"backingBean");//该方法已经过时
  3. BackingBeanbean=(BackingBean)context.getApplication().getELResolver().getValue(context.getELContext(),null,"backingBean");
  4. backBean.getIdComponent().getValue();
  5. bean.getIdComponent().getValue();
FacesContext context = FacesContext.getCurrentInstance();
        BackingBean backBean =(BackingBean)context.getApplication().getVariableResolver().resolveVariable(context,"backingBean");//该方法已经过时
        BackingBean bean =(BackingBean)context.getApplication().getELResolver().getValue(context.getELContext(), null, "backingBean");
        backBean.getIdComponent().getValue();
        bean.getIdComponent().getValue();

2.2页面到页面的参数传递
页面中设置参数:
Java代码 复制代码
  1. <h:form>
  2. <h:inputHiddenvalue="123456"binding="#{backingBean.idComponent}"></h:inputHidden>
  3. <h:commandButtonvalue="Test5"action="param"></h:commandButton>
  4. <h:commandLinkvalue="Test6"action="param"></h:commandLink>
  5. </h:form>
<h:form>
		<h:inputHidden value="123456" 			binding="#{backingBean.idComponent}"></h:inputHidden>
		<h:commandButton value="Test5" 	action="param"></h:commandButton>
		<h:commandLink value="Test6" action="param"></h:commandLink>
	</h:form>

注意:h:outputLink 标签不能使用该方式传递参数!
页面中取参数:
Java代码 复制代码
  1. <h:outputTextvalue="#{backingBean.idComponent.value}"></h:outputText>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值