2
我有一个非常简单的页面,只需提示用户输入名称,然后使用该名称创建资源。当用户点击提交按钮时,我想直接导航到刚才创建的实体的页面。所以,我的网页看起来是这样的:使用带动态ID的Prettyfaces进行导航
<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和3.3.2 PrettyFaces。
请问您可以发布映射“实体 - 细节”吗? – chkal 2012-02-11 10:28:51
啊,当然。不知道我该如何设法忘记这一点。 – 2012-02-11 12:35:14