tutorials.de Buch-Aktion 05/2012
ERLEDIGT
NEIN
ANTWORTEN
2
ZUGRIFFE
621
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    schwarzenegger schwarzenegger ist offline Mitglied
    Registriert seit
    Dec 2008
    Beiträge
    17
    Hallo,

    ich bin Anfänger in JSF und probiere gerade ein Beispiel-Projekt aufzuziehen, aber das funktioniert leider überhaupt nicht.

    Ich benutze JSF 1.2.

    Was kann ich tun ?

    Ich komme nicht weiter ?

    Bekomme immer folgende Exception:
    Code :
    1
    2
    
    org.apache.jasper.el.JspPropertyNotFoundException: 
    /test_jsf.jsp(16,2) '#{Test_jsf_bean.input}' Target Unreachable, identifier 'Test_jsf_bean' resolved to null

    faces-config.xml:
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
    <?xml version="1.0" encoding="UTF-8"?>
    <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xi="http://www.w3.org/2001/XInclude"
     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_1_2.xsd">
     
     <managed-bean>
      <managed-bean-name>Test_jsf_bean</managed-bean-name>
      <managed-bean-class>test_jsf_package.Test_jsf_bean</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
     </managed-bean>
     
    </faces-config>

    web.xml:
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    
    <?xml version="1.0"?>
    <web-app version="2.5" 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-app_2_5.xsd">
     <!-- Display Name -->
    <display-name>test</display-name>
     <!-- Context Name -->
     <context-param>
      <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
      <param-value>server</param-value>
     </context-param>
     <!-- Listener -->
     <listener>
      <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
     </listener>
     <!-- Faces Servlet -->
     <servlet>
      <servlet-name>Faces Servlet</servlet-name>
      <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
     </servlet>
     <!-- Faces Servlet Mapping -->
     <servlet-mapping>
      <servlet-name>Faces Servlet</servlet-name>
      <url-pattern>*.jsf</url-pattern>
     </servlet-mapping>
    </web-app>

    Bean:
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    
    package test_jsf_package;
     
    import java.io.Serializable;
     
    public class Test_jsf_bean implements Serializable{
     
        private static final long serialVersionUID = 1L;
        private String input = "Test";
        private String output = "Test";
     
        public Test_jsf_bean() {
            super();
        }
     
        public void action() {
            output = "Welcome at the JSF world, " + input;
        }
        
        public void test() {
        }
        
        public String getInput() {
            return input;
        }
     
        public void setInput(String input) {
            this.input = input;
        }
     
        public String getOutput() {
            return output;
        }
     
        public void setOutput(String output) {
            this.output = output;
        }
    }

    jsp:
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <f:view>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Title</title>
    </head>
    <body>
        <h:form>
            <h:outputLabel value="Enter your name (input): " /> <!-- for="input" -->
            <h:inputText id="input" value="#{Test_jsf_bean.input}" required="true" />
            <h:commandButton value="submit" action="#{Test_jsf_bean.action}" />
            <h:outputText value="#{Test_jsf_bean.output}" />
            <h:messages />
        </h:form>
    </body>
    </html>
    </f:view>

    build.xml:
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    
    <?xml version="1.0" encoding="UTF-8"?>
    <project name="ear" default="deploy-local" basedir=".">
     
        <property name="ear.name" value="test_jsf.ear" />
        <property name="war.name.server" value="test_jsf.war" />
        <property name="jar.name.server" value="test_jsf.jar" />
        <property name="jar.name.client" value="test-client.jar" />
     
        <property name="deploy.dir.local" value="C:/develop/jboss-5.1.0.GA/jboss-5.1.0.GA/server/default/deploy" />
     
        <!-- <property name="src.dir.client" value="C:/Dokumente und Einstellungen/Administrator/workspace/ejb_project_testClient/ejbModule/" /> -->
     
        <property name="ear.dir.build" value="${basedir}/build" />
        <property name="ear.dir.name" value="${ear.dir.build}/${ear.name}" />
        
        <property name="jboss.dir" value="C:/develop/jboss-5.1.0.GA/jboss-5.1.0.GA" />
     
        <property name="ear.META-INF.dir" value="${basedir}/EarContent/META-INF/" />
        <property name="ear.META-INF.dir.appxml" value="${basedir}/EarContent/META-INF/application.xml" />
     
        <property name="war.WebContent.dir" value="C:/Dokumente und Einstellungen/Administrator/workspace/test_jsf/WebContent/" />
        <property name="war.WEB-INF.dir" value="C:/Dokumente und Einstellungen/Administrator/workspace/test_jsf/WebContent/WEB-INF" />
        <property name="war.WEB-INF.dir.lib" value="C:/Dokumente und Einstellungen/Administrator/workspace/test_jsf/WebContent/WEB-INF/lib" />
        <property name="war.WEB-INF.dir.webxml" value="C:/Dokumente und Einstellungen/Administrator/workspace/test_jsf/WebContent/WEB-INF/web.xml" />
        <property name="war.WEB-INF.dir.classes" value="C:/Dokumente und Einstellungen/Administrator/workspace/test_jsf/WebContent/WEB-INF/classes" />
        <property name="war.WEB-INF.dir.src.package" value="C:/Dokumente und Einstellungen/Administrator/workspace/test_jsf/WebContent/WEB-INF/src/test_jsf_package/" />
     
        <!-- Beliebig erweiterbar -->
        <path id="compile.classpath.1">
            <pathelement location="${jboss.dir}" />
            <fileset dir="${jboss.dir}/client">
                <include name="*.jar" />
            </fileset>
        </path>
        
        <path id="compile.classpath.2">
            <pathelement location="${war.WEB-INF.dir.lib}" />
            <fileset dir="${war.WEB-INF.dir.lib}">
                <include name="*.jar" />
            </fileset>
        </path>
     
        <target name="init" description="Build the distribution build folder">
            <tstamp />
            <mkdir dir="build" />
        </target>
     
        <target name="compile" depends="init" description="Compile the Java source code">
            <javac destdir="build" debug="on" optimize="on" debuglevel="lines,vars,source"> 
                <!-- classpath="${jboss.dir}/client/jbossall-client.jar" -->
                <src path="${war.WEB-INF.dir.src.package}" />
                <classpath refid="compile.classpath.1" />
                <classpath refid="compile.classpath.2" />
            </javac>
        </target>
     
        <target name="jar" depends="compile" description="Build the distribution *.jar file">
            <jar jarfile="build/${jar.name.server}">
                <fileset dir="build">
                    <include name="**/*.class" />
                    <exclude name="test/*.class" />
                </fileset>
            </jar>
        </target>
     
        <target name="war" depends="compile" description="Build the distribution *.war file">
            <war destfile="build/${war.name.server}" webxml="${war.WEB-INF.dir.webxml}">
                <lib dir="${war.WEB-INF.dir.lib}" />
                <classes dir="${war.WEB-INF.dir.classes}" /> 
                
                <fileset dir="${war.WebContent.dir}">
                    <include name="**/*.jsp" />
                    <!-- <exclude name="WEB-INF/web.xml" /> -->
                </fileset>
                
                <fileset dir="${war.WEB-INF.dir}">
                    <include name="**/*.xml" />
                </fileset>
            </war>
        </target>
     
        <target name="ear" depends="jar, war" description="Build the distribution *.ear file">
            <ear destfile="${ear.dir.name}" appxml="${ear.META-INF.dir.appxml}">
                <metainf dir="${ear.META-INF.dir}" />
                <fileset dir="${ear.dir.build}">
                    <include name="*.war" />
                    <include name="*.jar" />
                </fileset>
            </ear>
        </target>
     
        <target name="deploy-local" depends="ear" description="Deploys *.ear to local jboss folder">
            <copy todir="${deploy.dir.local}">
                <fileset dir="${ear.dir.build}">
                    <include name="*.ear" />
                </fileset>
            </copy>
        </target>
     
        <target name="clean" depends="ear" description="Delete all generated files and folders">
            <delete dir="build" />
        </target>
     
    </project>

    Ordner-Struktur:
    test_jsf (Projektname):
    test_jsf/../WebContent
    test_jsf/../WebContent/test_jsf.jsp
    test_jsf/../WebContent/META-INF
    test_jsf/../WebContent/WEB-INF
    test_jsf/../WebContent/WEB-INF/lib
    test_jsf/../WebContent/WEB-INF/faces-config.xml
    test_jsf/../WebContent/WEB-INF/web.xml
    test_jsf/../WebContent/WEB-INF/src
    test_jsf/../WebContent/WEB-INF/classes
    Geändert von schwarzenegger (07.11.10 um 12:04 Uhr)
     

  2. #2
    MadM MadM ist offline Mitglied Bronze
    Registriert seit
    Mar 2005
    Ort
    Darmstadt
    Beiträge
    39
    probiers mal hiermit:

    http://jsftutorials.net/jsf1.2-and-Facelets.html

    (jsf12KickStart.zip)
     

  3. #3
    schwarzenegger schwarzenegger ist offline Mitglied
    Registriert seit
    Dec 2008
    Beiträge
    17
    @MadM
    Thx für deine Antwort.
    Ich habe mein Problem gelöst.
    Es lag an meiner falsch konstruierten WAR-Datei.

    @Alle
    Für alle die Anfänger in JSF sind, empfehle ich als Build-Tool vielleicht lieber apache maven.
    Ich nutze apache ant und daher habe ich meine WAR falsch gebaut.
    Meine test.war hat jetzt folgende Struktur:

    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    WebContent\
    WebContent\img\
    WebContent\META-INF\MANIFEST.MF
    WebContent\WEB-INF\
    WebContent\WEB-INF\classes\
    WebContent\WEB-INF\lib\
    WebContent\WEB-INF\faces-config.xml
    WebContent\WEB-INF\web.xml
    WebContent\pages\test.xhtml
    WebContent\stylesheets\
    WebContent\templates\

    In meiner build.xml habe ich mein war-target folgendermaßen angepasst:

    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    
    <target name="war" depends="compile" description="Build the distribution *.war file">
        <war destfile="test.war"webxml="C:/develop/workspace/test_jsf/WebContent/WEB-
     INF/web.xml">
            <metainf dir="C:/develop/workspace/test_jsf/WebContent/WEB-INF/" />
            <lib dir="C:/develop/workspace/test_jsf/WebContent/WEB-INF/lib/" />
            <classes dir="C:/develop/workspace/test_jsf/build/classes" />
     
            <webinf dir="C:/develop/workspace/test_jsf/WebContent/WEB-INF/">
                <include name="*.xml" />
                <exclude name="web.xml" />
            </webinf>
     
            <fileset dir="C:/develop/workspace/test_jsf/WebContent/">
                <include name="**/*.css" />
                <include name="**/*.html" />
                <include name="**/*.xhtml" />
            </fileset>
     
            <!-- Bilder -->
            <zipfileset dir="C:/develop/workspace/test_jsf/WebContent/img/" prefix="img"/>
        </war>
    </target>
    Geändert von schwarzenegger (27.11.10 um 21:15 Uhr)
     

Ähnliche Themen

  1. Warum wirft Exception andere Exception?
    Von Onkel Schuppig im Forum C/C++
    Antworten: 5
    Letzter Beitrag: 01.03.10, 13:45
  2. Exception
    Von krokojo im Forum Java
    Antworten: 5
    Letzter Beitrag: 15.08.09, 17:46
  3. Exception im Konstruktor
    Von Leyja im Forum Java
    Antworten: 1
    Letzter Beitrag: 16.12.07, 10:42
  4. Exception
    Von girl2005 im Forum Algorithmen & Datenstrukturen mit Java
    Antworten: 1
    Letzter Beitrag: 01.08.05, 14:28
  5. Exception bei RMI
    Von javaprogger1987 im Forum Java
    Antworten: 0
    Letzter Beitrag: 30.05.05, 18:29

Stichworte