0

我正在学习 JSF 1.2,并且我有一个使用请求 bean 呈现视图“profile.jsf”的场景BeanProfile。bean“BeanProfile”是一个请求 bean,因为我需要在每个请求中更新数据并刷新视图。该视图有一个<h:commandButton/>触发会话 bean 中的方法,LoginBean并且应该在持久化之前更新用户配置文件。因此,我需要将配置文件视图中的所有信息传递给会话 bean 中的方法。我尝试使用这样<f:attribute/>的:<h:commandButton/>

<h:commandButton id="submit" actionListener="#{beanLogin.updateUser}" value="Update">
    <f:attribute name="ttt" value="789"/> <!-- just for debug -->
    <f:attribute name="name" value="#{name}" /> <!-- I will pass just that one for the moment -->
</h:commandButton>

和组件:

<h:inputText id="name"
             binding="#{name}"
             value="#{beanProfile.name}"
             required="true" /> 

在我的方法中,我有:

public void updateUser(ActionEvent event) {
    /*Debug*/
    System.err.println("size: "+event.getComponent().getAttributes().size());
    System.err.println("--"+(String) event.getComponent().getAttributes()
            .get("ttt")+"--");;
    UIInput input = (UIInput) event.getComponent().getAttributes().get("name");
    String text = (String) input.getSubmittedValue();
    System.err.println("++"+text+"++");
}

结果我得到:

2014-12-20T01:43:25.850+0100|Severe: size: 1
2014-12-20T01:43:25.850+0100|Severe: --789--
java.lang.NullPointerException ...

所以我传递了 2 个参数,但我在会话 bean 的方法中只得到了一个,这就是导致java.lang.NullPointerException. 我不知道我做错了什么。我正在使用动态 Web 模块 3.0 和 GlassFish Server Open Source Edition 4.1(包括 Mojarra 2.2.7)在 Eclipse 4.4.1 SR1 中工作。

更新:

我使用我已经在 GlassFish 和 Mojarra 中使用的 tomcat 8.0.15、MyFaces 1.2.12 和 JSTL 1.2 尝试了相同的代码。我有同样的问题,我发现 bean 注入认为managed-propertyfaces-config.xml 中的内容在我使用的两种配置中都不起作用(空值)。

4

0 回答 0