我不确定我做错了什么。我在我的另一个项目中遇到了同样的问题,我无法访问托管bean。
这是facelet客户端:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://xmlns.jcp.org/jsf/passthrough"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns="http://www.w3.org/1999/xhtml"
template="./template.xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:define name="left">
<h:form>
<h:inputTextarea value="#{blogmanager.blogEntity.text}" p:placeholder="Tweet max 30 chars." style="width: 100%; height:150px; resize: none;" /><br/><br/>
<h:commandButton value="Tweet" action="#{blogmanager.save}" />
</h:form>
</ui:define>
<ui:define name="right">
<c:forEach items="#{blogManager.blogs()}" var="item">
<h:outputText value="#{blogManager.item.text}" />
Likes: <h:outputText value="" />
<h:commandLink action="" value="like">
<f:param name="tweetid" value="" />
<f:param name="username" value="" />
</h:commandLink> <br />
<textarea>
<h:outputText value="" />
</textarea>
</c:forEach>
</ui:define>
这是托管bean:
@Named("blogmanager")
@SessionScoped
public class BlogManager implements Serializable {
private Blog BlogEntity;
@EJB
private BlogFacade BlogFacade;
@PostConstruct
public void init(){
BlogEntity = new Blog();
}
public Blog getBlogEntity(){
return this.BlogEntity;
}
public void setBlogEntity(Blog BlogEntity){
this.BlogEntity = BlogEntity;
}
public void save(){
BlogFacade.create(BlogEntity);
}
public void delete(){
BlogFacade.remove(BlogEntity);
}
public void deleteBlog(@QueryParam("blogid") int id){
BlogFacade.deleteBlog(id);
}
public List<Blog> getBlogs(){
return BlogFacade.getBlogs();
}
}
当尝试使用命令按钮"Tweet"时,我收到以下消息:/index.xhtml@113156 value="#{blogmanager.blogEntity.text}":目标无法访问,标识符"blogmanager"解析为空
我做错了什么?IDE Netbeans识别facelet中的managedbean,并建议特定于消息bean的方法和实体。
堆栈跟踪:
javax.el.PropertyNotFoundException: /index.xhtml @13,156 value="#{blogmanager.blogEntity.text}": Target Unreachable, identifier 'blogmanager' resolved to null
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1046)
at javax.faces.component.UIInput.validate(UIInput.java:976)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1249)
at javax.faces.component.UIInput.processValidators(UIInput.java:712)
at javax.faces.component.UIForm.processValidators(UIForm.java:253)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:744)
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'blogmanager' resolved to null
at com.sun.el.parser.AstValue.getTarget(AstValue.java:174)
at com.sun.el.parser.AstValue.getType(AstValue.java:86)
at com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:201)
at org.jboss.weld.el.WeldValueExpression.getType(WeldValueExpression.java:93)
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)
<h:outputText value="#{blogManager.item.text}"
应该是
<h:outputText value="#{item.text}"
如果不需要来自服务的初始化值,您还应该在bean的构造函数中初始化新实体。
编辑:尝试更改
@Named("blogmanager")
至@Named("blogManager")
在你的脸上,更换
<h:inputTextarea value="#{blogmanager.blogEntity.text}"
通过
<h:inputTextarea value="#{blogManager.blogEntity.text}" >
在Java编程语言中,命名对象的约定/标准方式是在第一个字母中使用小写字母。即将CCD_ 2改变为CCD_。你的问题与此无关,但坚持标准仍然是一件好事。
检查blogmanager与#{blogmanager.blogs((}的拼写