Target Unreachable,"null"以JSF形式返回null [英] Target Unreachable, 'null' returned null in JSF form

查看:210
本文介绍了Target Unreachable,"null"以JSF形式返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我测试了此源代码:

Bean:

Bean:

private NewAccountObj na;

public class NewAccountObj {

    private int userid;
        ............

    public NewAccountObj(int userid.............) {

        this.userid = userid;
            ............
        }

        public int getUserid() {
            return userid;
        }

        ...............

    }

    // Getters 
    public NewAccountObj getDataList() {        
        return na;
    }

JSF页面:

JSF Page:

<h:panelGrid columns="2">
    <h:panelGroup>User ID</h:panelGroup>
    <h:panelGroup>
        <h:inputText id="userid" value="#{bean.dataList['userid']}">                    
        </h:inputText>
    </h:panelGroup>
......................
</h:panelGrid> 

当我提交表格时,我得到Target Unreachable, 'null' returned null. 你能帮我找到问题吗?也许这不是在h:panelGrid中访问Java对象的正确方法吗?

When I submit the form I get Target Unreachable, 'null' returned null. Can you help me to find the problem? Maye this is not the proper way to access Java object in h:panelGrid?

PS:

PS:

我在Glassfish日志中收到此错误消息:

I get this error message in Glassfish log:

javax.el.PropertyNotFoundException: /NewAccount.xhtml @38,126 value="#{NewAccountController.dataList['userid']}": Target Unreachable, 'null' returned null

推荐答案

使用上面的代码,NewAccountObj为null.因此,当调用getDataList()时,它返回null.然后它将调用null.getUserId().

With the above code, the NewAccountObj is null. So when the getDataList() is called, it returns null. Then it will to call null.getUserId().

na需要初始化.我在您的评论中看到您有一个很长的构造函数,您应该创建另一个不带参数(或该对象正常工作所需的最低限度)的构造函数.

na needs to be initialized. I see in your comment that you have a very long constructor, you should create another one with no arguments (or the minimum required for the object to work).

private NewAccountObj na;

    public class NewAccountObj {

        private int userid;
        ............

        public NewAccountObj() {
            new New AccountObj(0,0,...........);
        }

        public NewAccountObj(int userid.............) {

            this.userid = userid;
            ............

        }

        public int getUserid() {
            return userid;
        }

        ...............

    }

    // Getters 
    public NewAccountObj getDataList() {        
        return na;
    }

并像这样更改数据列表获取器:

And change the datalist getter like this:

public NewAccountObj getDataList() {
    if(na == null){
        na = new NewAccountObj();
    }
    return na;
}

这篇关于Target Unreachable,"null"以JSF形式返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