[Resolvido] Duvida JSF

10 respostas
C

quando dou um FacesContext.getCurrentInstance().getExternalContext() da excecao nullpointerexception

quando rodei apenas FacesContext.getCurrentInstance() vi que está voltando null… alguem tem alguma explicacao pra isso?

10 Respostas

M

Tens a stracktrace para ver onde que ele começa a reclamar de null?

Até!

C
09:59:42,647 INFO  [MyfacesConfig] No context init parameter 'org.apache.myfaces
.CHECK_EXTENSIONS_FILTER' found, using default value true
09:59:51,991 INFO  [STDOUT] Hibernate: select autor0_.COD_AUTOR as COD1_2_, auto
r0_.DSC_EMAIL as DSC2_2_, autor0_.NOM_AUTOR as NOM3_2_ from TB_AUTOR autor0_
09:59:52,038 ERROR [STDERR] java.lang.NullPointerException
09:59:52,038 ERROR [STDERR]     at br.com.digitalhall.ctrl.BaseBean.getRequest(B
aseBean.java:32)
09:59:52,038 ERROR [STDERR]     at br.com.digitalhall.ctrl.BaseBean.getRequestPa
rameter(BaseBean.java:22)
09:59:52,038 ERROR [STDERR]     at br.com.digitalhall.ctrl.AutorCtrlBean.deletar
(AutorCtrlBean.java:75)
09:59:52,038 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(
Native Method)
09:59:52,038 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke(N
ativeMethodAccessorImpl.java:39)
09:59:52,038 ERROR [STDERR]     at sun.reflect.DelegatingMethodAccessorImpl.invo
ke(DelegatingMethodAccessorImpl.java:25)
09:59:52,038 ERROR [STDERR]     at java.lang.reflect.Method.invoke(Method.java:5
85)
09:59:52,038 ERROR [STDERR]     at org.apache.myfaces.el.MethodBindingImpl.invok
e(MethodBindingImpl.java:132)
09:59:52,038 ERROR [STDERR]     at org.apache.myfaces.application.ActionListener
Impl.processAction(ActionListenerImpl.java:61)
09:59:52,038 ERROR [STDERR]     at javax.faces.component.UICommand.broadcast(UIC
ommand.java:109)
09:59:52,038 ERROR [STDERR]     at javax.faces.component.UIData.broadcast(UIData
.java:517)
09:59:52,038 ERROR [STDERR]     at javax.faces.component.UIViewRoot._broadcastFo
rPhase(UIViewRoot.java:97)
09:59:52,038 ERROR [STDERR]     at javax.faces.component.UIViewRoot.processAppli
cation(UIViewRoot.java:171)
09:59:52,038 ERROR [STDERR]     at org.apache.myfaces.lifecycle.InvokeApplicatio
nExecutor.execute(InvokeApplicationExecutor.java:32)
09:59:52,038 ERROR [STDERR]     at org.apache.myfaces.lifecycle.LifecycleImpl.ex
ecutePhase(LifecycleImpl.java:95)
09:59:52,038 ERROR [STDERR]     at org.apache.myfaces.lifecycle.LifecycleImpl.ex
ecute(LifecycleImpl.java:70)
09:59:52,038 ERROR [STDERR]     at javax.faces.webapp.FacesServlet.service(Faces
Servlet.java:139)
09:59:52,038 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterCha
in.internalDoFilter(ApplicationFilterChain.java:252)
09:59:52,038 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterCha
in.doFilter(ApplicationFilterChain.java:173)
09:59:52,038 ERROR [STDERR]     at org.jboss.web.tomcat.filters.ReplyHeaderFilte
r.doFilter(ReplyHeaderFilter.java:96)
09:59:52,038 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterCha
in.internalDoFilter(ApplicationFilterChain.java:202)
09:59:52,038 ERROR [STDERR]     at org.apache.catalina.core.ApplicationFilterCha
in.doFilter(ApplicationFilterChain.java:173)
09:59:52,038 ERROR [STDERR]     at org.apache.catalina.core.StandardWrapperValve
.invoke(StandardWrapperValve.java:213)
09:59:52,038 ERROR [STDERR]     at org.apache.catalina.core.StandardContextValve
.invoke(StandardContextValve.java:178)
09:59:52,038 ERROR [STDERR]     at org.jboss.web.tomcat.security.SecurityAssocia
tionValve.invoke(SecurityAssociationValve.java:175)
09:59:52,038 ERROR [STDERR]     at org.apache.catalina.authenticator.Authenticat
orBase.invoke(AuthenticatorBase.java:432)
09:59:52,038 ERROR [STDERR]     at org.jboss.web.tomcat.security.JaccContextValv
e.invoke(JaccContextValve.java:74)
09:59:52,038 ERROR [STDERR]     at org.apache.catalina.core.StandardHostValve.in
voke(StandardHostValve.java:126)
09:59:52,038 ERROR [STDERR]     at org.apache.catalina.valves.ErrorReportValve.i
nvoke(ErrorReportValve.java:105)
09:59:52,038 ERROR [STDERR]     at org.jboss.web.tomcat.tc5.jca.CachedConnection
Valve.invoke(CachedConnectionValve.java:156)
09:59:52,038 ERROR [STDERR]     at org.apache.catalina.core.StandardEngineValve.
invoke(StandardEngineValve.java:107)
09:59:52,038 ERROR [STDERR]     at org.apache.catalina.connector.CoyoteAdapter.s
ervice(CoyoteAdapter.java:148)
09:59:52,038 ERROR [STDERR]     at org.apache.coyote.http11.Http11Processor.proc
ess(Http11Processor.java:869)
09:59:52,054 ERROR [STDERR]     at org.apache.coyote.http11.Http11BaseProtocol$H
ttp11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
09:59:52,054 ERROR [STDERR]     at org.apache.tomcat.util.net.PoolTcpEndpoint.pr
ocessSocket(PoolTcpEndpoint.java:527)
09:59:52,054 ERROR [STDERR]     at org.apache.tomcat.util.net.MasterSlaveWorkerT
hread.run(MasterSlaveWorkerThread.java:112)
09:59:52,054 ERROR [STDERR]     at java.lang.Thread.run(Thread.java:595)
09:59:52,054 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet
 threw exception
