1

JPA エンティティを持つ JSF2、ファサード/ejb オブジェクトとしてのステートレス ejb セッション Bean、およびビジネス メソッドを公開するコントローラーとしてのマネージド Bean (リクエストおよびビュー スコープ) を使用する Web アプリがあり、マネージド コントローラーは注入されたステートレス セッション Bean からデータをプルしています。

しかし、この環境でコントローラーのビュー全体でデータをナビゲートして保持する方法がわかりません。たとえば、次のようになります。

Department オブジェクトのリストを表示する jsf2 ビュー ページ (departmentView.xhtml) があり、各行には編集項目があります。[編集] をクリックして、新しいページをロードし、新しいページにその部門のリストまたは従業員を表示したいので、選択した部門を渡す従業員コントローラーを呼び出します。

action="#{employeeController.getEmployeeListForADepartment(ithDepartment)}" 

ここに私の departmentView.xhtml のスニペットがあります

    <h:dataTable id="table" value="#{departmentController.departmentList}" 
            var="ithDepartment">
...
<h:column>              
<h:commandLink id="editId" value="Edit"
action="#{employeeController.getEmployeeListForADepartment(ithDepartment)}" />
</h:column>

私のemployeeControllerは次のように定義されています

ManagedBean(name = "employeeController")
@ViewScoped
public class EmployeeController implements Serializable {
   ...
private List<Employee> employeeList = new ArrayList<Employee>();
   ...      

@EJB
private com.ejb.session.EmployeeFacade ejbEmployeeFacade;    
   ...

public List<Employee> getEmployeeListForADepartment(Department dept) 
{
    if(employeeList==null || employeeList.isEmpty())
          employeeList = ejbEmployeeFacade.findEmployeesByDepartment(dept);  

// now i want to navigate to the employee view showing these employees for the
// selected department.
// but this navigation below triggers creating a new EmployeeController 
// and i lose my employeeList 
    return "employeeView";
}

私は本当にjsfセッションスコープの使用を避けたいと思っており、これを行う方法があると信じています.jsf/ejbの本でそれについて読んでいません。

大声で考えて、おそらくEmployeeController.getEmployeeListForADepartment(..)ルックアップを行う必要はありません。部門IDからパラメーターを作成し、それを介して渡しreturn "employeeView?departmentId=X";、IDが存在する場合はコンストラクターにルックアップを実行させますか?

EJB/JSF2環境でこれを実装する適切な方法を教えてください

ありがとう

4

1 に答える 1

0

ソース ビューで単純な GET<h:link>を使用して部門 ID を渡し、<f:viewParam>ターゲット ビューで を使用して部門を変換して設定します。

例えば

<h:link id="editId" value="Edit" outcome="employeeView">
    <f:param name="departmentId" value="#{ithDepartment.id}" />
</h:link>

<f:metadata>
    <f:viewParam name="id" value="#{editDepartmentBean.department}"
        converter="#{departmentConverter}" converterMessage="Bad request. Unknown department."
        required="true" requiredMessage="Bad request. Please use a link from within the system." />
</f:metadata>

@ManagedBean
@ViewScoped
public class EditDepartmentBean {

    private Department department;

    // ...
}

以下も参照してください。

于 2011-12-07T12:19:45.940 に答える