转载自:http://blog.csdn.net/duankaige/article/details/6711044
1:JSF页面之间传参
方法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>
2:JSF页面之间取得参数
方法1:
<h:outputText value="#{param.name}"></h:outputText>
方法2:
<%=request.getParameter("name")%>
3:JSF页面到后台传参
<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>
4:JSF后台取得页面值
方法1:
HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
request.getParameter("name");
方法2:
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>
当前位置举例及相关总结
1:JS中可以使用java代码。获得当前Bean、获得当前Bean中属性值的java代码。
try{
parent.historyIframe.addHistory('/glp_user/glp_user_view_ViewForm.faces?<%=FacesContext.getCurrentInstance().getApplication().createValueBinding("#{glpUserForm.historyUrlParameter}").getValue(FacesContext.getCurrentInstance())%>','<%=LocaleMessage.getMessage("glpUser.glp_user_view_ViewForm.heading")%>(<%=FacesContext.getCurrentInstance().getApplication().createValueBinding("#{glpUserForm.glpUser.userName}").getValue(FacesContext.getCurrentInstance()) %>)',"1")
}catch(e){}
2:通过配置文件属性注入,param可以将页面上存入request的值放入后台的属性中。
public String getHistoryUrlParameter(){
if(this.glpUserPrimaryKey == null)
return "_key=" + this.glpUser.getUserId();
return "_key=" + this.glpUserPrimaryKey;
}
<managed-bean>
<managed-bean-name>glpUserForm</managed-bean-name>
<managed-bean-class>
cn.com.brilliance.begen.webapp.action.GlpUserForm
</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>glpUser</property-name>
<value>#{glpUser}</value>
</managed-property>
<managed-property>
<property-name>glpUserPrimaryKey</property-name>
<value>#{param._key}</value>
</managed-property>
</managed-bean>