JSF - Non mi visualizza i tag jsf

di il
5 risposte

JSF - Non mi visualizza i tag jsf

Ho provato ad inserire la combobox nella pagina index.xhtml, ma quando avvio il server apache tomcat non fà vedere niente, vede solo la pagina vuota.
Ho sbagliato qualcosa?

index.xhtml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml" 
   xmlns:f = "http://java.sun.com/jsf/core"     
   xmlns:h = "http://java.sun.com/jsf/html"> 
   
   <head> 
      <title>Progetto Falavigna</title> 
   </head> 
   
   <h:body> 
      
      <h:form> 
         <h3>Combo Box</h3>  
         <h:selectOneMenu value = "#crudGenericsImpl}"> 
            <f:selectItem itemValue = "1" itemLabel = "Item 1" /> 
            <f:selectItem itemValue = "2" itemLabel = "Item 2" />   
         </h:selectOneMenu>  
         <h:commandButton value = "Submit" action = "result" /> 
      </h:form>    
   
   </h:body> 
</html>

web.xml

<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>ProgettoFalavignaJsf</display-name>
  
  <welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</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>
  
  
</web-app>



faces-config.xml

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.0" 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/web-facesconfig_2_0.xsd">
 
  
 
</faces-config>


5 Risposte

  • Re: JSF - Non mi visualizza i tag jsf

    Correzione nella pagina index.xhtml ma non funziona lo stesso:
    <h:selectOneMenu value = " ">
    oppure soltanto il nome del Bean
    <h:selectOneMenu value = "#{crudGenericsImpl}">
    ma non funziona lo stesso ma vedo soltanto una pagina vuota con la scritta combobox
  • Re: JSF - Non mi visualizza i tag jsf

    robot ha scritto:


        <url-pattern>/faces/*</url-pattern>
    E il tuo index.xhtml .. dove è? Sotto la faces? O no? Se no ... come pensi che possa entrare in gioco la FacesServlet?
  • Re: JSF - Non mi visualizza i tag jsf

    Web.xml modificato:
    
    <?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"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    	id="WebApp_ID" version="3.0">
    	<display-name>ProgettoFalavignaJsf</display-name>
    
    	<!-- Change to "Production" when you are ready to deploy -->
    	<context-param>
    		<param-name>javax.faces.PROJECT_STAGE</param-name>
    		<param-value>Development</param-value>
    	</context-param>
    
    	<!-- Welcome page -->
    	<welcome-file-list>
    		<welcome-file>index.xhtml</welcome-file>
    	</welcome-file-list>
    
    	<!-- JSF mapping -->
    	<servlet>
    		<servlet-name>Faces Servlet</servlet-name>
    		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    
    	<!-- Map these files with JSF -->
    	<servlet-mapping>
    		<servlet-name>Faces Servlet</servlet-name>
    		<url-pattern>/faces/*</url-pattern>
    	</servlet-mapping>
    	<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>
    	<servlet-mapping>
    		<servlet-name>Faces Servlet</servlet-name>
    		<url-pattern>*.xhtml</url-pattern>
    	</servlet-mapping>
    
    
    </web-app>
    
    

    pom.xml modificato: --> vedete se manca qualche driver?
    
    <project xmlns="http://maven.apache.org/POM/4.0.0"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    	<modelVersion>4.0.0</modelVersion>
    	<groupId>ProgettoFalavignaJsf</groupId>
    	<artifactId>ProgettoFalavignaJsf</artifactId>
    	<version>0.0.1-SNAPSHOT</version>
    	<packaging>war</packaging>
    
    
    	<dependencies>
    		<dependency>
    			<groupId>mysql</groupId>
    			<artifactId>mysql-connector-java</artifactId>
    			<version>5.1.6</version>
    		</dependency>
    		<dependency>
    			<groupId>com.sun.faces</groupId>
    			<artifactId>jsf-api</artifactId>
    			<version>2.2.2</version>
    		</dependency>
    		<dependency>
    			<groupId>com.sun.faces</groupId>
    			<artifactId>jsf-impl</artifactId>
    			<version>2.2.2</version>
    		</dependency>
    		<dependency>
    			<groupId>javax.servlet</groupId>
    			<artifactId>javax.servlet-api</artifactId>
    			<version>3.0.1</version>
    		</dependency>
    		<dependency>
    			<groupId>javax.servlet</groupId>
    			<artifactId>jstl</artifactId>
    			<version>1.2</version>
    		</dependency>
    		<dependency>
    			<groupId>javax.servlet.jsp</groupId>
    			<artifactId>jsp-api</artifactId>
    			<version>2.1</version>
    		</dependency>
    		<dependency>
    			<groupId>javax.servlet</groupId>
    			<artifactId>servlet-api</artifactId>
    			<version>2.5</version>
    		</dependency>
    		<dependency>
    			<groupId>commons-fileupload</groupId>
    			<artifactId>commons-fileupload</artifactId>
    			<version>1.3</version>
    		</dependency>
    	</dependencies>
    
    
    
    	<build>
    		<sourceDirectory>src</sourceDirectory>
    		<plugins>
    			<plugin>
    				<artifactId>maven-compiler-plugin</artifactId>
    				<version>3.7.0</version>
    				<configuration>
    					<source>1.6</source>
    					<target>1.6</target>
    				</configuration>
    			</plugin>
    			<plugin>
    				<artifactId>maven-war-plugin</artifactId>
    				<version>3.2.1</version>
    				<configuration>
    					<warSourceDirectory>WebContent</warSourceDirectory>
    				</configuration>
    			</plugin>
    		</plugins>
    	</build>
    </project>
    
    
    

    xhtml:
    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:f="http://java.sun.com/jsf/core"      
          xmlns:h="http://java.sun.com/jsf/html">
    	
        <h:head>
            <title>JSF 2.0 Hello World</title>
        </h:head>
        <h:body>
        	<h2>JSF 2.0 Hello World Example - hello.xhtml</h2>
        	<h:form>
        	   <h:inputText value="#{anagrafica.nome}"></h:inputText>
        	   <h:commandButton value="Welcome Me" action="welcome"></h:commandButton>
        	</h:form>
        </h:body>
    </html>
    
    
    Gentilmente se qualcuno conosce i jsf, chiedo se mi potete risolvere questo problema che quando avvio nella pagina index.xhtml non vede niente
  • Re: JSF - Non mi visualizza i tag jsf

    Risolto!!!!
  • Re: JSF - Non mi visualizza i tag jsf

    robot ha scritto:


    
    	<servlet-mapping>
    		<servlet-name>Faces Servlet</servlet-name>
    		<url-pattern>/faces/*</url-pattern>
    	</servlet-mapping>
    	<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>
    	<servlet-mapping>
    		<servlet-name>Faces Servlet</servlet-name>
    		<url-pattern>*.xhtml</url-pattern>
    	</servlet-mapping>
    
    Questo è di per sé corretto. Ma giusto perché tu lo sappia, a partire dalle Servlet API 2.5 il XSD di descrizione del web.xml è stato ampliato ed è diventato lecito avere più <url-pattern> dentro <servlet-mapping>.
    Quindi quella parte si potrebbe compattare.

    robot ha scritto:


    
    		<dependency>
    			<groupId>javax.servlet</groupId>
    			<artifactId>javax.servlet-api</artifactId>
    			<version>3.0.1</version>
    		</dependency>
    
    		<dependency>
    			<groupId>javax.servlet</groupId>
    			<artifactId>servlet-api</artifactId>
    			<version>2.5</version>
    		</dependency>
    Qui hai sostanzialmente la API della Servlet ripetuta e in due versioni differenti. Non va bene. Visto che il web.xml ce l'hai con version 3.0, allora tieni la 3.0.1 e togli la 2.5 .

    Inoltre: le dipendenze della Servlet API e la JSP API sono già implementate di certo nel Servlet container (qualunque esso sia), quindi di norma queste dipendenze si mettono nel pom.xml con scope "provided". Ovvero sono messe in classpath da Maven in compilazione ma NON vengono portate avanti nel pacchetto war finale (se si arriva a quello) perché sarà già il container a fornirle a runtime.

    Quindi
    		<dependency>
    			<groupId>javax.servlet</groupId>
    			<artifactId>javax.servlet-api</artifactId>
    			<version>3.0.1</version>
    			<scope>provided</scope>
    		</dependency>
    
    		<dependency>
    			<groupId>javax.servlet.jsp</groupId>
    			<artifactId>jsp-api</artifactId>
    			<version>2.1</version>
    			<scope>provided</scope>
    		</dependency>
    La JSTL non so se la usi.
Devi accedere o registrarti per scrivere nel forum
5 risposte