SEAM 无状态 bean 未更新

发布于 2024-12-04 17:02:10 字数 3563 浏览 0 评论 0原文

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

当我发送电子邮件时,它似乎工作正常(如一个字符串),但是当我添加卡号(int)时,它抛出以下错误..

引起:javax.el.PropertyNotFoundException:/index.xhtml @256,138 allocateTo="#{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 属性?任何帮助表示赞赏!

I am trying to implement 'forgot password' functionality using JSF SEAM in our index page, I am using a a4j:jsFunction to send the users email and card number via two 's

It seems to work fine when I just send the email (as a string), but when I added card number (int) it threw the following..

Caused by: javax.el.PropertyNotFoundException: /index.xhtml @256,138 assignTo="#{forgotPasswordActions.cardnumber}": The class 'org.javassist.tmp.java.lang.Object_$$_javassist_seam_5' does not have the property 'cardnumber'.

The backing bean looks like this...

@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;
    }

}

and the 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>

I cant work out why it wont set this bean property?? Any help appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

汹涌人海 2024-12-11 17:02:10

您的 setter 称为 setCardno(),而视图需要 setCardnumber()#{bean.property} 与 bean 中的属性名称无关。它与 getter/setter 方法名称相关。有 2 种方法可以解决此问题:

  • 重命名 setter 方法:

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

    assignTo="#{forgotPasswordActions.cardno}"
    

Your setter is called setCardno() while setCardnumber() is been expected by the view. The #{bean.property} does not relate to property names in the bean. It relates to getter/setter method names. There are 2 ways to fix this:

  • Rename the setter method:

    public void setCardnumber(int cardnumber) {
        this.cardnumber = cardnumber;
    }
    
  • Or, rename the view property:

    assignTo="#{forgotPasswordActions.cardno}"
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文