introduccion struts2

Post on 22-Dec-2014

3.734 Views

Category:

Technology

4 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

4ta. Reunión SpringHispano & JavaMexico

Struts 2Struts 2

Agenda

• Introducción Framework

• Características nuevas

• Configuración

• Plugin Spring

Introducción Framework

Caracteristicas Struts2

Basado en POJO’s Conversion de Datos Inyección de Dependencias Validaciones Flexible con etiquetas para Ajax Soporte OGNL Testability

Configuración XMLo Ahora la configuración se basa en paquetes donde cada paquete

contiene los actions.

o Permite heredar configuraciones de otro paquete.

<struts>

<constant name="struts.objectFactory" value="spring" />

<package name="defaulf" namespace="/" extends="struts-default">

<action name="index" class="mx.com.mexico.IndexAction">

<result>/jsp/index.jsp</result>

</action>

</package>

</struts>

Como creo un Action?o Los actions se basan en POJO’s.

public class HelloWorldAction extends ActionSupport {

private Date now;

private String name;

@RequiredFieldValidator ( message = "Por favor ingresa la fecha” )

public void setDateNow( Date now ) { this.now = now; }

public Date getDateNow() { return now; }

@RequiredStringValidator ( message = "Por favor ingresa el nombre", trim = true )

public void setName(String name) { this.name = name; }

public String getName() { return this.name; }

public String execute() throws Exception {

return SUCCESS;

}

}

Conversion datoso Facilita el manejo de tipo de datos como los Date, Time

@TypeConversion(converter = ”org.struts2.DateConverter")

public Date getDateNow() { return now; }

public class DateConverter extends StrutsTypeConverter {

public String convertToString(Map context, Object o) {

if (o instanceof Date) {

return sdf.format((Date)o);

}

return "";

}

Inyeccion de Dependencias

o Plugin Spring: Framework OpenSource de IoC y más que eso!

o Plugin Plexus

o Google Guice

Elementos basicos

o ActionSupport: Clase para manejo de los request

o Result

o default

o redirect-action

o Redirect

o Freemarker

o Velocity

o stream

o Interceptor

o validationWorkflowStack

o fileUploadStack

o paramPrepareParamsStack

o etc…

Configuracion Wildcard

o Esta forma de configuracion es muy flexible para invocar diferentes metodos de nuestros actions

<action name="*Telefono" method="{1}" class="mx.com.mexico.actions.telefono.TelefonoAction">

<result>/jsp/telefono/{1}Telefono.jsp</result>

<result name="exito" type="redirect-action">allTelefono</result>

<result name="input">/jsp/telefono/allTelefono.jsp</result>

</action>

public String edit() throws Exception {telefono = telefonoService.find( id );return SUCCESS;

}

public String all() throws Exception {telefonos = telefonoService.findAll();return SUCCESS;

}

Soporte para OGNL (Object Graph Navigation Language)

Una tecnologia para el manejo de propiedades en los objetos Java

Ejemplos:

<s:property value="#session.mySessionPropKey"/>

<s:property value="#session['mySessionPropKey']"/>

<s:property value="#request['myRequestPropKey']"/>

<s:property value="address.postcode"/>

<s:property value=“@com.static.Constants@getRoles()” />

<s:property value=“@com.static.Constants@USER_NAME” />

<s:if test=” 'foo' in {'foo','bar'}”>

<s:if test=“ listaElementos.size > 0 ” >

Que mas hay??

Soporte para:

o JasperReports

o JFreeChart

o JSF

o Struts1

o Portlets

o REST

o Tiles

o TestNG

Caracteristicas Struts2 version 2.1

Anotaciones en lugar de configuración XML

Convensión sobre configuración Mas diversidad soporte para Ajax

( Dojo, YUI, Ajax file Upload, GWT, JSON )

Recursos

o Struts: http://struts.apache.org/2.1.6/

o http://struts.apache.org/2.1.6/docs/guides.htm

o http://www.infoq.com/minibooks/starting-struts2l

o http://www.javaworld.com/javaworld/jw-10-2008/jw-10-struts2validation.html

o http://www.struts2.net/

Preguntas??

GRACIAS….

Esten pendientes de

www.springhispano.org

www.javamexico.org

http://www.planetajava.org/

top related