iT邦幫忙

0

JSF faces-config.xml不見了

大家好:
又來請教問題了
我在練習JSF,
平台:netbean
但我發現專案建好後,沒有faces-config.xml
所以我就自己建一個
http://ithelp.ithome.com.tw/upload/images/20170621/20102983Y3XsLt4f75.jpg
但建了之後我的網頁textbox就被吃掉了....
http://ithelp.ithome.com.tw/upload/images/20170621/20102983AKAMhMKt2w.jpg
在run的時候也沒錯誤訊息,所以不知道如何解決....
請各位指教,感謝
以下是我的專案:
https://drive.google.com/open?id=0B0SyQeRkRiM4U0dEMGVKMmJ6X1U

fillano iT邦超人 1 級 ‧ 2017-06-21 18:05:40 檢舉
tomcat的log有資訊嗎?有可能你使用的tag沒有被處理,結果沒有render成html,所以顯示不出來,這樣的話就是設定的問題。
神威 iT邦研究生 4 級 ‧ 2017-06-22 08:16:23 檢舉
tomcat log
22-Jun-2017 08:11:01.719 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath
22-Jun-2017 08:11:01.750 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext
22-Jun-2017 08:11:03.388 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Initializing Spring FrameworkServlet 'dispatcher'
22-Jun-2017 08:11:04.917 INFO [http-nio-8084-exec-6] org.apache.catalina.core.ApplicationContext.log Destroying Spring FrameworkServlet 'dispatcher'
22-Jun-2017 08:11:04.948 INFO [http-nio-8084-exec-6] org.apache.catalina.core.ApplicationContext.log Closing Spring root WebApplicationContext
22-Jun-2017 08:11:09.332 INFO [http-nio-8084-exec-3] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath
22-Jun-2017 08:11:09.379 INFO [http-nio-8084-exec-3] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext
22-Jun-2017 08:11:10.549 INFO [http-nio-8084-exec-3] org.apache.catalina.core.ApplicationContext.log Initializing Spring FrameworkServlet 'dispatcher'
22-Jun-2017 08:11:36.973 INFO [http-nio-8084-exec-12] org.apache.catalina.core.ApplicationContext.log Destroying Spring FrameworkServlet 'dispatcher'
22-Jun-2017 08:11:36.988 INFO [http-nio-8084-exec-12] org.apache.catalina.core.ApplicationContext.log Closing Spring root WebApplicationContext
22-Jun-2017 08:14:04.896 INFO [http-nio-8084-exec-17] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath
22-Jun-2017 08:14:04.943 INFO [http-nio-8084-exec-17] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext
22-Jun-2017 08:14:06.087 INFO [http-nio-8084-exec-17] org.apache.catalina.core.ApplicationContext.log Initializing Spring FrameworkServlet 'dispatcher'
22-Jun-2017 08:14:34.410 INFO [localhost-startStop-2] org.apache.catalina.core.ApplicationContext.log Destroying Spring FrameworkServlet 'dispatcher'
22-Jun-2017 08:14:34.426 INFO [localhost-startStop-2] org.apache.catalina.core.ApplicationContext.log Closing Spring root WebApplicationContext
22-Jun-2017 08:14:53.848 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath
22-Jun-2017 08:14:53.879 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext
22-Jun-2017 08:14:55.470 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Initializing Spring FrameworkServlet 'dispatcher'

感覺都很正常...
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
fillano
iT邦超人 1 級 ‧ 2017-06-22 09:55:23
最佳解答

用回答來診斷比較容易閱讀。

先問一下你的web.xml怎麼設定的?

看更多先前的回應...收起先前的回應...
神威 iT邦研究生 4 級 ‧ 2017-06-22 10:06:12 檢舉

你好:
web.xml我都是讓他自動產生的,沒有去改
http://ithelp.ithome.com.tw/upload/images/20170622/20102983oJ547J4Z1W.jpg
現在textbox出來了
但打字後會出現
http://ithelp.ithome.com.tw/upload/images/20170622/20102983dU8nssNOSS.jpg

fillano iT邦超人 1 級 ‧ 2017-06-22 11:10:46 檢舉

web.xml設定會跟JSF的Servlet是否要去剖析你的View有關阿。

另外,faces-config.xml裡面的類別的mapping要對阿,我看到你寫com.jj.a但是你程式中是com.jj.t3.a,所以伺服器找不到user這個bean。

神威 iT邦研究生 4 級 ‧ 2017-06-22 14:17:01 檢舉

web.xml內容

 <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <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>dispatcher</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
神威 iT邦研究生 4 級 ‧ 2017-06-22 14:19:00 檢舉

java內容(我有改過,跟原本專案的不一樣)

package com.jj.t3;
import javax.inject.Named;
import javax.enterprise.context.Dependent;

@Named(value = "user2")
@Dependent
public class user2 {
private String userName2="1111";

    public String getUserName2() {
     return userName2;
    }

    public void setUserName2(String userName2) {
	this.userName2 = userName2;
    }
   
    public user2() {
	System.out.println("123456789!");
    }
    
}
fillano iT邦超人 1 級 ‧ 2017-06-22 17:49:27 檢舉

那faces-config.xml呢?現在改成怎樣?

神威 iT邦研究生 4 級 ‧ 2017-06-22 17:59:19 檢舉
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC
 "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
 "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">

<faces-config>
   <navigation-rule>
        <from-view-id>/t3/index.xhtml</from-view-id>
        <navigation-case>
            <from-outcome>login</from-outcome>
            <to-view-id>/t3/b.xhtml</to-view-id>
        </navigation-case>
    </navigation-rule>
       
       
    <managed-bean>
        <managed-bean-name>user2</managed-bean-name>
         <managed-bean-class>
             com.jj.t3
         </managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
</faces-config>

大概就是改成這樣

神威 iT邦研究生 4 級 ‧ 2017-06-22 18:01:56 檢舉
fillano iT邦超人 1 級 ‧ 2017-06-23 09:21:51 檢舉

com.jj.t3.user2啦...managed-bean-class要寫完整的class name。

神威 iT邦研究生 4 級 ‧ 2017-06-23 09:58:54 檢舉

fillano
謝謝指正,我有改了
但變成....
http://ithelp.ithome.com.tw/upload/images/20170623/20102983SoF38xOsJH.jpg
index.xhtml

 <h:body>
        Hello from Facelets
        <br />
        #{user2.userName2}
        <h:form>    
            <h:inputText value="#{user2.userName2}"/>
            <h:commandButton value="send" action="login"/>
         </h:form>  
    </h:body>

user2.java

package com.jj.t3;
import javax.inject.Named;
import javax.enterprise.context.Dependent;

@Named(value = "user2")
@Dependent
public class user2 {
private String userName2="1111";
    public String getUserName2() {
     return userName2;
    }

    public void setUserName2(String userName2) {
	this.userName2 = userName2;
    }
   
    public user2() {
	System.out.println("123456789!");
    }
    
}

一直卡關,快崩饋啦....

神威 iT邦研究生 4 級 ‧ 2017-06-23 10:01:48 檢舉

對了,請問我的
session
需不需要改成Dependent啊?

神威 iT邦研究生 4 級 ‧ 2017-06-23 15:32:42 檢舉

努力好久,他終於顯示出東西了
我把faces-config.xml刪了,再改.java就行了~~
http://ithelp.ithome.com.tw/upload/images/20170623/20102983GatcU095iS.jpg
但是不知為何她不能轉跳.....
我希望我按send會跳到另一個頁面....

神威 iT邦研究生 4 級 ‧ 2017-06-26 18:13:04 檢舉

終於OK了

我要發表回答

立即登入回答