无法再次访问托管bean ... jsf

时间:2014-05-18 20:34:53

标签: java jsf jsf-2

我不确定我做错了什么。我的另一个项目遇到了同样的问题,我无法访问托管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}" />&nbsp;&nbsp;
        Likes: &nbsp;&nbsp;<h:outputText value="" />&nbsp;&nbsp;&nbsp;
        <h:commandLink action="" value="like">
            <f:param name="tweetid" value="" />
            <f:param name="username" value="" />
        </h:commandLink>&nbsp;<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();
}
}

尝试使用commandButton&#34; Tweet&#34;我收到此消息:/index.xhtml @ 13,156 value =&#34;#{blogmanager.blogEntity.text}&#34;:Target Unreachable,identifier&#39; blogmanager&#39;解析为null

我做错了什么? 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)

2 个答案:

答案 0 :(得分:1)

<h:outputText value="#{blogManager.item.text}"

应该是

<h:outputText value="#{item.text}"

如果bean的构造函数不需要服务的初始化值,你也应该在bean的构造函数中初始化它。

编辑: 尝试更改

@Named("blogmanager")

@Named("blogManager")

在你的脸上, 取代

<h:inputTextarea value="#{blogmanager.blogEntity.text}" 

通过

<h:inputTextarea value="#{blogManager.blogEntity.text}" >

在Java编程语言中,命名对象的约定/标准方法是使用小写字母作为第一个字母。即将BlogEntity更改为blogEntity。你的问题与此无关,但坚持标准仍然是件好事。

答案 1 :(得分:0)

检查拼写blogmanager vs#{blogManager.blogs()}