托管 bean 不保留输入值并在打包到单独的 JAR 后返回 null

发布于 2024-12-16 21:41:05 字数 1471 浏览 3 评论 0原文

我在托管 bean 中有一个非常奇怪的行为,它不保留从 jsf 发送的值,并且当它要处理 POST 时,属性全部为 null。

我的 JSF 是一个简单的表单,有 2 个字段和一个按钮,接收两个字段的值,按钮执行 POST 方法来处理从 JSF 接收的数据。运行调试时,我可以看到按下按钮后,将使用发送到 bean 的值执行 setter 方法(很好),但是当它执行该方法时,突然所有属性都为空。

我必须指出,所有这些之前都工作正常,当我将所有托管 bean(backbean)移动到一个单独的 JAR 文件时,它就开始了这种行为。我知道,如果我再次将文件移动到 web 应用程序,那么它会起作用,但我正在寻找一种不在同一项目中积累太多文件的方法,因为编译和部署花费的时间太长。

以下是 backbean 和 JSF 的代码:

@Named
@RequestScoped
public class RegisterController implements Serializable {            
private String accountType;

public String getAccountTypes() {
    return accountType;
}

public void setAccountTypes(String accountType) {
    this.accountType = accountType;   // Here it stores the value ********
}

private String businessType;

public String getBusinessType() {
    return businessType;
}

public void setBusinessType(String businessType) {
    this.businessType = businessType;    // Here it stores the other value *******
}   

// Method called with the button
public String prepareCreate() {
    if ("PERSONAL".equals(getAccountTypes()))  // Here is null!!  *************
    {            
        return "PersonalSignup";
    }
    else
        if (businessType == null)  // Here is also null!! ************
        {
            JsfUtil.addErrorMessage(
                    new Exception(""), ResourceBundle.getBundle(CommonUtil.bundleStr).getString("cc.signup.accounttype.invalid.businesstype"));
        }
...

任何帮助将不胜感激,谢谢。

I have a very strange behavior in a managed-bean where it is not retaining the values sent from the jsf and when it s going to process the POST then the properties are all null.

The JSF I have is a simple form with 2 fields and a button, the values of the two fields are received, and the button executes a POST method to process the data received from the JSF. When running a debug, I can see that after pressing the button then the setter methods are executed with the values sent to the bean (good), but when it goes to execute the mothod then suddenly all properties are null.

I have to include, that all this was working fine before, it started with this behavior when I moved all the managed-beans (backbeans) to a separated JAR file. I know that if I move the files again to the webapp then it will work, but I am looking for a way to not accumulate too many files in the same project, it's taking too long for compilation and deployment.

Here is the code of the backbean and the JSF:

@Named
@RequestScoped
public class RegisterController implements Serializable {            
private String accountType;

public String getAccountTypes() {
    return accountType;
}

public void setAccountTypes(String accountType) {
    this.accountType = accountType;   // Here it stores the value ********
}

private String businessType;

public String getBusinessType() {
    return businessType;
}

public void setBusinessType(String businessType) {
    this.businessType = businessType;    // Here it stores the other value *******
}   

// Method called with the button
public String prepareCreate() {
    if ("PERSONAL".equals(getAccountTypes()))  // Here is null!!  *************
    {            
        return "PersonalSignup";
    }
    else
        if (businessType == null)  // Here is also null!! ************
        {
            JsfUtil.addErrorMessage(
                    new Exception(""), ResourceBundle.getBundle(CommonUtil.bundleStr).getString("cc.signup.accounttype.invalid.businesstype"));
        }
...

Any help would be really appreciated, thanks.

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

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

发布评论

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

评论(1

夜巴黎 2024-12-23 21:41:05

Found the answer here: How does JSF find beans annotated with @ManagedBean?. Certainly if you need that your webapp looks into your jar file for managed-beans, only include a faces-config.xml file in your META-INF folder of your jar file.

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