不接受ManagedBean Params,并且Bean似乎不在范围内 [英] ManagedBean Params not accepted and Bean seemingly not in scope

查看:107
本文介绍了不接受ManagedBean Params,并且Bean似乎不在范围内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这使用来自以下代码的相同代码 primefaces树控件

This uses the same code that comes from primefaces tree control

@ManagedBean( name = "theName", eager = true)

第一个问题是为什么无法识别名称"和渴望". Eclipse建议我将其中一个参数都更改为值"-因此不确定在那里发生了什么.

The first question is why "name" and "eager" are not recognised. Eclipse suggests I change either parameter to "value" - so not sure whats going on there.

然后,在需要注意的地方大写并创建我的bean

Then, where I have been careful to capitalise where necessary and create my bean

public class TreeBean implements Serializable {

并在我的xhtml中引用它

and reference it in my xhtml

<h:form id="mainForm">  

<p:tree id="treeSingle" value="#{treeBean.root}" var="node"
        selectionMode="single"
        selection="#{treeBean.selectedNode}">

(注意类名的大写).

输出仅显示一个窄条. System.out.println(构造函数为")表明该bean未知.为此,如果我按示例中的代码(顶部提供的链接)按按钮,则会收到错误消息

The output shows only a narrow bar. System.out.println("Constructor called") suggests the bean is not known. To support this, if I press the button as coded in the example (link provided at the top) I get the error

Jan 13, 2014 12:19:26 AM com.sun.faces.context.AjaxExceptionHandlerImpl handlePartialResponseError
SEVERE: javax.el.PropertyNotFoundException: /HelloWorld.xhtml @23,50 selection="#{treeBean.selectedNode}": Target Unreachable, identifier 'treeBean' resolved to null
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:133)

关于可能会出现的问题,我现在没有足够的想法了.是否有任何进一步调试的方法,或者任何人对渴望/名称的事情以及导致Bean类成为(我认为)不可见的原因有任何想法.

I've run out of ideas now as to what could be the problem. Is there any way of further debugging this or anyone got any ideas about the eager/name thing and what is causing the Bean class to be (I assume) not to be seen.

先谢谢了. 凯文

推荐答案

beans应该这样定义:

beans should be defined this way:

@ManagedBean(name="treeBean")
@SessionScoped // or whatever scope you would like to use
public class TreeBean implements Serializable {
....

在XHTML中的用法:...="#{treeBean.root}"

Usage in XHTML: ...="#{treeBean.root}"

@ManagedBean(name="xyz")
@SessionScoped // or whatever scope you would like to use
public class TreeBean implements Serializable {
....

在XHTML中的用法:...="#{xyz.root}"

Usage in XHTML: ...="#{xyz.root}"

bean名称只是地图的键,您可以随意命名它

bean name is just a key for the map, you can name it whatever you want

bean的范围应来自软件包javax.faces.bean

the scope of the bean should be from the package javax.faces.bean

即对于必须导入的 sessionscoped

import javax.faces.bean.SessionScoped;

以及ManagedBean Annotation

and for the managedBean Annotation

import javax.faces.bean.ManagedBean;

这篇关于不接受ManagedBean Params,并且Bean似乎不在范围内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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