CC68J APLICACIONES EMPRESARIALES CON JEE JSF. Profesores: Andrés Farías



Similar documents
Sample HP OO Web Application

Developing XML Solutions with JavaServer Pages Technology

JSF (Java Server Faces) Melih Sakarya

Simplify Your Web App Development Using the Spring MVC Framework

How To Understand The Architecture Of Java 2Ee, J2Ee, And J2E (Java) In A Wordpress Blog Post

Web Programming II JSP (Java Server Pages) ASP request processing. The Problem. The Problem. Enterprise Application Development using J2EE

JWIG Yet Another Framework for Maintainable and Secure Web Applications

Client-side Web Engineering From HTML to AJAX

Advanced Tornado TWENTYONE Advanced Tornado Accessing MySQL from Python LAB

CSc 230 Software System Engineering FINAL REPORT. Project Management System. Prof.: Doan Nguyen. Submitted By: Parita Shah Ajinkya Ladkhedkar

Página 1 de <xs:complextype name="signedinfotype"> <xs:element name="rsakeyvalue" type="tns:rsakeyvaluetype"/>

Building an Agile PLM Web Application with JDeveloper and Agile 93 Web Services

HTML Forms and CONTROLS

<Insert Picture Here> Betting Big on JavaServer Faces: Components, Tools, and Tricks

Hello World RESTful web service tutorial

İNTERNET TABANLI PROGRAMLAMA- 13.ders GRIDVIEW, DETAILSVIEW, ACCESSDATASOURCE NESNELERİ İLE BİLGİ GÖRÜNTÜLEME

Using Database Metadata and its Semantics to Generate Automatic and Dynamic Web Entry Forms

Web Programming with PHP 5. The right tool for the right job.

Further web design: HTML forms

Getting Started Guide. Version 1.8

Yandex.Widgets Quick start

COMPUTACIÓN ORIENTADA A SERVICIOS (PRÁCTICA) Dr. Mauricio Arroqui EXA-UNICEN

WIRIS quizzes web services Getting started with PHP and Java

JavaScript and Dreamweaver Examples

<Insert Picture Here>

CS412 Interactive Lab Creating a Simple Web Form

<Insert Picture Here> Oracle Mobile Enterprise Application Platform Overview

Direct Post Method (DPM) Developer Guide

Workshop for WebLogic introduces new tools in support of Java EE 5.0 standards. The support for Java EE5 includes the following technologies:

PRIMEFACES MOBILE USER S GUIDE

Guide to Integrate ADSelfService Plus with Outlook Web App

FORM-ORIENTED DATA ENTRY

Real SQL Programming 1

public void setusername(string username) { this.username = username; } public void setname(string name) { this.name = name; }

Fortigate SSL VPN 4 With PINsafe Installation Notes

Tutorial on Building a web Application with Jdeveloper using EJB, JPA and Java Server Faces By Phaninder Surapaneni

Application Security

Script Handbook for Interactive Scientific Website Building

Configuring iplanet 6.0 Web Server For SSL and non-ssl Redirect

Defeating XSS and XSRF with JSF Frameworks

JavaScript: Arrays Pearson Education, Inc. All rights reserved.

HTML Form Widgets. Review: HTML Forms. Review: CGI Programs

Java Server Pages and Java Beans

Introduction to XHTML. 2010, Robert K. Moniot 1

Mobile Solutions for Data Collection. Sarah Croft and Laura Pierik

Fortigate SSL VPN 3.x With PINsafe Installation Notes

Website Login Integration

Internet Technologies

In this chapter, we lay the foundation for all our further discussions. We start

Oracle JDeveloper 10g for Forms & PL/SQL

White Paper. JavaServer Faces, Graphical Components from Theory to Practice

Concordion. Concordion. Tomo Popovic, tp0x45 [at] gmail.com

Working with forms in PHP

How to make a good Software Requirement Specification(SRS)

HTML Tables. IT 3203 Introduction to Web Development

Web Development and Core Java Lab Manual V th Semester

Web Application Development Using Borland JBuilder 8 WebLogic Edition

BAPI. Business Application Programming Interface. Compiled by Y R Nagesh 1

ANGULAR JS SOFTWARE ENGINEERING FOR WEB SERVICES HASAN FAIZAL K APRIL,2014

