Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
titlehelloForm.jsp
<%@ taglib uri="/webwork" prefix="ww" %>

<H2>Hi there! Please enter your name</H2>
<ww:form action="helloWorld" method="POST">
	<ww:textfield label="First name" name="firstName" value="%{firstName}"/>
	<ww:textfield label="Last name" name="lastName" value="%{lastName}"/>
	<ww:submit value="Say hello!"/>
</ww:form>

Now we're ready to code some Java, not much, but at least a little bit. We create a new package in our src folder, let's name it com.opensymphony.webwork.portlet.tutorial. In this package, create a HelloWorldAction class. In usual WebWork manners, this class extends the ActionSupport class from the XWork framework, and we'll add a couple of properties that maps to our form in the JSP we just created:

Code Block
titleHelloWorldAction.java

package com.opensymphony.webwork.portlet.tutorial;

import com.opensymphony.xwork.ActionSupport;

public class HelloWorldAction extends ActionSupport {
	private String firstName;
	private String lastName;
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
}

We also need a JSP to display the processed input. We'll just use the old helloWorld.jsp and modify it a bit. As with helloForm.jsp, we import the WebWork tag library, and we use the ww:property tags to display the input from the form:

Code Block
titlehelloWorld.jsp

<%@ taglib prefix="ww" uri="/webwork" %>

<H2>Hello <ww:property value="firstName"/> <ww:property value="lastName"/></H2>
<p/>
<a href="<ww:url action="helloWorldInput"/>">Back to form</a>

Re-deployment

Now we're ready to do a re-deployment of our application, so zip up a new war and drop it in the server/default/deploy folder. The "MyPortlet Tutorial" page will now display:

Hello World form
Image Added

Enter some data, and press the "Say hello!" button, and you will get a nice little personalized "hello" message:

Personalized Hello World

Image Added