欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

JSF参数传递--richfaces

程序员文章站 2022-07-15 16:37:59
...

参考:http://pity1115.iteye.com/blog/336431

f:param标签

      页面代码:       

 

<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>

    后台取参方法:

 

//通过Request对象取值

HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();

request.getParameter("name");

 

//通过RequestParameterMap取值

Map varMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();

varMap.get("id");

 f:attribute标签传递

页面代码:

 

<h:commandButton action="#{paramBean.test3}" value="Test11" actionListener="#{paramBean.changeName}">

<f:attribute name="name" value="hujilie"/>

</h:commandButton>

  后台取参方法:

 

UIComponent component = e.getComponent(); 
Map<String, Object> map = component.getAttributes(); 
Object nameValue = map.get("name");

 

 

 

f:setPropertyActionListener 标签传递

页面代码:

 

 

 

<h:commandButton action="#{projectBean.searchProject}" value="show project"> 
          <f:setPropertyActionListener value="peter" target="#{projectBean.name}"/> 
</h:commandButton> 

 

 

 

  

后台取参方法:JSF自动完成对属性的赋值;直接使用name属性

 

findProject(name);

  facelets标签:ui:param

可在页面之间传递任意java object(managed Bean)

页面代码:

 

<ui:include src="/pages/contents/process/processDefHead.xhtml" >

<ui:param name="piMgtBean" value="#{processInstanceMgtBean}" />

</ui:include>

 

 richfaces标签:a4j:actionparam

JSF自动完成对属性的赋值;直接使用name属性(限定类型为String)

 

<a4j:commandButton value="Set Name to Alex" reRender="rep" >

<a4j:actionparam name="username" value="Alex" assignTo="#{userBean.name}"/>

</a4j:commandButton>