2

是否有解决以下错误的方法。当我单击命令按钮时,它会调用 java 脚本来设置 topic_body、topic_url 的值,并通过命令按钮将值提交给服务器中的方法。我不确定需要纠正什么来阻止错误。

XHTML

<h:form prependId="false" id="testForm">
        <h:inputHidden value="#{topicBean.topicVO.body}" id="topic_body">
        </h:inputHidden>
        <h:inputHidden value="#{topicBean.topicVO.videoAudioUrl}" id="topic_vaurl" >
        </h:inputHidden>
        <h:inputHidden value="#{topicBean.topic_guid}" id="topic_guid">
        </h:inputHidden>
                <p:commandButton id="shareeButton" action="#{topicController.createTopic}" onclick="javascript:renderElement();">
                Share
                <f:ajax execute="@form" render="@form"></f:ajax>
                </p:commandButton>
            </h:form>

Javascript

function  renderElement(){
           var textarea_content = $('textarea#wall').val();
           $('#topic_body').val(textarea_content);
           if (textarea_content != '') {
               var sitetitle = $('label.title').html();
               if (sitetitle == null) {
                   sitetitle = ' ';
               }
.......
......
..

}

JSF 豆

@ManagedBean(name = "topicBean")
@SessionScoped
public class TopicBean extends BaseMB implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private final static Logger logger = Logger.getLogger(CircleBean.class.toString());
    private TopicVO topicVO = new TopicVO();
    private long topic_guid =0;
    public TopicBean(){
        logger.info("****************************Start TopicBean Constructor****************************************");
        logger.info("****************************End TopicBean Constructor****************************************");

    }

JSF 方法

@ManagedBean(name = "topicController")
@RequestScoped
public class TopicController  extends BaseMB implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private final static Logger logger = Logger
            .getLogger(CircleController.class.toString());
    TopicBean topicBean;


    public void createTopic(){
        logger.info("*******************Inside creatTopic********************");
        topicBean = (TopicBean) FacesUtils.getManagedBean("topicBean");
        ITopicService topicService = (ITopicService) ServiceLocator
                .getService("TOPICSERVICE");
         topicBean.setTopic_guid(topicService.createTopic(topicBean.getTopicVO(), userSession));

        logger.info("*******************Inside creatTopic********************");
    }

错误

14:44:20,335 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/emyed-web].[Faces Servlet]] (http--127.0.0.1-8080-3) Servlet.service() for servlet Faces Servlet threw exception: java.lang.NullPointerException
    at com.sun.faces.mgbean.BeanManager$ScopeManager$SessionScopeHandler.handle(BeanManager.java:575) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.mgbean.BeanManager$ScopeManager.pushToScope(BeanManager.java:458) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:410) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.zreflect.emyed.filter.EmyEdAccessFilter.hasLoggedIn(EmyEdAccessFilter.java:113) [emyed-ui-1.0.jar:]
    at com.zreflect.emyed.filter.EmyEdAccessFilter.doFilter(EmyEdAccessFilter.java:84) [emyed-ui-1.0.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:897) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:626) [jbossweb-7.0.13.Final.jar:]
    at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:2039) [jbossweb-7.0.13.Final.jar:]
    at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_25]



enter code here
4

2 回答 2

4

根据堆栈跟踪,

java.lang.NullPointerException
    at com.sun.faces.mgbean.BeanManager$ScopeManager$SessionScopeHandler.handle(BeanManager.java:575) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.mgbean.BeanManager$ScopeManager.pushToScope(BeanManager.java:458) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:410) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.zreflect.emyed.filter.EmyEdAccessFilter.hasLoggedIn(EmyEdAccessFilter.java:113) [emyed-ui-1.0.jar:]
    at com.zreflect.emyed.filter.EmyEdAccessFilter.doFilter(EmyEdAccessFilter.java:84) [emyed-ui-1.0.jar:]

您有一个FilterEmyEdAccessFilter正在尝试使用 解析特定于 JSF 的 EL 表达式ValueExpression,其唯一目的很可能是查找会话范围的 JSF 托管 bean 或其应该代表登录用户的属性。FacesContext但是这个 EL 解析失败了,因为servlet 过滤器内部没有方法。应该由FacesContext来创建FacesServlet,但是在过滤器运行的那一刻,FacesServlet根本没有运行,因此FacesContext.getCurrentInstance()返回null,因此您的代码会中断。

总而言之,这不是在过滤器中检查会话范围的 JSF 托管 bean 的正确方法。

在 JSF 的保护下,会话范围的托管 bean 存储为 的属性,HttpSession托管 bean 名称作为会话属性名称。您可以将它们作为 servlet 过滤器中的会话属性以“常规方式”访问。例如

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;
    HttpSession session = request.getSession(false);
    UserManager userManager = (session != null) ? (UserManager) session.getAttribute("userManager") : null;

    if (userManager == null || !userManager.isLoggedIn()) {
        response.sendRedirect(request.getContextPath() + "/login.xhtml"); // No logged-in user found, so redirect to login page.
    } else {
        chain.doFilter(req, res); // Logged-in user found, so just continue request.
    }
}

WhereUserManager代表您的会话范围的 JSF 托管 bean。

也可以看看:

于 2012-08-27T19:41:39.440 回答
0

还要检查@ManagedProperty 是否正确。例如:

@ManagedProperty(value = "#{user_ejb}")
UserEJB userEJB;

或@Inject

于 2015-02-03T21:38:11.557 回答