We9 Struts 2.0

46
Struts 2.0 Don Brown

Transcript of We9 Struts 2.0

Page 1: We9 Struts 2.0

Struts 2.0

Don Brown

Page 2: We9 Struts 2.0

Web, Circa 2000

Page 3: We9 Struts 2.0

Web, Circa 2006

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

Struts 2 Architecture

Page 19: We9 Struts 2.0

Struts 1Action ActionForm ActionForward struts-config.xml

ActionServlet

RequestProcessor

Struts 2ActionAction or POJO’s

Resultstruts.xmlFilterDispatcher

Interceptors

Page 20: We9 Struts 2.0

Struts Plugins

Page 21: We9 Struts 2.0

Simple Example

Page 22: We9 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: We9 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: We9 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: We9 Struts 2.0

...

Only four pages!

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

Page 26: We9 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: We9 Struts 2.0

Example Revisited

Page 28: We9 Struts 2.0

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

Page 29: We9 Struts 2.0

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

Page 30: We9 Struts 2.0

<s:optiontransferselect ... />

Page 31: We9 Struts 2.0

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

Page 32: We9 Struts 2.0

But there's more . . .

Page 33: We9 Struts 2.0

Brian Kernighan Law of Debugging Difficulty

Debugging 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: We9 Struts 2.0

Prevention and Cure

Page 35: We9 Struts 2.0

struts.devMode = true

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

Built-in Testing Support

public class MyActionTest extends StrutsTestCase {

public void testExecute() throws Exception {

assertTrue(true); }}

Page 39: We9 Struts 2.0

any.action?debug=console

Page 40: We9 Struts 2.0

any.action?profiling=yes

Page 41: We9 Struts 2.0

Time to Upgrade?

Page 42: We9 Struts 2.0

Tutorials, Guides, and FAQs

Page 43: We9 Struts 2.0

Struts 2 Training Course

Page 44: We9 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: We9 Struts 2.0

How do I get started?

Page 46: We9 Struts 2.0

Where We are Going