我正在使用jsf中的ViewScoped注释,但未获得正确的输出

时间:2019-03-18 12:16:49

标签: jsf-2 view-scope

我正在JSF2.0中使用@ViewScoped注释。以下是我编写的代码。它没有按我预期的那样工作。请查看它,并让我知道是否需要进行任何更改以获取确切的输出结果。

这是我的控制器SearchController.java

package com.s2tech.jsfapp.controllers;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import com.s2tech.jsfapp.helper.SearchHelper;
import com.s2tech.jsfapp.managedbean.SearchManagedBean;

@ManagedBean(name ="searchController")
@ViewScoped
public class SearchController  implements Serializable{
    public SearchController(){

    private static final long serialVersionUID = 1L;
     SearchHelper searchHelper;

    private List<SearchManagedBean> employeeList=new ArrayList<SearchManagedBean>();

    public List<SearchManagedBean> getEmployeeList() {
        return employeeList;
    }

    public void setEmployeeList(List<SearchManagedBean> employeeList) {
        this.employeeList = employeeList;
    }


    public void  getEmployee(SearchManagedBean searchManagedBean) {
       searchHelper=new SearchHelper();

         employeeList = searchHelper.getEmployee(searchManagedBean);

         //return "search.xhtml";

    //return Constants.searchPage;

    //   return null;
            }

下面是我的视图search.xhtml

<h:body style="background-color:skyblue;">
<ui:include src="mainMenu.xhtml"></ui:include>
<h:form prependId="false">   

   <table>

   <tr style="display:block;margin-top:10px;width:100%;margin-left:40%">

   <td style="width:40%">

           <p:outputLabel for="firstName" value="First Name:" style="font-weight:bold" />

        <p:inputText id="firstName" value="#{searchManagedBean.firstName}"  required="true" requiredMessage="please enter First Name"> </p:inputText>
        <p:message id="firstNameMsg" for="firstName" showDetail="true"  ></p:message>

    </td>  
    <td style="width: 20%"></td>  
        <td style="width:40%;">
        <p:outputLabel for="lastName" value="Last Name:" style="font-weight:bold"/>
        <p:inputText id="lastName" value="#{searchManagedBean.lastName}" required="true" requiredMessage="please enter Last Name" />
         <p:message id="lastNameMsg" for="lastName" showDetail="true"  ></p:message>
        </td> 
            </tr>
    <tr style="display:block;margin-top:10px;width:100%;margin-left:78%">
    <td  style="width:40%">  <p:commandButton value="Search" action="#{searchController.getEmployee(searchManagedBean)}" update="firstNameMsg lastNameMsg emailMsg phoneMsg dataTable"/></td>
                </tr>
         </table>

</h:form>

<p:dataTable id="dataTable" var="emp" rendered="#{not empty searchController.employeeList}" value="#{searchController.employeeList}" rowStyleClass="table table-striped table-hover table-bordered" resizableColumns="true" resizeMode="expand" scrollWidth="50%" scrollHeight="150" >
    <p:column headerText="First Name">
        <h:outputText value="#{emp.firstName}"/>
    </p:column>

    <p:column headerText="Last Name">
        <h:outputText value="#{emp.lastName}"/>
    </p:column>

    <p:column headerText="Email">
        <h:outputText value="#{emp.email}"/>
    </p:column>

    <p:column headerText="Phone">
        <h:outputText value="#{emp.phone}"/>
    </p:column>

     <p:column headerText="Edit">
       <p:commandLink value="Edit" action="#{searchController.getEditForm(emp)}"  style="margin-left:40px;color:blue;"></p:commandLink>

    </p:column>


</p:dataTable>


</h:body>  

</html>  

我的问题是,在输入名字和姓氏之后,当我单击提交按钮时,它需要点击控制器的getEmployee()方法,并且需要显示控制器的getEmployeeList()中的数据表值。即使在这里使用ViewScoped bean Iam也不会获得输出。有什么建议吗?

0 个答案:

没有答案