相关疑难解决方法(0)

识别并解决javax.el.PropertyNotFoundException:Target Unreachable

当尝试在EL中引用托管bean时#{bean.entity.property},有时会javax.el.PropertyNotFoundException: Target Unreachable抛出异常,通常是在设置bean属性时,或者要调用bean操作时.

似乎有五种不同的消息:

  1. 目标无法访问,标识符'bean'已解析为null
  2. 目标无法访问,'entity'返回null
  3. 目标无法访问,'null'返回null
  4. 目标无法访问,''0'返回null
  5. 目标无法访问,'BracketSuffix'返回null

这些都意味着什么?它们是如何引起的,它们应该如何解决?

jsf el cdi managed-bean propertynotfoundexception

117
推荐指数
2
解决办法
11万
查看次数

CDI:beans.xml,我在哪里放你?

我使用Weld作为CDI实现.当我有空的beans.xml时,我试图组装实例化Weld容器的对象图的集成测试运行良好src/test/java/META-INF/beans.xml.这是一个简单的测试:

public class WeldIntegrationTest {
    @Test
    public void testInjector() {
        new Weld().initialize();
        // shouldn't throw exception
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,当我跑步时mvn clean install,我总是得到:Missing beans.xml file in META-INF!

我的根文件夹是"src"和"web",其中包含WEB-INF文件夹,但我也尝试使用默认的maven结构并将"web"重命名为"webapp"并将其移至src/main.我尝试了所有合理的位置:

 - src/main/java/META-INF/beans.xml
 - src/test/java/META-INF/beans.xml
 - web/WEB-INF/beans.xml
 - src/main/webapp/WEB-INF/beans.xml
 - src/main/webapp/META-INF/beans.xml
 - src/main/webapp/META-INF/(empty) and src/main/webapp/WEB-INF/beans.xml
Run Code Online (Sandbox Code Playgroud)

到目前为止没有任何作用:/

java java-ee maven cdi jboss-weld

58
推荐指数
2
解决办法
4万
查看次数

JSF 最佳实践:自定义组件和 JavaScript

我正在开发一个 JSF 自定义组件,使用我在以下书籍Pro JSF and HTML5 by Apress 中找到的信息。

至此,我成功开发了:

  • 获取要在组件中呈现的数据的java类
  • java组件类
  • Java 渲染器类
  • 标签库文件
  • 呈现 taglib 的示例页面

一切正常,组件已成功呈现。

现在我想向呈现的元素添加 javascript 事件和行为,更具体地说,我的自定义组件的目的是在网页上呈现菜单,我想向菜单项添加下拉效果。我知道如何用 JavaScript 编写整个代码,但我不知道的是:

将 javascript 事件和行为添加到自定义组件中呈现的元素的最佳实践是什么?

JS文件应该放在哪里?如何将事件绑定到元素?它是在渲染类中完成的,还是在网页上完成的?

谢谢,如果需要,我愿意提供有关我的代码的更多具体信息。


Java 组件类

注意: CosmoMenu 类只是一个 bean。它基本上存储一个菜单树(一个标签、一个 id 和一组子项,如果有的话)。

package components;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import domain.CosmoMenu;
import javax.faces.component.FacesComponent;
import javax.faces.component.UIComponentBase;


@FacesComponent(CosmoMenuComponent.COMPONENT_TYPE)
public class CosmoMenuComponent extends UIComponentBase{

  /** Component family of {@link CosmoMenuComponent}.        */
  public static final String COMPONENT_FAMILY = "CosmoMenu";

  /** Component type of {@link …
Run Code Online (Sandbox Code Playgroud)

javascript jsf taglib custom-component

5
推荐指数
1
解决办法
3626
查看次数