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