myfaces と richfaces を使用して簡単なマスター/ディテールを作成しました。rich:dataTable で ah:commandLink をクリックすると、ユーザーは詳細ビューを開いてエンティティを編集できます。
ここで、ユーザーが詳細ビューを直接開くことができる URL を作成したいと考えています。通常、/detail.jsp?id=12 のような URL を作成してこれを行います - JSF でそれを実現するにはどうすればよいですか?
リンク コントロールのパラメーターを使用して URL を作成できます。
<h:outputLink value="reqscope.faces">
<f:param name="id" value="#{row.id}" />
<h:outputText value="link" />
</h:outputLink>
ターゲット ページで、式言語を直接使用するかマネージド Bean を介してパラメーター マップから ID を読み取ることができます。
意見:
<f:view>
id= <h:outputText value="#{param['id']}" />
<br />
id= <h:outputText value="#{lookupBean.id}" />
</f:view>
豆:
public class LookupBean implements Serializable {
public String getId() {
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext extContext = context.getExternalContext();
Map<String, String> params = extContext.getRequestParameterMap();
return params.get("id");
}
}
faces-config.xml 宣言:
<managed-bean>
<managed-bean-name>lookupBean</managed-bean-name>
<managed-bean-class>reqscope.LookupBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
JSF 1.2を使用している場合は、f:setPropertyActionListenerを使用できます。
<h:commandLink action="#{reqscope.faces}">
<h:outputText value="link"/>
<f:setPropertyActionListener
value="#{id}"
target="#{lookupBean.id}"/>
</h:commandLink>
a4j:commandlinkを使用して、最初に詳細を表示するエンティティのIDを詳細ビューBeanに渡します。次に、document.locationを使用してビューに移動します。
<a4j:commandLink action="#{detailviewBean.setDetailID(entity.someid)}" value="#{entity.someid}" oncomplete="document.location='/app/detailview.seam'"/>