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 - notaGastos.jspx - Convertir los valores de los campos de texto a numéricos

Cuando un usuario introduce por ejemplo la cantidad 246 en el campo de texto de dietas, y seguidamente pierde el foco de este campo de texto el valor que se va a mostrar es 246,00 con dos números decimales precedidos de una coma.

En esta imagen podemos observar que introducimos 246 € en concepto de dietas

Navegador - Campo de texto | <ice:inputText>

y al perder el foco esta cantidad se convierte en 246,00

Navegador - Campo de texto | <f:convertNumber/>

Este es el código de la página JSPX notaGastos.jspx con componentes ICEfaces

<?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">
    <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="es" />
   </ice:inputText>
   <ice:outputLabel value="€"
                    style="left: 204px; top: 70px; position: absolute"/>

   <ice:outputLabel id="lblTransporte"
                    value="Transporte"
                    style="left:30px; top: 100px; position: absolute"/>
   <ice:inputText id="txfTransporte"
                  style="left: 118px; top: 96px; position: absolute"
                  styleClass="iceInpTxtNumeros"/>
   <ice:outputLabel value="€"
                  style="left: 204px; top: 100px; 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"/>
   <ice:outputLabel value="€"
                  style="left: 204px; top: 130px; position: absolute"/>
  </ice:form>
 </body>
 </html>
</f:view>

Ahora vamos a tratar el campo de texto Transporte de la misma forma que el campo de texto Dietas, es decir realizando una petición AJAX cuando se pierde el foco. También tendremos en cuenta que el campo de texto Transporte y la etiqueta Total gastos tienen valor es como localización y los números tienene que tener dos decimales.

Navegador - Campo de texto | <f:convertNumber/>


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">
    <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="es" />
   </ice:inputText>
   <ice:outputLabel value="€"
                    style="left: 204px; top: 70px; 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">
    <f:convertNumber maxFractionDigits="2" minFractionDigits="2" locale="es" />
   </ice:inputText>
   <ice:outputLabel value="€"
                  style="left: 204px; top: 100px; 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>

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 ...