Portals, Portlets & Liferay Platform

Securing JSF Applications Against the OWASP Top Ten. The OWASP Foundation JSF One Rich Web Experience Sep 2008

Chapter 22 How to send and access other web sites

SQL Injection for newbie

Mini Project Report ONLINE SHOPPING SYSTEM

Complete Java Web Development

WEB PROGRAMMING LAB (Common to CSE & IT)

ACI Commerce Gateway Hosted Payment Page Guide

Developing Java Web Applications with Jakarta Struts Framework

USERS MANUAL IN.TRA.NET PROJECT

The Google Web Toolkit (GWT): Declarative Layout with UiBinder Basics

Development. with NetBeans 5.0. A Quick Start in Basic Web and Struts Applications. Geertjan Wielenga

AV-002: Professional Web Component Development with Java

DIPLOMADO DE JAVA - OCA

Manejo Basico del Servidor de Aplicaciones WebSphere Application Server 6.0

JavaServer Faces 2.0: The Complete Reference

Java 2 Platform, Enterprise Edition (J2EE) Bruno Souza Java Technologist, Sun Microsystems, Inc.

InternetVista Web scenario documentation

Dictionary (catálogo)

Multi Factor Authentication API

Sales Management Main Features

Cover Page. Dynamic Server Pages Guide 10g Release 3 ( ) March 2007

PHP Authentication Schemes

Xtreeme Search Engine Studio Help Xtreeme

Rapid Application Development. and Application Generation Tools. Walter Knesel

Web-based Hybrid Mobile Apps: State of the Practice and Research Opportunities

JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

OpenMRS Open Medical Records System

Programming on the Web(CSC309F) Tutorial: Servlets && Tomcat TA:Wael Aboelsaadat

Transcription:

CC68J APLICACIONES EMPRESARIALES CON JEE JSF Profesores: Andrés Farías

Objetivos: aprender a

REVISITANDO EL PATRÓN MVC

INTRODUCCIÓN A JSF

Java Server Faces Introducción <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

Java Server Faces Introducción

En qué tecnologías se basa? Introducción

CONCEPTOS CENTRALES DE JSF

Los conceptos clave Resumen

1. Componentes de UI General <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

1. Componentes de UI Ejemplos <h:commandbutton id= siguiente value= #{msg.buttonheader} action= sigpagina /> <h:inputtextarea id= textarea rows= 4 cols= 7 value= texto />

1. Componentes de UI De JSF a HTML (1/2) Enter address: <h:message style="color: red" for="useraddress" /> <h:inputtext id="useraddress" value="#{jsfexample.address}" required="true"/> <h:commandbutton action="save" value="save"/>

1. Componentes de UI De JSF a HTML (2/2) Enter address: <span style="color: red"> Validation Error: Value is required. </span> <input id="jsftags:useraddress" type="text" name="jsftags:useraddress" value="" /> <input type="submit" name="jsftags:_id1" value="save" />

2. Eventos General

2. Eventos Ejemplo: value-change event <h:inputtext valuechangelistener= #{myform.processvaluechanged} /> public void processvaluechanged(valuechangeevent event){ HtmlInputText sender = (HtmlInputText)event.getComponent(); sender.setreadonly(true); changepanel.setrendered(true); }

2. Eventos Ejemplo: action event <h:commandbutton id="redisplaycommand" type="submit" value="redisplay actionlistener="#{myform.doit} /> public void doit(actionevent event){ HtmlCommandButton button = (HtmlCommandButton)event.getComponent(); button.setvalue("it's done!"); }

3. Beans Manejados Managed Beans - General

3. Beans Manejados Ejemplo de declaración (faces-config.xml) <managed-bean> <managed-bean-name>hellobean</managed-bean-name> <managed-bean-class> com.virtua.jsf.sample.hello.hellobean </managed-bean-class> <managed-bean-scope> session </managed-bean-scope> </managed-bean>

3. Beans Manejados Ejemplo de uso <h:outputtext id= output value= #{hellobean.numcontrols} /> El uso de EL es similar a JSP.

4. Validadores General validator

4. Validadores General <h:inputtext id="usernumber value="#{numberbean.usernumber} required= true /> <h:inputtext> <f:validatelength minimum="2" maximum="10"/> </h:inputtext>

5. Internacionalización y localización General

