SEAM无状态bean没有更新

时间:2011-09-14 15:23:26

标签: java jsf seam ajax4jsf

我正在尝试在索引页面中使用JSF SEAM实现'忘记密码'功能,我使用a4j:jsFunction通过两个用户发送用户电子邮件和卡号

当我发送电子邮件(作为字符串)时似乎工作正常,但是当我添加卡号(int)时,它会抛出以下内容。

引起:javax.el.PropertyNotFoundException:/index.xhtml @ 256,138 assignTo =“#{forgotPasswordActions.cardnumber}”:类'org.javassist.tmp.java.lang.Object _ $$ _ javassist_seam_5'没有物业'cardnumber'。

支持bean看起来像这样......

@Stateless
@Name("forgotPasswordActions")
public class ForgotPasswordActionsBean implements ForgotPasswordActions, Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Logger private Log log;

    @In private EmailService emailService;
    @In private UserDAO userDAO;
    @In private MessagePoster messagePoster;
    @In private Map<String, String> messages;
    private User user;
    private String address;
    private String email;
    private int cardnumber;

    @Override
    public void resetPassword(){
        new RunAsOperation(true) {
            public void execute() {
                if(StringUtils.isNotEmpty(email)){
                    user = userDAO.findByEmail(email);
                }
                else{
                    messagePoster.postPopupInfoMessage(messages.get("inputEmpty"));
                }
                if(user!=null && cardnumber == user.getCardId()){
                    String newPassword = generateRandomPassword();
                    log.debug("updating password...");
                    user.setPassword(newPassword);
                    user = userDAO.makePersistent(user);
                    address = user.getEmail();
                    log.debug("password changed to: "+newPassword);
                    Map<String, Object> emailInfo = new HashMap<String, Object>();
                    emailInfo.put("name", user.getFirstname());
                    emailInfo.put("newPassword", newPassword);
                    emailService.sendToAddress(Email.user_password_reset, address, emailInfo);
                    messagePoster.postPopupInfoMessage(messages.get("pwReset")+" "+user.getEmail());
                }
                else{
                    messagePoster.postPopupInfoMessage(messages.get("resetFailed"));
                }
            }
        }.run();
    }

    //---------------------- Setters

    @Override
    public void setEmail(String email) {
        this.email = email;
    }

    @Override
    public void setCardno(int cardnumber) {
        this.cardnumber = cardnumber;
    }

}

和JSF / HTML

    <div id="forgotPasswordDialog" title="Forgot Password">
        <div class="textBox">
            <input id="emailLookupval" type="text" />
            <input id="cardNoval" type="text" />
            <button onclick="resetPassword(jQuery('#emailLookupval').val(),jQuery('#cardNoval').val())" type="button">Reset</button>
            <a4j:form id="forgotPassword">
                <a4j:jsFunction name="resetPassword" 
                        action="#{forgotPasswordActions.resetPassword}"
                        oncomplete="jQuery('#forgotPasswordDialog').dialog('open')">
                    <a4j:actionparam name="userEmail" assignTo="#{forgotPasswordActions.email}"  />
                    <a4j:actionparam name="userCardno" assignTo="#{forgotPasswordActions.cardnumber}" />
                </a4j:jsFunction>
            </a4j:form>
        </div>
    </div>

我无法解决为什么它不会设置这个bean属性?任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:1)

您的二传手被称为setCardno(),而视图需要setCardnumber()#{bean.property}与bean中的属性名称无关。它涉及getter / setter方法名称。有两种方法可以解决这个问题:

  • 重命名setter方法:

    public void setCardnumber(int cardnumber) {
        this.cardnumber = cardnumber;
    }
    
  • 或者,重命名视图属性:

    assignTo="#{forgotPasswordActions.cardno}"