大家好:
又來請教問題了
我在練習JSF,
平台:netbean
但我發現專案建好後,沒有faces-config.xml
所以我就自己建一個
但建了之後我的網頁textbox就被吃掉了....
在run的時候也沒錯誤訊息,所以不知道如何解決....
請各位指教,感謝
以下是我的專案:
https://drive.google.com/open?id=0B0SyQeRkRiM4U0dEMGVKMmJ6X1U
用回答來診斷比較容易閱讀。
先問一下你的web.xml怎麼設定的?
你好:
web.xml我都是讓他自動產生的,沒有去改
現在textbox出來了
但打字後會出現
web.xml設定會跟JSF的Servlet是否要去剖析你的View有關阿。
另外,faces-config.xml裡面的類別的mapping要對阿,我看到你寫com.jj.a
但是你程式中是com.jj.t3.a
,所以伺服器找不到user這個bean。
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>
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!");
}
}
那faces-config.xml呢?現在改成怎樣?
<?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>
大概就是改成這樣
com.jj.t3.user2
啦...managed-bean-class要寫完整的class name。
fillano
謝謝指正,我有改了
但變成....
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!");
}
}
一直卡關,快崩饋啦....