按Seam中的特定列名称搜索

时间:2013-10-04 09:49:21

标签: jsf seam crud

我正在使用jsf1.2工作。

除搜索操作外,一切正常。任何人都可以建议我以正确的方式前进吗?

在这里,我的表格如何:

            <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);

    }

实现接口的Action类:

    @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

        }
    }

控制台说第一个名字是:null。

我尝试了很多次,但在此失去了理智。请建议我。

1 个答案:

答案 0 :(得分:2)

为什么要在firstName组件中注入userListAction?这应该从哪里来? 如果没有更多,我想它的工作原理如下:

  1. 用户输入名字并单击命令按钮
  2. 表单已提交,输入的名字使用setter-method
  3. 设置到模型中
  4. 执行命令按钮时,会发生Seam-bijection并为“some”上下文中存储的firstName注入值。由于未在任何地方定义,因此会注入null
  5. 因此,如果您需要注射(对于任何情况),您应该在任何地方将比赛中的正确值。如果没有,只需删除@In注释。