Visualizzazione dei risultati da 1 a 4 su 4

Discussione: Problema con JSF

  1. #1

    Problema con JSF

    ciao a tutti,
    sono uno studente e ho appena iniziato a lavorare con le JSF, nonostante sia abbastanza pratico di java e jsp ho trovato molte difficoltà a far funzionare l'ambiente su eclipse e avrei bisogno di un piccolo aiuto su un errore riscontrato.
    adesso tento di dare tutte le informazioni necessarie:
    uso Eclipse elios, Apache Tomcat 6.0 e il framework JFS della SUN versione 1.2 (ho provato anche il 2.0 sempre SUN ).

    cosa ho fatto:
    ho creato un nuovo dynamic web project, nei setting iniziali ho messo in configuration javaserver faces 1.2 runtime e importato i jar relativi a jsf , jsf-api jsf-impl e jstl-api-1.2

    una volta creato il progetto ho aggiunto una semplice jsp a webcontent e come template ho messo "New javaserver faces (JSF) Page (html)"

    ho aggiunto una semplice tabella vuota alla pagina e ho generato il war per tomcat per vedere se funzionava.
    purtroppo non funziona e la pagina ritorna un errore :
    java.lang.RuntimeException: Cannot find FacesContext


    qui di seguito posto tutto il codice di errore



    codice:
    type Exception report
    
    message
    
    description The server encountered an internal error () that prevented it from fulfilling this request.
    
    exception
    
    org.apache.jasper.JasperException: An exception occurred processing JSP page /prova.jsp at line 11
    
    8: <title>Insert title here</title>
    9: </head>
    10: <body>
    11: <f:view>
    12: 
    13: 	<h:dataTable border="1">
    14: 		<h:column id="column1">
    
    
    Stacktrace:
    	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    root cause
    
    java.lang.RuntimeException: Cannot find FacesContext
    	javax.faces.webapp.UIComponentClassicTagBase.getFacesContext(UIComponentClassicTagBase.java:1852)
    	javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:1669)
    	org.apache.jsp.prova_jsp._jspx_meth_f_005fview_005f0(prova_jsp.java:105)
    	org.apache.jsp.prova_jsp._jspService(prova_jsp.java:79)
    	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

    il file jsp è il esguente:


    codice:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
    <%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <f:view>
    
    	<h:dataTable border="1">
    		<h:column id="column1">
    			<f:facet name="header">
    				<h:outputText value="column1"></h:outputText>
    			</f:facet>
    		</h:column>
    		<h:column id="column2">
    			<f:facet name="header">
    				<h:outputText value="column2"></h:outputText>
    			</f:facet>
    		</h:column>
    	</h:dataTable>
    </f:view>
    </body>
    </html>
    infine i file di configurazione web.xml e faces-config.xml

    codice:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>prova</display-name>
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
      </welcome-file-list>
      <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>
      <context-param>
        <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
      </context-param>
      <context-param>
        <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
        <param-value>resources.application</param-value>
      </context-param>
      <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
      </listener>
      <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
      </servlet-mapping>
    </web-app>
    .

    codice:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <faces-config
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/we...config_1_2.xsd"
        version="1.2">
    
    </faces-config>
    leggendo un po in rete ho trovato alcuni che dicevano di aggiungere al web.xml
    <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsp</url-pattern>
    </servlet-mapping>
    ma se lo aggiungo il sito non riesco nemmeno a "startarlo" su tomcat quindi nn credo sia una buona idea.
    quancuno ha qualche consiglio o si è trovato con stesso problema?
    grazie anticipatamente

  2. #2
    Utente di HTML.it L'avatar di bstefano79
    Registrato dal
    Feb 2004
    Messaggi
    2,520

    Re: Problema con JSF

    leggendo un po in rete ho trovato alcuni che dicevano di aggiungere al web.xml
    <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsp</url-pattern>
    </servlet-mapping>
    ma se lo aggiungo il sito non riesco nemmeno a "startarlo" su tomcat quindi nn credo sia una buona idea.
    quancuno ha qualche consiglio o si è trovato con stesso problema?
    grazie anticipatamente
    ce l'hai gia quel pezzo di codice nel web.xml
    codice:
      <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
      </servlet-mapping>
    questo vuol dire (in parole povere) che se anche la pagina è jsp la devi chiare come fosse jsf

    http://localhosorta/cartelle/prova.jsf

    fammi sapere

  3. #3
    grazie mille!
    adesso funziona!
    In pratica (correggimi se sbaglio) da eclipse le pagine le crea tutte con estenzione jsp qualsiasi template io decida di usare, ma io da browser posso chiamarle solo con .jsf e .faces come è definito nel web.xml.
    un ultima cosa, sempre nel web.xml ho visto questo:
    codice:
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
      </servlet-mapping>
    è sempre un mapping ma cosa mi significa ?

    ciao e grazie ancora

  4. #4
    Utente di HTML.it L'avatar di bstefano79
    Registrato dal
    Feb 2004
    Messaggi
    2,520
    Originariamente inviato da 5tefano82
    grazie mille!
    adesso funziona!
    prego
    è un tipico errore di quando si inizia
    In pratica (correggimi se sbaglio) da eclipse le pagine le crea tutte con estenzione jsp qualsiasi template io decida di usare, ma io da browser posso chiamarle solo con .jsf e .faces come è definito nel web.xml.
    si
    un ultima cosa, sempre nel web.xml ho visto questo:
    codice:
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
      </servlet-mapping>
    è sempre un mapping ma cosa mi significa ?

    ciao e grazie ancora
    significa che le pagine jsp le va a cercare nella cartella faces del WebContent del tuo progetto. Se apri il workspace e vai in WebContent/faces troverai il tuo prova.jsp

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.