2012-01-14 43 views
1

我使用JSF2.0 + Richfaces3.3.3在Netbeans6.9.1 + tomcat6.0.29JSF2.0 + RichFaces的3.3.3,JSP沒有發現錯誤

第一步創建簡單的項目:文件 - > NewProject +選擇JSF 2.0 +首選頁語言爲JSP

步驟2:JAR

JSF2.0 jsf-api.jar 
JSF2.0 jsf-impl.jar 
JSTL1.1 - Standard.jar 
JSTL1.1 - jstl.jar 
jsf-facelets.jar (Facelets 1. 1. 15) 
richfaces-api-3.3.3.Final.jar 
richfaces-ui-3.3.3.Final.jar 
richfaces-impl-jsf2-3.3. 3.Final.jar 
commons-beanutils-1.8.3.jar 
commons-collections-3.2. 1.jar 
commons-digester-2.0.jar 
commons-logging-1.1.1.jar and hth-api-0.4.0.jar 

web.xml文件

<?xml version="1.0" encoding="UTF-8"?> 
<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"> 

<context-param> 
    <param-name>javax.faces.PROJECT_STAGE</param-name> 
    <param-value>Production</param-value> 
</context-param> 
<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> 
    <param-name>javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER</param-name> 
    <param-value>true</param-value> 
</context-param> 

<context-param> 
    <param-name>org.richfaces.SKIN</param-name> 
    <param-value>blueSky</param-value> 
</context-param> 


<!--Configuration for Richfaces--> 
<filter> 
    <display-name>RichFaces Filter</display-name> 
    <filter-name>richfaces</filter-name> 
    <filter-class>org.ajax4jsf.Filter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>richfaces</filter-name> 
    <servlet-name>Faces Servlet</servlet-name> 
    <dispatcher>REQUEST</dispatcher> 
    <dispatcher>FORWARD</dispatcher> 
    <dispatcher>INCLUDE</dispatcher> 
</filter-mapping> 
<!--End of the configuration part for Richfaces--> 

<!--Configuration for Facelets--> 
<context-param> 
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name> 
    <param-value>.jsp</param-value> 
</context-param> 
<context-param> 
    <param-name>facelets.RECREATE_VALUE_EXPRESSION_ON_BUILD_BEFORE_RESTORE</param-name> 
    <param-value>false</param-value> 
</context-param> 
<context-param> 
    <param-name>facelets.VIEW_MAPPINGS</param-name> 
    <param-value>*.xhtml</param-value> 
</context-param> 
<context-param> 
    <param-name>facelets.SKIP_COMMENTS</param-name> 
    <param-value>true</param-value> 
</context-param> 
<!--End of the configuration part for Facelets--> 


<welcome-file-list> 
    <welcome-file>faces/welcomeJSF.jsp</welcome-file> 
</welcome-file-list> 
</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"> 

<managed-bean> 
    <description>Managed Bean for HomeContent</description> 
    <managed-bean-name>Sample1</managed-bean-name> 
    <managed-bean-class>com.test.Sample1</managed-bean-class> 
    <managed-bean-scope>session</managed-bean-scope> 
</managed-bean> 

</faces-config> 

了welcomeJSF.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> 
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> 
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%> 
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%> 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd"> 

<f:view> 
<html> 
<head> 
    <title>JSP Page</title> 
</head> 
    <body> 
     <h:form id="sampleForm" binding="#{Sample1.initForm}">    

     <a4j:outputPanel id="sampleOutputPanel"> 

      <h:outputText value="UserName : "/> 
      <h:inputText value="#{Sample1.username}"/> 

      <a4j:commandButton value="Test" 
          reRender="sampleOutputPanel,output" 
          action="#{Sample1.displayButtonAction}"/> 

     <h:outputText id="output" 
     value="Typed username : #{Sample1.displayValue}"/> 
    </a4j:outputPanel> 
</rich:panel> 
</h:form></body> </html></f:view> 

和Sample1.java

package com.test; 
import javax.faces.component.html.HtmlForm; 

public class Sample1 { 

    private HtmlForm initForm; 
    private String username; 
    private String displayValue; 

    public String displayButtonAction() { 
     displayValue = username; 
     return ""; 
    } 


    public HtmlForm getInitForm() { 
     username = ""; 
     return initForm; 
    } 


    public void setInitForm(HtmlForm initForm) { 
     this.initForm = initForm; 
    } 

    public String getUsername() { 
     return username; 
    } 

    public void setUsername(String username) { 
     this.username = username; 
    } 

    public String getDisplayValue() { 
     return displayValue; 
    } 

    public void setDisplayValue(String displayValue) { 
     this.displayValue = displayValue; 
    } 
} 

我的問題是:

部署後,我戰爭進入我的tomcat6.0.29,r取消我的申請。 當我點擊A4J:命令按鈕下面的錯誤發生

HTTP Status 404 - /.jsp not found 
type Status report 
message /.jsp not found 
description The requested resource (/.jsp not found) is not available. 
Apache Tomcat/6.0.29 

幫助我。在displayButtonAction方法

public String displayButtonAction() { 
    displayValue = username;   
    return null;  
} 

或返回類型爲Void

public void displayButtonAction() { 
     displayValue = username;   

    } 

回答

1

你行動的返回值被用來尋找新的視圖來重寫你的操作方法 預先感謝

+0

嗨Eelke,謝謝你的迴應。它爲我工作。我沒有在JSF1.2中爲a4j操作返回'null'值。爲什麼JSF2.0需要爲a4j:action返回空值。 Hele我。 – jackrobert 2012-01-16 01:41:36

+0

在2.0中添加了結果可以直接命名視圖。所以結果的處理略有改變。 – Eelke 2012-01-16 20:26:40

+0

謝謝埃爾克。謝謝你的解釋。還有一個疑問,我是新的(JSF 2.0 + Richfaces3.3.3)。在我上面的配置(web.xml,faces-config.xml)是正確的?或其他任何我想念的事? – jackrobert 2012-01-17 09:19:43

1

返回null顯示。可以通過在faces-config中找到匹配項,或者直接將其作爲頁面名稱使用,從而找到映射。當你返回一個空字符串時,最終只有.jsp作爲文件名。如果你想返回到同一頁面,返回null而不是空字符串。

+0

嗨Naveen,謝謝你的迴應。它爲我工作。但在現有的JSF1.2應用程序中,我沒有爲任何a4j操作返回「null」值。是否有任何理由在JSF2.0中返回'null'以用於a4j動作 – jackrobert 2012-01-16 01:39:44

+0

Implicit導航是從JSF2.0引入的,它將「結果」視爲頁面名稱,例如,導航到「page1.xhtml」,您必須把「結果」作爲「page1」。然而,JSF1.2沒有暗示導航,但用於通過在faces-config.xml中查找匹配(結果)來進行導航。看起來像return「」在JSF 1.2中被視爲null,但在JSF2.0中沒有被處理爲 – 2012-01-16 20:30:11

+0

好的..謝謝Naveen。我是新的JSF2.0 + richfaces3.3.3。在我上面的配置是否正確?否則任何其他配置錯過? – jackrobert 2012-01-17 09:23:20