Struts 2.0

46
Struts 2.0 Don Brown

description

Don Brown. Struts 2.0. Web, Circa 2000. Web, Circa 2006. Struts 2 Architecture. Struts 1 Action  ActionForm  ActionForward  struts-config.xml  ActionServlet  RequestProcessor . Struts 2 Action Action or POJO’s Result struts.xml - PowerPoint PPT Presentation

Transcript of Struts 2.0

Page 1: Struts 2.0

Struts 2.0

Don Brown

Page 2: Struts 2.0

Web, Circa 2000

Page 3: Struts 2.0

Web, Circa 2006

Page 4: Struts 2.0
Page 5: Struts 2.0
Page 6: Struts 2.0
Page 7: Struts 2.0
Page 8: Struts 2.0
Page 9: Struts 2.0
Page 10: Struts 2.0
Page 11: Struts 2.0
Page 12: Struts 2.0
Page 13: Struts 2.0
Page 14: Struts 2.0
Page 15: Struts 2.0
Page 16: Struts 2.0
Page 17: Struts 2.0
Page 18: Struts 2.0

Struts 2 Architecture

Page 19: Struts 2.0

Struts 1Action ActionForm ActionForward struts-config.xml

ActionServlet RequestProcessor

Struts 2ActionAction or POJO’sResultstruts.xmlFilterDispatcherInterceptors

Page 20: Struts 2.0

Struts Plugins

Page 21: Struts 2.0

Simple Example

Page 22: Struts 2.0

<html:errors/><html:form action="/SaveMeeting"><table border="0" width="100%"><tr> <th align="right"> Name: </th> <td align="left"> <html:text property="name" size=”50” /> </td></tr><tr> <th align="right"> Date:

Struts 1

Page 23: Struts 2.0

</th> <td align="left"> <html:text property="date" size="50"/> </td></tr><tr> <th align="right"> Invitees: </th> <td align="left"> <html:select property="invitees" multiple="true"> <html:options collection="employees" property="value" labelProperty="label"/> </html:select>

Page 24: Struts 2.0

</tr><tr> <th align="right"> Description: </th> <td align="left"> <html:textarea property="description" rows="4" cols="50" /> </td></tr><tr> <td align="right"> &nbsp; </td>

Page 25: Struts 2.0

...

Only four pages!

<td align="left"> <html:submit property="DO_SUBMIT"> Save </html:submit> </td></tr></table></html:form>

Page 26: Struts 2.0

<s:form action="Meeting" validate="true"> <s:token /> <s:textfield label=”Name” name=“name” /> <s:textfield label=”Date" name="date"/> <s:select label=”Invitees” name="invitees" list="employees"/> <s:textarea label=”Description” name="description" rows="4" cols="50" /> <s:submit value=”Save" method="save"/></s:form>

Struts 2

Page 27: Struts 2.0

Example Revisited

Page 28: Struts 2.0

<s:textfield label="Name" name="name" tooltip="Meeting name" />

Page 29: Struts 2.0

<s:datepicker label="Date" name="date"/>

Page 30: Struts 2.0

<s:optiontransferselect ... />

Page 31: Struts 2.0

<jsp:include page="/ajax/commonInclude.jsp"/>...<s:textarea theme="ajax" label="Description" name="description" rows="4" cols="50" />

Page 32: Struts 2.0

But there's more . . .

Page 33: Struts 2.0

Brian Kernighan Law of Debugging DifficultyDebugging is twice as hard as writing the code in the first

place. Therefore, if you write the code as cleverly as

possible, you are, by definition, not smart enough

to debug it.

Page 34: Struts 2.0

Prevention and Cure

Page 35: Struts 2.0

struts.devMode = true

Page 36: Struts 2.0
Page 37: Struts 2.0
Page 38: Struts 2.0

Built-in Testing Support

public class MyActionTest extends StrutsTestCase {

public void testExecute() throws Exception {

assertTrue(true); }}

Page 39: Struts 2.0

any.action?debug=console

Page 40: Struts 2.0

any.action?profiling=yes

Page 41: Struts 2.0

Time to Upgrade?

Page 42: Struts 2.0

Tutorials, Guides, and FAQs

Page 43: Struts 2.0

Struts 2 Training Course

Page 44: Struts 2.0

<action name="editGangster" class="org.apache.struts2.s1.Struts1Action"> <param name="className"> com.mycompany.gangstas.EditGangsterAction </param> <result> gangsterForm.jsp </result></action>

Run Struts 1 Actions as Is

Page 45: Struts 2.0

How do I get started?

Page 46: Struts 2.0

Where We are Going