在我使用的应用程序中,JSF1.2
我有两个 jsp 页面,其中一个是allemployee.jsp
我放置了一个<h:dataTable>
with 100 rows
。每个都包含员工的name
, phone No
,experience
等等......第二页是
detail.jsp
我显示单个员工的详细信息的地方。在每一行中allemployee.jsp
都有一个<h:commandLink>
with value employee's name
。单击此按钮后<h:commandLink>
,将在 中显示相应员工的详细信息detail.jsp
。现在detail.jsp
我有一个<h:commandButton>
名为Go Back
. 我希望单击此button
用户后,将进入allemployee.jsp
他/她跳到的上一个位置detail.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>
employeelist
豆看起来像:
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
有变量name
、、getter 和setter。在课堂上,我设置了所有员工的详细信息。phNo
experience
Service
我的detail
Bean 看起来像:
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>
我怎样才能满足我的要求?任何指针都会对我很有帮助。谢谢,