5. Internacionalización y localización Ejemplo - declaración en faces-config.xml <application> <locale-config> <default-locale>en</default-locale> <supported-locale>en</supported-locale> <supported-locale>en_us</supported-locale> <supported-locale>es_es</supported-locale> </locale-config> <message-bundle>custommessages</message-bundle> </application>

5. Internacionalización y localización Ejemplo - Resource Boundles y uso <f:loadbundle basename="localizationresources" var="bundle"/> LocalizationResources_en.properties halloween=every day is like Halloween. numberofvisits=you have visited us {0} time(s), {1}. Rock on! togglelocale=translate to Spanish helloimage=../images/hello.gif <h:outputtext value="#{bundle.halloween}"/>

6. Conversores General

6. Conversores General <f:converter> converter Conversores no predefinidos

6. Conversores Ejemplo: Conversor predefinido <h:outputtext value="#{user.dateofbirth}"> <f:convertdatetime type="date" datestyle="short"/> </h:outputtext> 03/18/06 18/03/06

7. Navegación General

7. Navegación Ejemplo de declaración (faces-config.xml) <navigation-rule> <from-view-id>/login.jsp</from-view-id> <navigation-case> <from-outcome>success</from-outcome> <to-view-id>/mainmenu.jsp</to-view-id> </navigation-case> <navigation-case> <from-outcome>failure</from-outcome> <to-view-id>/login.jsp</to-view-id> </navigation-case> </navigation-rule> Página destino Página origen acción

UN PEQUEÑO EJEMPLO

Que ofrece workshop? Un ejemplo sencillo

Login con WebLogic Un ejemplo sencillo Presentación MVC: JSF Lógica de Negocio Login.jsp LoginBean.java Login.java welcome.jsp

La receta failure success

Creación del proyecto Eligiendo las librerías

Creando el bean LoginBean package cl.uchile.cc68j.login; public class LoginBean { private String username; private String password; public String login(string username, String password) { if (username.equals("afarias") && password.equals("password")) return "sucess"; else return null; } public String getpassword() { return password; } public void setpassword(string password) { this.password = password; } public String getusername() { return username; } } public void setusername(string username) { this.username = username; }

Beans administrados Modificando el faces-config.xml <?xml version="1.0" encoding="utf-8"?> <faces-config> <application> <message-bundle>resources.application</message-bundle> <locale-config><default-locale>en</default-locale></localeconfig> </application> <managed-bean> <managed-bean-name>login</managed-bean-name> <managed-bean-class>cl.uchile.cc68j.login.loginbean</managedbean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> </faces-config>

Creando la vista Login.jsp <%@ page language="java" contenttype="text/html; charset=iso-8859-1" pageencoding="iso-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/tr/html4/loose.dtd"> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <f:loadbundle basename="resources.application" var="bundle"/> <f:view> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>insert title here</title> </head> <body> <table border="1" cellpadding="0" width="800"> <tr> <td></td> </tr> <tr> <td> <h:messages globalonly="true" layout="table"/> <h:form id="loginform"> <h:panelgrid columns="3"> <f:facet name="header"> <h:outputtext value="#{bundle['login.title']}"/> </f:facet> <h:outputtext value="#{bundle['login.user']}"/> <h:inputtext id="username" value="#{login.username}" required="true"> <f:validatelength minimum="6" maximum="10"/> </h:inputtext> <h:message for="username"/> <h:outputtext value="password:"/> <h:inputsecret id="password" value="#{login.password}" required="true"> <f:validatelength minimum="6" maximum="10"/> </h:inputsecret> <h:message for="password"/> </h:panelgrid> <h:commandbutton action="#{login.login}" value="login"/> </h:form></td></tr> </table></body></html> </f:view>

Navegación Modificando el faces-config.xml <?xml version="1.0" encoding="utf-8"?> <faces-config> <application> <message-bundle>resources.application</message-bundle> <locale-config><default-locale>en</default-locale></localeconfig> </application>... <navigation-rule> <from-view-id>/pages/login.jsp</from-view-id> <navigation-case> <from-outcome>success</from-outcome> <to-view-id>/pages/welcome.jsp</to-view-id> </navigation-case> </navigation-rule> </faces-config>

TEORÍA VS. PRÁCTICE

Teoría vs Práctica En teoría

En la práctica

