Перейти к содержимому

Фото
- - - - -

JSF


  • Вы не можете создать новую тему
  • Please log in to reply
4 ответов в этой теме

#1 wheatus

wheatus
  • Пользователь
  • 14 сообщений

Отправлено 30 Январь 2008 - 20:53

на4ал изу4ать JSF и при выполнении первого примера возникли проблемя!
есть следующии код:

UserNumberBean.java
public class UserNumberBean {

	private Integer randomInt = null;
	private Integer userNumber = null;
	private String response = null;
	private boolean maximumSet = false;
	private boolean minimumSet = false;
	private long maximum = 0;
	private long minimum = 0;
	
	public UserNumberBean() {
		Random randomGR = new Random();
		randomInt = new Integer(randomGR.nextInt(10));
		System.out.println("Duke's number: " + randomInt);
	}
	
	public void setUserNumber(Integer userNumber) {
		this.userNumber = userNumber;
	}
	
	public Integer getUserNumber() {
		return userNumber;
	}
	
	public String getResponse() {
		if((userNumber != null) && (userNumber.compareTo(randomInt) == 0)) {
			return "Yay! You got it!";
		} else {
			return "Sorry, " + userNumber + " is incorrect.";
		}
	}
	
	public long getMaximum() {
		return maximum;
	}
	
	public void setMaximum(long maximum) {
		this.maximum = maximum;
		this.maximumSet = true;
	}
	
	public long getMinimum() {
		return minimum;
	}
	
	public void setMinimum(long minimum) {
		this.minimum = minimum;
		this.minimumSet = true;
	}
}

ApplicationMessages.properties
userNoConvert=The value you entered is not a number.

web.xml
<?xml version="1.0" encoding="UTF-8"?>

