在数据表上,我单击commandLink,该链接导航到目标页面。我需要在该目标网页上获取参数(' id'在本例中为)。
链接可以正常工作,但不能使用commandLink。我将参数设为null。我必须使用commandLink解决这个问题。
源页面
<p:dataTable value="#{orderBean.orders}" var="order" id="orderDTable" rowKey="#{order.id}">
<p:column id="editButtonsId" >
<p:commandLink value="Edit" action="orderInsert" >
<f:param name="id" value="#{order.id}"/>
</p:commandLink>
<!-- works fine with this link -->
<p:link value="Edit" outcome="orderInsert" >
<f:param name="id" value="#{order.id}" />
</p:link>
</p:column>
</p:dataTable>
目标网页
<ui:composition template="templates/layout.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:components="http://java.sun.com/jsf/composite/components"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:p="http://primefaces.org/ui">
<f:metadata>
<f:viewParam name="id" value="#{orderInsertBean.id}" />
<f:event listener="#{orderInsertBean.init}" type="preRenderView" />
</f:metadata>
</ui:composition>
@Component("orderInsertBean")
@ManagedBean
@RequestScoped
public class OrderInsertBean implements Serializable {
private String id;
public void init() {
// the parameter id is null here when the page is navigated by the commandLink
FacesMessage msg = new FacesMessage(id, null);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public String getId() { return id; }
public void setId(String id) { this.id = id; }
}
答案 0 :(得分:-1)
Semantics of "?faces-redirect=true" in <commandlink action=...> and why not use it everywhere
f:param does not work with p:commandLink or h:commandLink on query string
使用commandLink
,您可以使用显示here的@ManagedProperty
注释ID,也可以使用请求参数map:
public void init() {
FacesContext context = FacesContext.getCurrentInstance();
Map requestParams = context.getExternalContext().getRequestParameterMap();
id = (String) requestParams.get("id");
// the parameter id is null here when the page is navigated by the commandLink
FacesMessage msg = new FacesMessage(id, null);
FacesContext.getCurrentInstance().addMessage(null, msg);
}