【发布时间】:2012-03-03 13:57:02
【问题描述】:
我有一个非常简单的页面,它只是提示用户输入一个名称,然后使用该名称创建一个资源。当用户点击提交按钮时,我想直接将他导航到刚刚创建的实体的页面。所以我的页面是这样的:
<h:form id="form">
<p:fieldset legend="Create new">
<p:panelGrid columns="2">
<h:outputText value="Name" />
<p:inputText value="#{createBean.entity.name}" />
</p:panelGrid>
<p:commandButton value="Create Entity" ajax="false"
action="#{createBean.submit}">
</p:commandButton>
</p:fieldset>
</h:form>
createBean 的 submit 操作现在应该保留实体。作为副作用,这会为实体分配一个 ID。现在我想导航到这个实体。
public void submit() {
/* Persist entity, entity.getId() will now
return a meaningful value. */
FacesContext context = FacesContext.getCurrentInstance();
NavigationHandler handler = FacesContext.getCurrentInstance().getApplication().getNavigationHandler();
// How could I pass the ID?
handler.handleNavigation(context, null, "pretty:entity-detail");
}
entity-detail 的映射如下:
<url-mapping id="entity">
<pattern value="/entities" />
<view-id value="/views/entity/list.xhtml"/>
</url-mapping>
<url-mapping parentId="entity" id="entity-detail">
<pattern value="/view/#{id}" />
<view-id value="/views/entity/entityDetail.xhtml"/>
</url-mapping>
备案:使用 Apache MyFaces 2.1.5 和 PrettyFaces 3.3.2。
【问题讨论】:
-
您能发布映射“实体详细信息”吗?
-
啊,当然。不知道我怎么能忘记这一点。
标签: jsf-2 primefaces prettyfaces