0

私のアプリケーションJSF1.2では、2 つの jsp ページがあり、そのうちの 1 つはwithallemployee.jspを配置しました。それぞれに従業員の、などが含まれています... 2 ページ目は 、1 人の従業員の詳細を表示する場所です。の各行にはwith valueがあります。これをクリックすると、対応する従業員の詳細が に表示されます。今、私はという名前を持っています。このユーザーをクリックした後、ジャンプした場所からの前の位置に移動します。<h:dataTable>100 rowsnamephone Noexperiencedetail.jspallemployee.jsp<h:commandLink>employee's name<h:commandLink>detail.jspdetail.jsp<h:commandButton>Go Backbuttonallemployee.jspdetail.jsp

allemployee.jspのように見えます:

<h:form>
    <h:dataTable id="employeeList" value="#{employeelist.employees}" var="employee" cellspacing="60">
        <f:facet name="header"><h:outputText value="#{msg.list}" /></f:facet>

        <h:column>
            <f:facet name="header"><h:outputText value="#{msg.name}"/></f:facet>
            <h:commandLink value="#{employee.name}" action="#{employeelist.getaction}" actionListener="#{employeelist.sendToDetail}">
                <f:param id="NamE" value="#{employee.name}" name="NamE"/>
            </h:commandLink>
        </h:column>

        <h:column>
            <f:facet name="header"><h:outputText value="#{msg.phn}" /></f:facet>
            <h:outputText value="#{employee.phNo}" />
        </h:column>

        <h:column>
                <f:facet name="header"><h:outputText value="#{msg.experience}" /></f:facet>
                <h:outputText value="#{employee.experiance}" />
        </h:column>
    </h:dataTable>
</h:form>

detail.jspのように見えます:

<h:form>
<h:panelGrid columns="2">
    <h:outputLabel value="#{msg.name}" />
    <h:outputText value="#{detail.employee.name}" />

    <h:outputLabel value="#{msg.phn}" />
    <h:outputText value="#{detail.employee.phNo}" />

    <h:outputLabel value="#{msg.experience}" />
    <h:outputText value="#{detail.employee.experiance}" />
</h:panelGrid>
    <h:outputLink value="/allemployee.jsp#paramName">
        <f:param name="paramName" value="#{detail.employee.name}"/>
        <h:outputText value="Go Back" />
    </h:outputLink>

employeelistBean は次のようになります。

public class EmployeeListController implements Serializable {

private static final long serialVersionUID = 6930161072142091260L;

private List<EmployeeModel> employees;

@PostConstruct
public void init() {
    Service service = new Service();
    this.employees = service.getAll();
}

public void sendToDetail(ActionEvent ev) {
    String name = (String)FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("NamE");
    for (EmployeeModel employee : employees) {
        if (employee.getName().equals(name)) {
            HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
            req.setAttribute("employe", employee);
        }
    }
}

public String goback(){
    return "allemployee";
}

public String getaction() {
    return "detail";
}
//getter & setter of  employees.

クラスEmployeeModelには、変数namephNoexperienceおよびゲッターとセッターがあります。クラスServiceでは、すべての従業員の詳細を設定します。

私のdetailBeanは次のようになります:

public class DetailController implements Serializable {
private static final long serialVersionUID = 8632585974603579268L;

private EmployeeModel employee = new EmployeeModel();
private String paramName;
public DetailController() {

}

@PostConstruct
public void init() {
    HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    this.employee = (EmployeeModel) req.getAttribute("employe");
    this.paramName = employee.getName();
    }

// getter & setter employee and paramName.

}

faces-configのようなものです :

<managed-bean>
<managed-bean-name>detail</managed-bean-name>
<managed-bean-class>com.edfx.controller.DetailController</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
 <managed-property>
    <property-name>paramName</property-name>
    <value>#{param.paramName}</value>
 </managed-property>
</managed-bean>

<managed-bean>
<managed-bean-name>employeelist</managed-bean-name>
<managed-bean-class>com.edfx.controller.EmployeeListController</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<navigation-rule>
<display-name>allemployee.jsp</display-name>
<from-view-id>/allemployee.jsp</from-view-id>
<navigation-case>
    <from-outcome>detail</from-outcome>
    <to-view-id>/detail.jsp</to-view-id>
</navigation-case>
</navigation-rule>

どうすれば要件を満たすことができますか? どんなポインタでも私にとって非常に役に立ちます。ありがとう、

4

0 に答える 0