4ta. Reunión SpringHispano & JavaMexico Struts 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 XML Ahora la configuración se basa en paquetes donde cada paquete contiene los actions. Permite heredar configuraciones de otro paquete. <struts> <constant name= &quot;struts.objectFactory&quot; value=&quot;spring&quot; /> <package name= &quot;defaulf&quot; namespace=&quot;/&quot; extends=&quot;struts-default&quot;> <action name= &quot;index&quot; class=&quot;mx.com.mexico.IndexAction&quot;> <result>/jsp/index.jsp</result> </action> </package> </struts>
Como creo un Action? Los actions se basan en POJO’s. public class HelloWorldAction extends ActionSupport { private Date now; private String name; @RequiredFieldValidator ( message = &quot;Por favor ingresa la fecha” ) public void setDateNow( Date now ) { this.now = now; } public Date getDateNow() { return now; } @RequiredStringValidator ( message = &quot;Por favor ingresa el nombre&quot;, trim =  true ) public void setName(String name) { this.name = name; } public String getName() { return this.name; } public String execute() throws Exception { return  SUCCESS; } }
Conversion datos Facilita el manejo de tipo de datos como los Date, Time @TypeConversion(converter = ”org.struts2.DateConverter&quot;)  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 &quot;&quot;; }
Inyeccion de Dependencias Plugin Spring: Framework OpenSource de IoC y más que eso! Plugin Plexus Google Guice
Elementos basicos ActionSupport : Clase para manejo de los request Result default redirect-action Redirect Freemarker Velocity stream Interceptor validationWorkflowStack fileUploadStack paramPrepareParamsStack etc…
Configuracion Wildcard Esta forma de configuracion es muy flexible para invocar diferentes metodos de nuestros actions <action name=&quot;*Telefono&quot; method=&quot;{1}&quot; class=&quot;mx.com.mexico.actions.telefono.TelefonoAction&quot;> <result>/jsp/telefono/{1}Telefono.jsp</result> <result name=&quot;exito&quot; type=&quot;redirect-action&quot;>allTelefono</result> <result name=&quot;input&quot;>/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=&quot;#session.mySessionPropKey&quot;/>  <s:property value=&quot;#session['mySessionPropKey']&quot;/>  <s:property value=&quot;#request['myRequestPropKey']&quot;/> <s:property value=&quot; address.postcode &quot;/> <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: JasperReports JFreeChart JSF Struts1 Portlets REST Tiles 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 Struts:  http://struts.apache.org/2.1.6/ http://struts.apache.org/2.1.6/docs/guides.htm http://www.infoq.com/minibooks/starting-struts2l http://www.javaworld.com/javaworld/jw-10-2008/jw-10-struts2validation.html http://www.struts2.net/
Preguntas??
GRACIAS…. Esten pendientes de www.springhispano.org   www.javamexico.org http://www.planetajava.org/

Introduccion Struts2

  • 1.
    4ta. Reunión SpringHispano& JavaMexico Struts 2
  • 2.
    Agenda Introducción FrameworkCaracterísticas nuevas Configuración Plugin Spring
  • 3.
  • 4.
    Caracteristicas Struts2 Basado en POJO’s Conversion de Datos Inyección de Dependencias Validaciones Flexible con etiquetas para Ajax Soporte OGNL Testability
  • 5.
    Configuración XML Ahorala configuración se basa en paquetes donde cada paquete contiene los actions. Permite heredar configuraciones de otro paquete. <struts> <constant name= &quot;struts.objectFactory&quot; value=&quot;spring&quot; /> <package name= &quot;defaulf&quot; namespace=&quot;/&quot; extends=&quot;struts-default&quot;> <action name= &quot;index&quot; class=&quot;mx.com.mexico.IndexAction&quot;> <result>/jsp/index.jsp</result> </action> </package> </struts>
  • 6.
    Como creo unAction? Los actions se basan en POJO’s. public class HelloWorldAction extends ActionSupport { private Date now; private String name; @RequiredFieldValidator ( message = &quot;Por favor ingresa la fecha” ) public void setDateNow( Date now ) { this.now = now; } public Date getDateNow() { return now; } @RequiredStringValidator ( message = &quot;Por favor ingresa el nombre&quot;, trim = true ) public void setName(String name) { this.name = name; } public String getName() { return this.name; } public String execute() throws Exception { return SUCCESS; } }
  • 7.
    Conversion datos Facilitael manejo de tipo de datos como los Date, Time @TypeConversion(converter = ”org.struts2.DateConverter&quot;) 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 &quot;&quot;; }
  • 8.
    Inyeccion de DependenciasPlugin Spring: Framework OpenSource de IoC y más que eso! Plugin Plexus Google Guice
  • 9.
    Elementos basicos ActionSupport: Clase para manejo de los request Result default redirect-action Redirect Freemarker Velocity stream Interceptor validationWorkflowStack fileUploadStack paramPrepareParamsStack etc…
  • 10.
    Configuracion Wildcard Estaforma de configuracion es muy flexible para invocar diferentes metodos de nuestros actions <action name=&quot;*Telefono&quot; method=&quot;{1}&quot; class=&quot;mx.com.mexico.actions.telefono.TelefonoAction&quot;> <result>/jsp/telefono/{1}Telefono.jsp</result> <result name=&quot;exito&quot; type=&quot;redirect-action&quot;>allTelefono</result> <result name=&quot;input&quot;>/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; }
  • 11.
    Soporte para OGNL (Object Graph Navigation Language) Una tecnologia para el manejo de propiedades en los objetos Java Ejemplos: <s:property value=&quot;#session.mySessionPropKey&quot;/> <s:property value=&quot;#session['mySessionPropKey']&quot;/> <s:property value=&quot;#request['myRequestPropKey']&quot;/> <s:property value=&quot; address.postcode &quot;/> <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 ” >
  • 12.
    Que mas hay??Soporte para: JasperReports JFreeChart JSF Struts1 Portlets REST Tiles TestNG
  • 13.
  • 14.
    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 )
  • 15.
    Recursos Struts: http://struts.apache.org/2.1.6/ http://struts.apache.org/2.1.6/docs/guides.htm http://www.infoq.com/minibooks/starting-struts2l http://www.javaworld.com/javaworld/jw-10-2008/jw-10-struts2validation.html http://www.struts2.net/
  • 16.
  • 17.
    GRACIAS…. Esten pendientesde www.springhispano.org www.javamexico.org http://www.planetajava.org/