当尝试在EL中引用托管bean时#{bean.entity.property},有时会javax.el.PropertyNotFoundException: Target Unreachable抛出异常,通常是在设置bean属性时,或者要调用bean操作时.
似乎有五种不同的消息:
这些都意味着什么?它们是如何引起的,它们应该如何解决?
我刚开始阅读Core JavaServer Faces,第3版.他们这样说(强调我的):
对于可以在JSF页面中使用的bean,有两种不同的机制,CDI bean和JSF托管bean,这是一个历史事故.我们建议您使用CDI bean,除非您的应用程序必须在像Tomcat这样的普通servlet运行器上运行.
为什么?他们没有提供任何理由.我一直在使用@ManagedBean在GlassFish 3上运行的原型应用程序中的所有bean,我还没有发现任何问题.我不介意迁移@ManagedBean到@Named,但我想知道为什么我应该打扰.
我目前正在实现一个小型的Spring MVC PoC,我想使用JSF作为视图技术,因为我公司的大多数人习惯于使用Primefaces环境的J2EE.
Spring MVC 3是支持JSF,还是只支持JSP?我已经阅读了两篇混合两篇的文章.
我需要创建一个吸引人的UI.有没有一种简单的方法来使用Spring MVC和JSP作为视图技术?
我们的应用程序在多页中使用计划/日历.它基本上是一个时间管理APP
混淆使用JSF2 + Spring + EJB3或它们的任意组合让我感到有些困惑.我知道Spring的一个主要特性是依赖注入,但是我可以使用JSF托管bean @ManagedBean和@ManagedPropertyanotations,并获得依赖注入功能.使用EJB3,我更加困惑何时将其与JSF一起使用,或者甚至有理由使用它.
那么,在什么样的情况下使用Spring + JSF2或EJB3 + JSF2是个好主意?
到目前为止,我只使用JSF2创建了一些小型Web应用程序,从不需要使用Spring或EJB3.但是,我在许多地方看到人们正在将所有这些东西放在一起.
我正在创建我的第一个项目Java EE 7,但我遇到了麻烦.感谢任何帮助.
应用程序启动时,Tomcat日志显示以下消息:
"validateJarFile (C:\...\build\web\WEB-INF\lib\javaee-api-7.0.jar)-jar not loaded. See Servlet 2.3 Spec, section 9.7.2. Offending class: javax/servlet/Servlet .class"
Run Code Online (Sandbox Code Playgroud)
当我点击调用托管bean的按钮时,我收到错误:
Advertência: /index.xhtml @18,66 value="#{indexMB.user}": Target Unreachable, identifier 'indexMB' resolved to null
javax.el.PropertyNotFoundException: /index.xhtml @18,66 value="#{indexMB.user}": Target Unreachable, identifier 'indexMB' resolved to null
Run Code Online (Sandbox Code Playgroud)
IndexMB
@Named("indexMB")
@RequestScoped
public class IndexMB {
private String password;
private String user;
public String loginTest(){
return (this.user.equals("admin") ? "adminPage" : "inOutPage");
}
// getters and setters
}
Run Code Online (Sandbox Code Playgroud)
的index.xhtml
<html ...>
<f:loadBundle …Run Code Online (Sandbox Code Playgroud) 对于Java开发人员来说,Spring是一个很好的DI和AOP框架.
现在,有一个标准规格的DI和AOP是CDI.
如果不支持相关标准,任何好产品都不能再保持良好状态.(例如,Hibernate支持JPA规范)
我的问题是,Spring将在未来版本中支持标准规范(CDI)吗?
我不确定我在JSF中使用MVC环境的方法是否是最好的方法.由于我想要充分利用JSF,我想知道我的服务层(或模型,用MVC术语说)应该如何"设计".
我知道视图 - 控制器比率应该是1比1(排除例外情况).现在我应该以什么方式设计我的服务层?我应该使用一项大型服务(不这么认为)吗?如果没有,根据我应该分割我的服务?
注意,我的服务将从Beans(控制器以MVC术语)调用,服务本身将在必要时使用JPA调用DAO.
提前致谢
@ViewScoped在Spring 3.0中是否有像JSF这样的范围?我有一个使用JSF + Spring的应用程序,其中支持bean由Spring管理.我在Spring中没有找到像JSF wiew作用域这样的范围.我看到博客将JSF 2.0的ViewScope移植到Spring 3.0,但它对我不起作用.
这是我对自定义Spring范围的尝试:
import java.util.Map;
import javax.faces.context.FacesContext;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.Scope;
/**
* Implements the JSF View Scope for use by Spring. This class is registered as a Spring bean with the CustomScopeConfigurer.
*/
public class ViewScope implements Scope {
public Object get(String name, ObjectFactory<?> objectFactory) {
System.out.println("**************************************************");
System.out.println("-------------------- Getting objects For View Scope ----------");
System.out.println("**************************************************");
if (FacesContext.getCurrentInstance().getViewRoot() != null) {
Map<String, Object> viewMap = FacesContext.getCurrentInstance().getViewRoot().getViewMap();
if (viewMap.containsKey(name)) {
return viewMap.get(name);
} …Run Code Online (Sandbox Code Playgroud) 在进行Spring-JSF集成时,我看到了这个条目faces-config.xml.
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
Run Code Online (Sandbox Code Playgroud)
有人可以解释究竟是什么<application>以及<el-resolver>是谁?
要使用@Autowire注释,使用注释的对象必须来自spring上下文.
JSF托管bean是由JSF的IOC not Springs创建的,因此我不能在其中使用@Autowire必须使用faces-config.xml和托管属性.
我已经设置的EL解析器,让是有春天豆类管理特性,我希望把它一步,摆脱需要每一个我需要的东西自动装配时间去到faces-config.xml中.这可能吗?
我正在开发spring-hibernate-jsf应用程序,但我不理解managedbean和spring控制器之间的区别.我认为管理员就像控制器一样工作.使用controller或managedbean有什么好处吗?
我找到了一些关于将JSF技术与Spring Boot集成的教程,但是让OmniFaces使用Spring Boot似乎是一项相当复杂的工作.将这两者结合在一起是一个好主意吗?
我尝试使用JSF 2进行联合Spring 3(MVC).我在Spring和JSF中有一些经验,但之前从未尝试过加入它们.最后我有2个文件
@ManagedBean(name = "userBean")
@Scope
@Component
public class someBean {
@Autowired
private TestService testService;
public void printString() {
System.out.println(testService.getString());
}
}
Run Code Online (Sandbox Code Playgroud)
和
@ManagedBean(name = "studentBean")
@Scope
@Component
public class StudentBean {
@Autowired
private TestService testService;
public void printString() {
System.out.println(testService.getString());
}
}
Run Code Online (Sandbox Code Playgroud)
对于这些文件,我有正确的spring,jsf和web.xml配置.并有.xhtml页面,我为'someBean'和'StudentBean'启动printString().我在第一种情况下使用NPE,在第二种情况下在控制台中使用"some string".原因很简单 - Spring上下文和JSF中的bean名称不同.所有问题都完成了
@Component => @Component("userBean")
public class someBean {
Run Code Online (Sandbox Code Playgroud)
在调试中我看到了
private TestService testService;
@Autowired
public void setTestService(TestService testservice) {
this.testService = testService;
}
Run Code Online (Sandbox Code Playgroud)
当JSF bean创建的testService集不为null时,但在JSF生命周期中它为null时
public void pringString() {
testService.blah();
}
Run Code Online (Sandbox Code Playgroud)
testService为null.这是我无法理解的.有谁深入了解Spring和JSF详细描述这种情况?
jsf ×11
spring ×8
cdi ×4
java-ee ×3
jsf-2 ×3
el ×2
java ×2
managed-bean ×2
aop ×1
autowired ×1
controller ×1
ejb ×1
faces-config ×1
integration ×1
javabeans ×1
jsf-2.2 ×1
jsp ×1
omnifaces ×1
primefaces ×1
spring-boot ×1
spring-mvc ×1
tomcat ×1
view-scope ×1