JSF: ESTRUCTURA Y CÓDIGO

JSF Estructura Template (jsp) faces-config (xml) Backing Bean (java) Wrapper (java) Logic Layer (rest of app) model (java)

JSF templates

Ejemplo de template <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <f:view> <html><head><title>items</title></head><body> <h:form id="items"> <h:datatable id="itemlist value="#{jsfbean.allitems} var="entry"> <h:column> <f:facet name="header"> <h:outputtext value=""/> </f:facet> <h:selectbooleancheckbox id="itemselect" value="#{entry.selected} rendered="#{entry.candelete}"/> <h:outputtext value="" rendered="#{not entry.candelete}"/> </h:column> </h:form> </body></html> </f:view>

faces-config.xml

Ejemplo de faces-config <faces-config> <navigation-rule> <from-view-id>/jsf/jsfitems.jsp</from-view-id> <navigation-case> <from-outcome>newitem</from-outcome> <to-view-id>/jsf/jsfadditem.jsp</to-view-id> </navigation-case> <navigation-case> <from-outcome>*</from-outcome> <to-view-id>/jsf/jsfitems.jsp</to-view-id> </navigation-case> </navigation-rule> <managed-bean> <managed-bean-name>jsfbean</managed-bean-name> <managed-bean-class>org.example.jsf.jsfbean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> <managed-property> <property-name>logic</property-name> <value>#{somelogicbean}</value> </managed-property> </managed-bean> </faces-config>

JSF backing beans

Ejemplo de backing bean public class JsfBean { private DataModel itemsmodel; private JsfItemWrapper currentitem = null;... private JsfLogic logic; public void setlogic(jsflogic logic) { this.logic = logic; }... public DataModel getallitems() { List wrappeditems = new ArrayList(); List items = logic.getallvisibleitems(logic.getcurrentsiteid()); for (Iterator iter = items.iterator(); iter.hasnext(); ) { JsfItemWrapper wrapper = new JsfItemWrapper((Item) iter.next()); wrappeditems.add(wrapper); } itemsmodel = new ListDataModel(wrappedItems); return itemsmodel; }... public String processactionlist() { return "listitems"; } }

JSF wrapper bean

Sample wrapper bean public class JsfItemWrapper { private Item item; // is this item selected by the user private boolean isselected; public JsfItemWrapper(Item item) { this.item = item; } public Item getitem() { return item; } public void setitem(item item) { this.item = item; } public boolean isselected() { return isselected; } } public void setselected(boolean isselected) { this.isselected = isselected; }

Web app basics 4 cosas necesarias en un webapp

Imprimir texto dinámico <h:outputtext value="#{jsfappbean.currentitem.title}"/> <h:outputtext value="#{msgs.jsfapp_text}"/> h:outputtext h:outputlabel h:outputformat

Estructuras de Loop <h:datatable id="itemlist value="#{jsfappbean.allitems} var="entry"> <h:column> <f:facet name="header"> <h:outputtext value="#{msgs.jsfapp_text}"/> </f:facet> <h:outputtext value="#{entry.item.title}"/> </h:column> <h:column> <f:facet name="header"> <h:outputtext value="#{msgs.jsfapp_hidden}"/> </f:facet> <h:selectbooleancheckbox id="itemhidden" value="#{entry.item.hidden} disabled="true" /> </h:column> </h:datatable> h:datatable h:column h:panelgrid

Rendering opcional <h:outputtext value="#{entry.item.title} rendered="#{not entry.candelete}"/> <h:commandlink id="updatelink" action="#{jsfappbean.processactionupdate}" rendered="#{entry.candelete}"> <h:outputtext value="#{entry.item.title}"/> </h:commandlink> h: rendered not

Gatillar acciones <h:commandbutton value="#{msgs.jsfapp_new}" action="#{jsfappbean.processactionnew}" /> public String processactionnew() { } currentitem = null; itemtext = TEXT_DEFAULT; itemhidden = HIDDEN_DEFAULT; return "newitem"; h:commandbutton h:commandlink

JSF EN LA PRÁCTICA

La experiencia con JSF

Revisitando la estructura JSF Template (jsp) faces-config (xml) Wrapper (java) model (java) Backing Bean (java) Logic Layer (rest of app)

Apache MyFaces

Oracle ADF faces

Otros faces

Links