javax.faces.FacesException: Error calling action method of component with id for
m1:_idJsp0:3:_idJsp12
        at org.apache.myfaces.application.ActionListenerImpl.processAction(Actio
nListenerImpl.java:72)
        at javax.faces.component.UICommand.broadcast(UICommand.java:109)
        at javax.faces.component.UIData.broadcast(UIData.java:517)
        at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:9
7)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1
71)
        at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(Invoke
ApplicationExecutor.java:32)
        at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl
.java:95)
        at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java
:70)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi
lter.java:96)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:178)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit
yAssociationValve.java:175)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
torBase.java:432)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv
e.java:74)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:105)
        at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConne
ctionValve.java:156)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:869)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.p
rocessConnection(Http11BaseProtocol.java:664)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpo
int.java:527)
        at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWor
kerThread.java:112)
        at java.lang.Thread.run(Thread.java:595)
Caused by: javax.faces.el.EvaluationException: Exception while invoking expressi
on #{autorCtrlBean.deletar}
        at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java
:156)
        at org.apache.myfaces.application.ActionListenerImpl.processAction(Actio
nListenerImpl.java:61)
        ... 28 more
Caused by: java.lang.NullPointerException
        at br.com.digitalhall.ctrl.BaseBean.getRequestParameter(BaseBean.java:22
)
        at br.com.digitalhall.ctrl.AutorCtrlBean.deletar(AutorCtrlBean.java:75)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java
:132)
        ... 29 more
