2013-10-04 36 views
0

我正在與jsf1.2一起工作。通過Seam中的特定圖像名稱搜索

除了搜索操作以外,一切正常,適合我。任何人都可以請我建議我以正確的方式去?

在這裏,我是怎麼有我的方式:

  <h:form class="input-list" id="searchUser" style="width:100%;" 
      name="searchUser"> 
        <div class="edit-label">FIRST NAME :</div> 
       <h:inputText tabindex="1" id="firstName" type="text" class="miniusername clp" 
       value="#{userListAction.firstName}" required="true"> 
       <f:validateLength minimum="3" maximum="20" /> 
      </h:inputText> 

      <h:commandButton value="Search" tabindex="2" style="margin-left: 5px" 
       action="#{userListAction.retrieveName}" class="usersearch"> 
      </h:commandButton> 
     </h:form> 

我的界面:

@Local 
    public interface UserListAction extends Serializable { 

     public List<User> retrieveCustomers(); 

     public List<User> retrieveEmployees(); 

     public List<User> getUsersList(); 

     public CLRPUser getLoginUser(); 

     public List<User> retrieveName(); 

     @WebRemote 
     public String deleteById(Integer userId); 

     @WebRemote 
     public CLRPUser getUserById(Integer userId); 

     public UserTypeEnum getUserType(); 

     public void setUserType(UserTypeEnum userType); 

     public void setFirstName(String firstName); 

     public String getFirstName(); 

     public CLRPUser getCurrentUser(); 

     public void setCurrentUser(CLRPUser currentUser); 

    } 

動作類,它實現的接口:

@Name("userListAction") 
    @Stateless 
    @AutoCreate 
    public class UserListActionImpl implements UserListAction { 

     @In 
     protected UserService userService; 

     @Out(value = "userType", scope = ScopeType.CONVERSATION, required = false) 
     private UserTypeEnum userType; 

     @In 
     private LoggedInUser loggedInUser; 

     @Out(value = "currentUser", scope = ScopeType.CONVERSATION, required = false) 
     @In(value = "currentUser", scope = ScopeType.CONVERSATION, required = false) 
     private CLRPUser currentUser; 

     @In(value = "firstName", scope = ScopeType.CONVERSATION, required = false) 
     private String firstName; 

     /** 
     * 
     */ 

     private static final long serialVersionUID = 8649412602585430272L; 

     /* 
     * (non-Javadoc) 
     * 
     * @see com.ermms.clrp.user.UserAction#getUsersList() 
     */ 


     public List<User> retrieveName() { 
      System.out.print("FirstName is :" + firstName); 
      return userService.getAllUsers(firstName); 
     } 


     public UserTypeEnum getUserType() { 
      return this.userType; 
     } 

     public void setUserType(UserTypeEnum userType) { 
      this.userType = userType; 
     } 

     public void setFirstName(String firstName) { 
      this.firstName = firstName; 
     } 

     public String getFirstName() { 
      return firstName; 
     } 

     @Override 
     public CLRPUser getCurrentUser() { 
      // TODO Auto-generated method stub 
      return null; 
     } 

     @Override 
     public void setCurrentUser(CLRPUser currentUser) { 
      // TODO Auto-generated method stub 

     } 
    } 

控制檯說,名字是: 空值。

我嘗試了更多次,但在此失去了我的想法。請建議我。

回答

2

爲什麼您在userListAction組件中注入firstName?這從哪裏來? 如果沒有什麼更多的,我想它的工作原理如下:

  1. 用戶輸入名字並單擊命令按鈕
  2. 形式被使用setter-提交和輸入的名字被設置到模型方法
  3. 當執行命令按鈕動作時發生Seam-bijection並注入存儲在「some」上下文中的firstName的值。由於它沒有在任何地方定義,因此注入null

因此,如果您需要注射(對於任何情況),您應該在任何地方在比賽中輸入正確的值。如果不是,請刪除@In註釋。

+0

MrD想要告訴你的是,你不需要注入表單中的每個字段。提交表單時,您的inputtext值將被連線到您的UseListAction bean的firstName屬性。 – Esteve

+0

哇...太好了。它的作用像魅力。謝謝MrD和Esteve ..也爲我的耽擱而道歉..我已經與其他項目捆綁在一起..帽子給你MrD。 – DevGo