<web-app 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 web-app_2_5.xsd"
			version="2.5">
	
	<display-name>guessNumber</display-name>
	
	<servlet>
		<display-name>FacesServlet</display-name>
		<servlet-name>FacesServlet</servlet-name>
		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	
	<servlet-mapping>
		<servlet-name>FacesServlet</servlet-name>
		<url-pattern>/guess/*</url-pattern>
	</servlet-mapping>
	
	<taglib>
		<taglib-uri>/html</taglib-uri>
		<taglib-location>/WEB-INF/html_basic.tld</taglib-location>
	</taglib>
	
	<taglib>
		<taglib-uri>/core</taglib-uri>
		<taglib-location>/WEB-INF/jsf_core.tld</taglib-location>
	</taglib>

</web-app>

faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>

<faces-config 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_1_2.xsd"
			version="1.2">
			
	<application>
		<resource-bundle>
			<base-name>guessNumber.ApplicationMessages</base-name>
			<var>ErrMsg</var>
		</resource-bundle>
		<locale-config>
			<default-locale>en</default-locale>
			<supported-locale>de</supported-locale>
			<supported-locale>fr</supported-locale>
			<supported-locale>es</supported-locale>
		</locale-config>
	<application>
	
	<navigation-rule>
		<from-view-id>/greeting.jsp</from-view-id>
		<navigation-case>
			<from-outcome>success</from-outcome>
			<to-view-id>/response.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>
	
	<navigation-rule>
		<from-view-id>/response.jsp</from-view-id>
		<navigation-case>
			<from-outcome>success</from-outcome>
			<to-view-id>/greeting.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>
	
	<managed-bean>
		<managed-bean-name>UserNumberBean</managed-bean-name>
		<managed-bean-class>guessNumber.UserNumberBean</managed-bean-class>
		<managed-bean-scope>session</managed-bean-scope>
		<managed-property>
			<property-name>minimum</managed-property>
			<property-class>long</property-class>
			<value>0</value>
		</managed-property>
		<managed-property>
			<property-name>maximum</property-name>
			<property-class>long</property-class>
			<value>10</value>
		</managed-property>
	</managed-bean>
	
</faces-config>

index.jsp
<html>
	<head>
	</head>
	<body>
		<jsf:forward page="guess/greeting.jsp"/>
	</body>
</html>

greeting.jsp
<!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" xml:lang="en">
	
	<head>
		<title>Hello</title>
	</head>
	<%@ page contentType="applycation/xhtml+xml" %>
	<%@ taglib uri="html" prefix="h" %>
	<%@ taglib uri="core" prefix="f" %>
	<body bgcolor="white">
		<f:view>
			<h:form id="helloForm">
				<h2>Hi. My name is Duke. I'm thinking of a number from
				<h:outputText lang="en_US" value="#{UserNumberBean.minimum}"/> to
				<h:outputText value="#{UserNumberBean.maximum}"/>. Can you guess it?</h2>
				
				<h:graphicImage id="waveImg" url="/wave.med.gif" alt="Duke waving"/>
				<h:inputText id="userNo" label="User Number" value="#{UserNumberBean.userNumber}"
							converterMessage="#{ErrMsg.userNoConvert}">
					<f:validateLongRange minimum="#{UserNumberBean.minimum}" maximum="#{UserNumberBean}" />
				</h:inputText>
				<h:commandButton id="submit" action="sucess" value="Submit"/>
				<p>
					<h:message style="color: red; font-family: 'New Century Schoolbool', serif; font-style: oblique; 
								text-decoration: overline" id="error1" for="userNo"/>
				</p>
			</h:form>
		</f:view>		
	</body>
	
</html>

response.jsp
<html>
	<head>
		<title>Guess The Number</title>
	</head>
	<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
	<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
	<body bgcolor="white">
		<f:view>
			<h:form id="responseForm">
				<h:graphicImage id="waveImg" url="/wave.med.gif" alt="Duke waving"/>
				<h2><h:outputText id="result" value="#{UserNumberBean.response}"/></h2>
				<h:commandButton id="back" value="Back" action="sucess"/><p>
			</h:form>
		</f:view>
	</body>
</html>

где здесь у меня ощибка мозет быть?

в логе пищет следующее:


SEVERE: Servlet /hello threw load() exception
java.util.MissingResourceException: Bundle javax.faces.LogStrings not found for locale en_US by classloader gnu.gcj.runtime.SystemClassLoader{urls=[file:./,
file:/usr/local/tomcat/bin/bootstrap.jar], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.util.ResourceBundle.getBundle(libgcj.so.81)
at java.util.ResourceBundle.getBundle(libgcj.so.81)
at java.util.logging.Logger.<init>(libgcj.so.81)
at java.util.logging.Logger.getLogger(libgcj.so.81)
at javax.faces.webapp.FacesServlet.<clinit>(FacesServlet.java:95)
at java.lang.Class.initializeClass(libgcj.so.81)
at java.lang.Class.newInstance(libgcj.so.81)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1104)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4045)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4351)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at java.lang.reflect.Method.invoke(libgcj.so.81)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
  • 0

#2 Fors

Fors
  • Пользователь
  • 328 сообщений

Отправлено 30 Январь 2008 - 23:00

проблема не в ЖСФ, проблема в конфиге, он чего-то не может найти...
проверь либы

Сообщение изменено: Fors (30 Январь 2008 - 23:00 )

  • 0

#3 wheatus

wheatus
  • Пользователь
  • 14 сообщений

Отправлено 30 Январь 2008 - 23:14

в WEB-INF/lib есть следующие jar фаилы:

commons-beanutils.jar
commons-collections.jar
commons-degester.jar
commons-logging.jar
jsf-api.jar
jsf-impl.jar
jstl.jar
servlet-api.jar
standard.jar

4его еще не хватает?
  • 0

#4 Fors

Fors
  • Пользователь
  • 328 сообщений

Отправлено 31 Январь 2008 - 02:23

хрен его знает :)

ты gcj используешь с каким-то сокральным смыслом?
  • 0

#5 ParadoxL

ParadoxL
  • Постоялец
  • 4 756 сообщений
  • Откуда:Edinburg

Отправлено 31 Январь 2008 - 11:03

Переименуй
ApplicationMessages.properties

в
ApplicationMessages_en_US.properties
---- и ----
Убери нахрен вот эту бороду
<locale-config>
			<default-locale>en</default-locale>
			<supported-locale>de</supported-locale>
			<supported-locale>fr</supported-locale>
			<supported-locale>es</supported-locale>
		</locale-config>
Добавь эту ...
<locale-config>
			<default-locale>en_US</default-locale>
		</locale-config>

Сообщение изменено: Incubo (31 Январь 2008 - 11:07 )

  • 0
Victoria nulla est, Quam quae confessos animo quoque subjugat hostes ...
Верю в смерть после жизни, любовь после секса и в крем после бритья ...