インデックス ページ (私の場合は index.xhtml) を用意することをお勧めします。インデックスページでいくつかのアクションを渡したいです(たとえば、strutsで:<c:redirect url="list.do" />
リンクやボタンなしでstrutsアクションクラスに移動します)ナビゲーションを使用したい場合は、commandLink-sまたはボタンを使用する必要があります)。onclick JavaScript関数で書くことはできます<h:commandButton>
が、これが最善の選択肢だとは思いません。
私は (JSF 2.0 を使用して) JSF にまったく慣れていないので、アドバイスが必要です。インデックス ページからコントローラーのアクションにリダイレクトするためのベスト プラクティスは何ですか?
///新しいバージョン
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:view>
<ui:insert name="metadata"/>
<f:viewParam name="action" value="listItems.xtml"/>
<f:event type="preRenderView" listener="#{yourBean.methodInManagedBean}" />
<h:body></h:body>
</f:view>
</html>
public class ForwardBean {
private String action;
// getter, setter
public void navigate(PhaseEvent event) {
FacesContext facesContext = FacesContext.getCurrentInstance();
String outcome = action;
facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, null, outcome);
}
}