当尝试在EL中引用托管bean时#{bean.entity.property},有时会javax.el.PropertyNotFoundException: Target Unreachable抛出异常,通常是在设置bean属性时,或者要调用bean操作时.
似乎有五种不同的消息:
这些都意味着什么?它们是如何引起的,它们应该如何解决?
我使用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)
到目前为止没有任何作用:/
我正在开发一个 JSF 自定义组件,使用我在以下书籍Pro JSF and HTML5 by Apress 中找到的信息。
至此,我成功开发了:
一切正常,组件已成功呈现。
现在我想向呈现的元素添加 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) cdi ×2
jsf ×2
el ×1
java ×1
java-ee ×1
javascript ×1
jboss-weld ×1
managed-bean ×1
maven ×1
taglib ×1