My current environment is JRE 1.7, JSF 2.2, Eclipse Luna. In a certain page (entity_index.xhtml
) of my application I have the following (PrimeFaces) button:
<p:commandButton value="Details" action="entity_details"
ajax="false" onclick="this.form.target='_blank'">
<f:param name="id" value="#{entity.id}" />
</p:commandButton>
The idea is to provide a button so the user can click it and some details on the current entity will be shown in another browser tab (page entity_details.xhtml
). This is one button of many, so the entity_index.xhtml
page shows many instances of Entity, each one with a details button.
The button works in the sense a new tab opens and that the correct page (entity_details.xhtml
) is shown, but the entity id never gets to the bean that handles the detail page (EntityDetailsMB
). The details page is as follows:
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui" xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:dsi="http://www.cce.ufpr.br"
template="/private/template/sbadmin.xhtml">
<f:metadata>
<f:viewParam name="id" value="#{entityDetailsMB.id}"/>
</f:metadata>
<ui:define name="content">
<h2 class="page-header">#{entityDetailsMB.entity.name}</h2>
<h:form id="form">
...
</ui:composition>
Notice that there is a <f:metadata/>
element dedicated to capture the parameter sent from the index page and forward it to the id
property in EntityDetailsMB
, where there is the following:
public Entity getEntity() {
return entityById(id);
}
public Long getId() {
return id;
}
public void setId(Long value) {
id = value;
}
Because the setId()
method is never called, getEntity()
always returns null
.
What is missing to make it to work?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…