0

我试图将数据从一个 jsf 页面发送到另一个页面,但没有成功。

第一页.xhtml

<h:form>
<p:dataTable id="dataList" value="#{firstBean.dataList}" var="data">
<p:column>
<f:facet name="header">Column 1</f:facet>                            
#{data.column1.id}
</p:column>

<p:column>
<f:facet name="header" >Column 2</f:facet>                            
#{data.colum2.name}
</p:column>

<p:column>
<f:facet name="header" >Detail Row</f:facet>                            
<!-- I need this button send me to another page where i will detail information about an certain id -->
<h:commandButton value="Detalhar" action="#{firstBean.someMethod}">
<f:param name="dataId" value="#{data.column1.id}"/>
</h:commandButton>
</p:column>
</p:dataTable>
</h:form>

第一豆

@ManagedBean
@ViewScoped
public class FirstBean implements Serializable{

private static final long serialVersionUID = 1L;

//list with some data
private List<Data> dataList; //getter setter

@EJB
MyDataManager manager;

@PostConstruct
public void init() {
dataList = manager.getDataList();
}

public void someMethod() throws IOException {
//do something
FacesContext.getCurrentInstance().getExternalContext().redirect("secondPage.xhtml");
}
}

第二页.xhtml

<h:body>
<f:metadata>
<f:viewParam name="dataId" value="#{secondBean.dataDetailId}" />
<f:viewAction action="#{secondBean.init}" />
</f:metadata>

<p:dataTable value="#{secondBean.dataDetailList}" var="dataDetail">
<p:column>
<f:facet name="header">Data Detail 1</f:facet>                            
#{dataDetail.data1}
</p:column>

<p:column>
<f:facet name="header">Data Detail 2</f:facet>                            
#{dataDetail.data2}
</p:column>

<p:column>
<f:facet name="header">Data Detail 3</f:facet>                            
#{dataDetail.data3}
</p:column>
</p:dataTable>
</h:body>

二豆

@ManagedBean
@ViewScoped
public class CarteiraDetalheBean implements Serializable{
private static final long serialVersionUID = 1L;

private Integer dataId; //getter setter
private List<DataDetail> dataDetailList; //getter setter


@EJB
MyDataManager manager;

@PostConstruct
public void init() {
dataDetailList = manager.getDataDetail(dataId);
}
}

当我使用:

<f:viewAction action="#{secondBean.init}" />

我得到消息:元数据组件需要嵌套在 af:metadata 标记中。建议:将必要的组件包含在

当我使用时:

<f:event type="preRenderView" listener="#{secondBean.init()}" />

我有一个空指针异常:

dataDetailList = manager.getDataDetail(dataId);

我做错了什么?

4

0 回答 0