JavaDabbaDoo.org -Tu comunidad Java parlante Imple. MVC - ICEfaces 1.8
Inicio | Cursos infosintesis.net liberados | Java EE | Baterķa de ejemplos componentes ICEfaces
Baterķa de ejemplos componentes ICEfaces - Campos de texto
Paso 1: Operativa

Vista/Modelo - notaGastos.jspx - Calcular el total de gastos con AJAX

Ahora vamos a enlazar los datos que introduce el usuario en los gastos de dietas y transporte con un backing bean realizando peticiones AJAX de forma transparente

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

<f:view xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ice="http://www.icesoft.com/icefaces/component">
 <html>  
 <head>
  <ice:outputStyle href="./resources/stylesheet.css" id="outputStyle1"/>
  <title>ICEfaces: Nota de gastos</title>
 </head>
 <body>
  <ice:form id="frmNotaGastos">
   <ice:outputText id="txtNotaGastos"
                    value="Nota de gastos"
                    style="left: 30px; top: 20px; position: absolute"
                    styleClass="iceOutTxtTituloCabecera"/>

   <ice:outputLabel id="lblDietas"
                    value="Dietas"
                    style="left: 30px; top: 70px; position: absolute" />
   <ice:inputText id="txfDietas"
                  partialSubmit="true"
                  style="left: 118px; top: 66px; position: absolute"
                  styleClass="iceInpTxtNumeros"
                  
value="#{notaGastosBackBean.dietas}">
    <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="es" />
   </ice:inputText>
   <ice:outputLabel value="€"
                    style="left: 204px; top: 70px; position: absolute"/>
   <ice:message for="txfDietas"
                style="left: 220px; top: 76px; position: absolute"/>

   <ice:outputLabel id="lblTransporte"
                    value="Transporte"
                    style="left:30px; top: 100px; position: absolute"/>
   <ice:inputText id="txfTransporte"
                  partialSubmit="true"
                  style="left: 118px; top: 96px; position: absolute"
                  styleClass="iceInpTxtNumeros"
                  value="#{notaGastosBackBean.transporte}">
    <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="es" />
   </ice:inputText>
   <ice:outputLabel value="€"
                  style="left: 204px; top: 100px; position: absolute"/>
   <ice:message for="txfTransporte"
                style="left: 220px; top: 106px; position: absolute"/>

   <ice:outputLabel id="lblTotalGastos"
                  value="Total gastos"
                  style="left:30px; top: 130px; position: absolute"
                  styleClass="iceOutLblNegrita"/>
   <ice:outputLabel id="lblValorTotalGastos"
                  style="left: 118px; top: 126px; position: absolute"
                  styleClass="iceOutLblNumerosTotales">
    <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="es" />
   </ice:outputLabel>
   <ice:outputLabel value="€"
                  style="left: 204px; top: 130px; position: absolute"/>
  </ice:form>
 </body>
 </html>
</f:view>

Nota: Recordemos que la variable de referencia notaGastosBackBean la obtiene el contenedor Web parseando el fichero de configuración JSF faces-config.xml. En el ejemplo que estamos siguiendo este es el contenido del mencionado fichero

<?xml version='1.0' encoding='UTF-8'?>

<faces-config version="1.2"
              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">
 <application>
  <message-bundle>literales.ErroresBundle</message-bundle>

  <locale-config>
   <default-locale>es</default-locale>
   </locale-config>
 </application>

 <managed-bean>
  <managed-bean-name>
notaGastosBackBean</managed-bean-name>
  <managed-bean-class>com.empresa.backbeans.NotaGastosBackBean</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
 </managed-bean>
</faces-config>

Ahora ya sólo nos queda invocar al método getTotalGastos() del backing bean NotaGastosBackBean desde la página notaGastos.jspx y así de esta forma podamos ver el total de gastos de nuestra nota de gastos.

Navegador - Calcular el total de los gastos con AJAX de forma transparente


Este es el código ampliado de la página JSPX notaGastos.jspx

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

<f:view xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ice="http://www.icesoft.com/icefaces/component">
 <html>  
 <head>
  <ice:outputStyle href="./resources/stylesheet.css" id="outputStyle1"/>
  <title>ICEfaces: Nota de gastos</title>
 </head>
 <body>
  <ice:form id="frmNotaGastos">
   <ice:outputText id="txtNotaGastos"
                    value="Nota de gastos"
                    style="left: 30px; top: 20px; position: absolute"
                    styleClass="iceOutTxtTituloCabecera"/>

   <ice:outputLabel id="lblDietas"
                    value="Dietas"
                    style="left: 30px; top: 70px; position: absolute" />
   <ice:inputText id="txfDietas"
                  partialSubmit="true"
                  style="left: 118px; top: 66px; position: absolute"
                  styleClass="iceInpTxtNumeros"
                  value="#{notaGastosBackBean.dietas}">
    <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="es" />
   </ice:inputText>
   <ice:outputLabel value="€"
                    style="left: 204px; top: 70px; position: absolute"/>
   <ice:message for="txfDietas"
                style="left: 220px; top: 76px; position: absolute"/>

   <ice:outputLabel id="lblTransporte"
                    value="Transporte"
                    style="left:30px; top: 100px; position: absolute"/>
   <ice:inputText id="txfTransporte"
                  partialSubmit="true"
                  style="left: 118px; top: 96px; position: absolute"
                  styleClass="iceInpTxtNumeros"
                  value="#{notaGastosBackBean.transporte}">
    <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="es" />
   </ice:inputText>
   <ice:outputLabel value="€"
                  style="left: 204px; top: 100px; position: absolute"/>
   <ice:message for="txfTransporte"
                style="left: 220px; top: 106px; position: absolute"/>

   <ice:outputLabel id="lblTotalGastos"
                  value="Total gastos"
                  style="left:30px; top: 130px; position: absolute"
                  styleClass="iceOutLblNegrita"/>
   <ice:outputLabel id="lblValorTotalGastos"
                  style="left: 118px; top: 126px; position: absolute"
                  styleClass="iceOutLblNumerosTotales"
                  value="#{notaGastosBackBean.totalGastos}">
    <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="es" />
   </ice:outputLabel>
   <ice:outputLabel value="€"
                  style="left: 204px; top: 130px; position: absolute"/>
  </ice:form>
 </body>
 </html>
</f:view>

Página anterior
Ignasi Pérez Valls
Infosintesis Solutions Group


Junio 2009
JavaDabbaDoo.org
Tu comunidad Java parlante. Cursos abiertos, tutoriales y mucho mucho más ...