C
public Object getRequestParameter(String parammeter) throws Exception {		
		return getRequest().getParameter(parammeter);
	}
	
	public Object getSessionAttribute(String name) {
		return getSession().getAttribute(name);
	}
	
	private HttpServletRequest getRequest() throws Exception {		
		try {
		   ExternalContext context = 
			   FacesContext.getCurrentInstance().getExternalContext();
		   return (HttpServletRequest)context.getRequest();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
M

Era para acontecer isso?

Caused by: java.lang.NullPointerException at br.com.digitalhall.ctrl.BaseBean.getRequestParameter(BaseBean.java:22 ) at br.com.digitalhall.ctrl.AutorCtrlBean.deletar(AutorCtrlBean.java:75)

C

maquiavelbona:
Era para acontecer isso?

Caused by: java.lang.NullPointerException at br.com.digitalhall.ctrl.BaseBean.getRequestParameter(BaseBean.java:22 ) at br.com.digitalhall.ctrl.AutorCtrlBean.deletar(AutorCtrlBean.java:75)

nao… era pra me retornar o parametro passado pela url

K

Tenta pegar usando o getRequestParametersMap(); [ ou algo semelhante ] no faces context. :wink:

C

o FacesContext.getCurrentInstance() já me retorna null… nao tem como chegar no getRequestParametersMap()…

qto a subir o facesServlet,
desculpa pela ignorancia… mas é assim?

web.xml


Faces Servlet
javax.faces.webapp.FacesServlet
1

K

Em alguma parte do sistema o FacesContext funciona? Já tentou depurar?

Era isso mesmo , mas eu ia perguntar isso mais no inicio da thread , acabou surgindo uns problemas aqui e demorei pra postar…

Boa sorte! :thumbup:

C
Guilherme Keller:
caduengenheiro:
o FacesContext.getCurrentInstance() já me retorna null... nao tem como chegar no getRequestParametersMap()..
Em alguma parte do sistema o FacesContext funciona? Já tentou depurar?

sim,.. mas pra fazer consulta parametrizada .. esta é a primeira

cara.. já to putasso com isso.. ng sabe, nao tem no google nada a respeito... to ferrado..

em qq lugar do meu fonte que eu chamo
FacesContext.getCurrentInstance()
retorna null.. nao sei se ta faltando algo no web.xml
<?xml version="1.0"?>
<!--
 * Copyright 2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * UPDATED: Marty Hall changed to use .faces suffix,
 *          faces-config.xml filename, and servlets 2.4.
 *          See tutorial at http://www.coreservlets.com/JSF-Tutorial/.
 *          Note: uncomment the filter entries at the bottom
 *                to use Tomahawk extended components.
-->

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">

    <!-- Marty Hall: 
         Changed name from "examples-config.xml"
         back to standard of "faces-config.xml" -->
    <context-param>
        <param-name>javax.faces.CONFIG_FILES</param-name>
        <param-value>
            /WEB-INF/faces-config.xml
        </param-value>
        <description>
            Comma separated list of URIs of (additional) faces config files.
            (e.g. /WEB-INF/my-config.xml)
            See JSF 1.0 PRD2, 10.3.2
        </description>
    </context-param>

    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
        <description>
            State saving method: "client" or "server" (= default)
            See JSF Specification 2.5.2
        </description>
    </context-param>

    <context-param>
        <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
        <param-value>true</param-value>
        <description>
            This parameter tells MyFaces if javascript code should be allowed in the
            rendered HTML output.
            If javascript is allowed, command_link anchors will have javascript code
            that submits the corresponding form.
            If javascript is not allowed, the state saving info and nested parameters
            will be added as url parameters.
            Default: "true"
        </description>
    </context-param>

    <context-param>
        <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
        <param-value>true</param-value>
        <description>
            If true, rendered HTML code will be formatted, so that it is "human readable".
            i.e. additional line separators and whitespace will be written, that do not
            influence the HTML code.
            Default: "true"
        </description>
    </context-param>

    <context-param>
        <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
        <param-value>false</param-value>
    </context-param>

    <context-param>
        <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
        <param-value>true</param-value>
        <description>
            If true, a javascript function will be rendered that is able to restore the
            former vertical scroll on every request. Convenient feature if you have pages
            with long lists and you do not want the browser page to always jump to the top
            if you trigger a link or button action that stays on the same page.
            Default: "false"
        </description>
    </context-param>

    <!-- Listener, that does all the startup work (configuration, init). -->
    <listener>
        <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
    </listener>

    <!-- Faces Servlet
         Marty Hall: changed .jsf back to standard of .faces -->
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>

    <!-- Welcome files -->
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

	<security-constraint>
		<display-name>
			Prevent access to raw JSP pages that are for JSF pages.
		</display-name>
		<web-resource-collection>
			<web-resource-name>Raw-JSF-JSP-Pages</web-resource-name>
			<!-- Add url-pattern for EACH raw JSP page -->
			<url-pattern>/primeiro.jsp</url-pattern>
		</web-resource-collection>
		<auth-constraint>
			<description>No roles, so no direct access</description>
		</auth-constraint>
	</security-constraint>

<!-- 
*** Uncomment the extensions filter and the two following extensions
*** mappings to enable Tomahawk (MyFaces extended components
*** and custom validators). See tutorial at 
*** http://www.coreservlets.com/JSF-Tutorial/ and
*** http://myfaces.apache.org/tomahawk/extensionsFilter.html
*** Also note that if you use the old style (servlet 2.3)
*** declaration for web.xml, you have to put these filter entries
*** at the TOP of web.xml.
     
    <filter>
	<filter-name>MyFacesExtensionsFilter</filter-name>
	<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
        <init-param>
            <param-name>maxFileSize</param-name>
            <param-value>20m</param-value>
            <description>Set the size limit for uploaded files.
                Format: 10 - 10 bytes
                        10k - 10 KB
                        10m - 10 MB
                        1g - 1 GB
            </description>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
    <filter-mapping>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
    </filter-mapping>
*** -->

</web-app>
C

de tanto fuçar acabei descobrindo o erro

eu uso dois diretórios de src:

entity-src e web-src…

entity-src guarda meu persistence.xml e meus domains (dessa forma nao preciso declarar todos os domains no persistence.xml)

web-src guarda os arquivos de configuracao e os outros modulos… business e persistencia…

o entity-src gera um jar e o web-src gera um war… os dois juntos viram um ear da minha aplicacao

o que tava acontecendo é que eu nao tinha configurado corretamente pra onde iam quais .class… entao todos estavam indo para o jar (inclusive business e persistencia) e o war nao continha o business e persistencia gerando os problemas de passagem de parametros

bem… é isso ai… obrigado quem tentou me ajudar

Criado 30 de março de 2007
Ultima resposta 30 de mar. de 2007
Respostas 10
Participantes 3