Bean is not reached by View

Asked

Viewed 47 times

0

I am with a Requestscoped Managedbean that is not being found by my view.

Managedbean

package br.com.hidros.control.beans;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import org.apache.commons.mail.EmailException;

import br.com.hidros.control.Email;

@ManagedBean(name="utilBean")
@RequestScoped
public class UtilBean implements Serializable {

    private static final long serialVersionUID = 1L;
    private Email email = new Email();

    /***************************************/
    /*********** Métodos Próprios **********/
    /***************************************/

    public String formatarData(Date data) {
        return new SimpleDateFormat("dd/MM/yyyy").format(data);
    }

    public void enviarEmail() {
        try {
            email.sendEmail();
        } catch (EmailException e) {
            e.printStackTrace();
        }
    }

    public void msg() {
        System.out.println("chegou");
    }
}

View

<?xml version="1.0" encoding="ISO-8859-1"?>  
<ui:composition 
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui" 
    xmlns:h="http://java.sun.com/jsf/html"
    template="/resources/template/template_restrito.xhtml">

    <ui:define name="css">
        <h:outputStylesheet library="css" name="restrito.css"/>
    </ui:define>

    <ui:define name="content">
        <div id="content">       

            <h:form id="form">
                <f:metadata>
                    <f:event type="preRenderView" listener="#{utilBean.msg()}"/>
                </f:metadata>
            </h:form>

            <h1 style="margin:0%; padding:0%;">PÁGINA PRINCIPAL</h1>
        </div>
    </ui:define>            
</ui:composition>

Exception

GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/Hidros] threw exception [/restrito/principal.xhtml @19,66 listener="#{utilBean.msg()}": Target Unreachable, identifier 'utilBean' resolved to null] with root cause
javax.el.PropertyNotFoundException: /restrito/principal.xhtml @19,66 listener="#{utilBean.msg()}": Target Unreachable, identifier 'utilBean' resolved to null
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:107)
    at com.sun.faces.facelets.tag.jsf.core.DeclarativeSystemEventListener.processEvent(EventHandler.java:128)
    at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.processEvent(UIComponent.java:2563)
    at javax.faces.event.SystemEvent.processListener(SystemEvent.java:108)
    at javax.faces.event.ComponentSystemEvent.processListener(ComponentSystemEvent.java:118)
    at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2190)
    at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(ApplicationImpl.java:2135)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:289)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:247)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:107)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

Thanks in advance.

  • 1

    Related: http://answall.com/questions/40669/

1 answer

0

I resolved.

I had forgotten to import some jars from the method I call on the Bean. I just referenced to the desktop, where they were.

Now it worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.