mes method bean ne fonctionne pas
voila mon simple code
hello-world.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 contentType="text/html" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="html" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="core" %>
<core:view>
<html:form>
<BR/>
<html:outputText value="Nom : #{accountDatas.customer.name}"/>
<BR/>
<html:outputText value="Numéro de compte : #{accountDatas.number}"/>
<BR/>
<html:outputText value="Total : #{accountDatas.total}"/>
<BR/>
<html:outputText value="Montant :"/>
<html:inputText value="#{accountDatas.amount}"/>
<html:commandButton value="Retirer le montant" action="#{accountDatas.retrieveAmount}"/>
<html:commandButton value="Ajouter le montant" action="#{accountDatas.addAmount}"/>
<BR/> <BR/>
<html:commandButton value="Valider" action="#{accountDatas.validate}"/>
<BR/>
</html:form>
</core:view> |
faces-config.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| <?xml version="1.0"?> <!--
Copyright 2003 Sun Microsystems, Inc. All rights reserved. SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. -->
<!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> <application>
<locale-config> <default-locale>fr</default-locale> </locale-config> </application>
<managed-bean>
<managed-bean-name>accountDatas</managed-bean-name>
<managed-bean-class>faces.AccountDatas</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 27 28 29 30
| <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<servlet>
<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>/faces/*</url-pattern>
</servlet-mapping>
<servlet>
<description>Added by JBuilder to compile JSPs with debug info</description>
<servlet-name>debugjsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>classdebuginfo</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>debugjsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
</web-app> |
AccountDatas.java
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
| package faces;
public class AccountDatas {
private long number = 20050000;
private float total = (float) 100.0;
private float amount;
private faces.Customer customer=new Customer();
public AccountDatas() { }
public long getNumber(){System.out.println("1"); return this.number; }
public void setNumber(long value){ System.out.println("2"); this.number = value; }
public float getAmount(){System.out.println("5");return this.amount; }
public void setAmount(long value){ System.out.println("6"); this.amount = value; }
public float getTotal(){System.out.println("3"); return this.total; }
public Customer getCustomer(){System.out.println("7"); return this.customer; }
public void setCustomer(Customer value){ System.out.println("8"); this.customer = value; }
public void addAmount(){ this.total = this.total + this.amount; this.amount = (float)0.0; System.out.println("9"); }
public void retrieveAmount(){ System.out.println("10"); this.total = this.total - this.amount; this.amount = (float)0.0; }
protected boolean checkAccount(){ System.out.println("11"); if(this.total < 0.0 ){ return false; } else return true; }
public String validate(){ System.out.println("12"); if(checkAccount()){ return "AccountDatasOK"; } else { return "AccountDatasError"; }}
} |
Customer.java
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
| package faces;
public class Customer {
private String name = "DURAND";
private String forname = "Paul";
public Customer() {
}
public Customer(String name, String forname) {this.name=name; this.forname=forname;System.out.println("13"); }
public String getName(){System.out.println("14");
return this.name; }
public void setName(String value){ System.out.println("15");
this.name = value; }
public String getForname(){System.out.println("16");
return this.forname; }
public void setForname(String value){ System.out.println("17");
this.forname = value; }
} |
a l'exaction les methode set get fonctionne mais addAmount et retrieveAmount ne fonctionne pas ,avec le test d'affichage je reçoit toujours après un click sur une bouttan
7
14
1
3
danc l'application n'accede pas au methode addAmount ou retrieveAmount
svp aidez moi à résoudre ce problème