JSF参数传递方式之二:Backing Bean 与 h:inputHidden标签
Backing Bean
页面到Bean的参数传递
页面中设置参数:
后台取参数:
2.2页面到页面的参数传递
页面中设置参数:
注意:h:outputLink 标签不能使用该方式传递参数!
页面中取参数:
- import javax.faces.component.UIInput;
- import javax.faces.component.UIOutput;
- public class BackingBean
- {
- private UIOutputidComponent;
- public UIOutputgetIdComponent()
- {
- return idComponent;
- }
- public void setIdComponent(UIOutputidComponent)
- {
- this .idComponent=idComponent;
- }
- }
页面到Bean的参数传递
页面中设置参数:
- <h:form>
- <h:inputHiddenvalue= "123456" binding= "#{backingBean.idComponent}" ></h:inputHidden>
- <h:commandButtonvalue= "登录" action= "#{paramBean.login}" ></h:commandButton>
- </h:form>
后台取参数:
- FacesContextcontext=FacesContext.getCurrentInstance();
- BackingBeanbackBean=(BackingBean)context.getApplication().getVariableResolver().resolveVariable(context, "backingBean" ); //该方法已经过时
- BackingBeanbean=(BackingBean)context.getApplication().getELResolver().getValue(context.getELContext(), null , "backingBean" );
- backBean.getIdComponent().getValue();
- bean.getIdComponent().getValue();
2.2页面到页面的参数传递
页面中设置参数:
- <h:form>
- <h:inputHiddenvalue= "123456" binding= "#{backingBean.idComponent}" ></h:inputHidden>
- <h:commandButtonvalue= "Test5" action= "param" ></h:commandButton>
- <h:commandLinkvalue= "Test6" action= "param" ></h:commandLink>
- </h:form>
注意:h:outputLink 标签不能使用该方式传递参数!
页面中取参数:
- <h:outputTextvalue= "#{backingBean.idComponent.value}" ></h:outputText>