我有一个表格,我列出了一些演员..这个页面是actor.xhtml。这是相关部分:
<p:dataTable id="allActors" var="actor" value="#{actorTableBackingBean.allActors}">
<p:column headerText="Actor Name" sortBy="#{actor.firstName}">
<h:outputText value="#{actor.firstName}"/>
</p:column>
<p:column headerText="Actor Detail">
<h:link value="Go to actor detail" outcome="actorDetail?actorId=#{actor.actorId}" />
</p:column>
</p:dataTable>
所以当我点击表格中的链接Go To Actor Detail时,我成功导航到:actorDetail.xhtml?actorId = 1
这是actorDetail.xhtml:
<ui:composition template="../maintemp.xhtml">
<f:metadata>
<f:viewParam name="actorId" value="#{actorDetailBackingBean.actorId}" />
</f:metadata>
<ui:define name="mainarea">
<div class="well" style="padding: 15px" >
<h3>Actor Detail</h3>
</div>
#{actorDetailBackingBean.actorWith().firstName}
</ui:define>
</ui:composition>
这是我的ActorDetailBackingBean.java:
@Named
@RequestScoped
public class ActorDetailBackingBean extends BasePage {
@Inject
ActorDao actorDao;
@Inject
Actor actor;
private int actorId;
public int getActorId() {
return actorId;
}
public void setActorId(int actorId) {
this.actorId = actorId;
}
public Actor actorWith(){
actor = actorDao.getWithId(actorId);
return actor;
}
}
但是这会返回零数据..所以没有加载细节。使用参数0调用actorDao.getWithId。
我错过了什么?
也是一个奖金问题:
如何通过POST请求执行此操作?
答案 0 :(得分:0)
我会回答我自己的问题。
将String传递给bean,而不是int。现在它有效!