【问题标题】:JSF pasing input to bean doesn't work [duplicate]JSF将输入传递给bean不起作用[重复]
【发布时间】:2017-05-03 15:18:29
【问题描述】:

您好,我正在尝试实现一些非常基本的目标,但在过程中失败了。我想将用户名和密码从 JSF 传递给 bean,然后在 bean 的方法中使用它们将用户添加到数据库。不幸的是,输入根本无法到达bean,我得到javax.ejb.EJBTransactionRolledbackException,因为密码和登录名都不能为空。 Log4j 日志显示参数确实为空

[2017-05-03T16:50:18.948+0200] [Payara 4.1] [INFO] [] [] [tid: _ThreadID=32 _ThreadName=http-thread-pool::http-listener-2(1)] [timeMillis: 1493823018948] [levelValue: 800] [[

  464239 [http-thread-pool::http-listener-2(1)] DEBUG pl.lodz.p.it.ssbd2017.ssbd06.mok.facades.AbstractFacade  - log4j: login null]]



[2017-05-03T16:50:18.949+0200] [Payara 4.1] [INFO] [] [] [tid: _ThreadID=32 _ThreadName=http-thread-pool::http-listener-2(1)] [timeMillis: 1493823018949] [levelValue: 800] [[

  464240 [http-thread-pool::http-listener-2(1)] DEBUG pl.lodz.p.it.ssbd2017.ssbd06.mok.facades.AbstractFacade  - log4j: passwordnull]]

这是来自 JSF 的代码

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
<body>
<f:view>
    <h:form>
        <h:outputLabel value="LOGIN: "/>
        <h:inputText value="#{createBean.login}"/>
        <h:outputLabel value="PASSWORD : "/>
        <h:inputText value="#{createBean.password}"/>
        <h:commandButton value="Register" action="#{createBean.create()}"/>

    </h:form>

</f:view>
</body>
</html>

这里来自 bean

@Named("createBean")
@RequestScoped
public class CreateBean {

    @Inject
    private MOKEndpointLocal mokEndpoint;

    private String login;
    private String password;

    static Logger log = Logger.getLogger(CreateBean.class);


    public CreateBean() {
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

//    public String getTest() {
//        return "test";
//    }

    public void create() {
        log.debug("logBean: login  " + login);
        log.debug("logBean: pass  " + password);
        mokEndpoint.create(login, password);
    }
}

谁能帮帮我?

【问题讨论】:

  • 我想如果你使用@Named("createBean") 就完成了,否则我应该看到你的项目配置
  • 不幸的是它没有帮助你想看到什么样的配置文件web.xml
  • 只是出于好奇,RequestScoped是什么类型的?
  • 根据“使用 NetBeans 进行 Java EE 7 开发”Request scoped beans are shared through the duration of a single request. A single request could refer to an HTTP request, an invocation to a method in an EJB, a web service invocation, or sending a JMS message. to a message-driven bean.
  • 默认有两个RequestScoped注解。 JSF 发生在 javax.faces.bean.RequestScoped 类中,而 CDI 发生在 javax.enterprise.context.RequestScoped 类中。对于 CDI bean(命名注释),您应该使用包 javax.enterprise.context 中的注释。

标签: jsf ejb


【解决方案1】:

好的,非常感谢大家的帮助,因为事实证明您对 javax.enterprise.context.RequestScoped 的看法是正确的。在 jsf 开始神奇地工作后,我检查了我的存储库中以前的提交,差异显示我之前使用的是 javax.faces.bean.RequestScoped,尽管我不记得更改它。现在它工作得很好。

再次感谢并保重!

【讨论】:

    猜你喜欢
    • 2019-09-27
    • 2015-01-07
    • 2016-09-10
    • 1970-01-01
    • 2012-08-10
    • 1970-01-01
    • 2016-01-22
    • 1970-01-01
    • 2011-05-21
    相关资源
    最近更新 更多