NewGameActionBean
@UrlBinding("/experimental/new/game") public class NewGameActionBean extends BaseActionBean implements ActionBean { private final static String JSP_NEWGAME = "/jsp/experimental/new_game.jsp"; private Game game = null; @DefaultHandler public Resolution defaultHandler() { return new ForwardResolution(JSP_NEWGAME); } public Resolution update() { if (this.game!=null) { this.setDebugString(game.toWebString()); } return new ForwardResolution(JSP_NEWGAME); } public Game getGame() { return game; } @ValidateNestedProperties({ @Validate(field="mainTitle", required=true, on="update") }) public void setGame(Game game) { this.game = game; } }
line 1:
@UrlBinding
(
"/experimental/new/game"
)
Very simple way to determine the URL under which the site will be available.
line 7:
@DefaultHandler
This Method is called when the URL is visited. Returns a Resolution to the JSP-File new_game.jsp.
line 12:
public
Resolution update() {
This method is called when the HTML-Form-Submit-Button (see below in new_game.jsp) is clicked (
<
stripes:submit
name
=
"update"
>
).The methods
getGame
and setGame
srepresent the Bean property "game", which can be accessed (read and write) from the corresponding jsp file.line 24:
@Validate
(field=
"mainTitle"
, required=
true
, on=
"update"
)
The form field "game.mainTitle" is validated (must not be empty) in the methode "update".
new_game.jsp
<%@ include file="/WEB-INF/taglibs.jspp"%> <stripes:layout-render name="/jsp/layout/main.jsp"> <stripes:layout-component name="contents"> <stripes:form beanclass="org.oregami.action.experimental.NewGameActionBean"> <table class="form"> <tr><td> mainTitle: <stripes:text name="game.mainTitle" class="required"/> </td> <td> <stripes:errors field="game.mainTitle"></stripes:errors> </td></tr> <tr><td> description: <stripes:text name="game.description"/> </td></tr> <tr><td colspan="1"> <stripes:submit name="update"><fmt:message key="aktualisieren"/></stripes:submit> </td></tr> </table> </stripes:form> </stripes:layout-component> </stripes:layout-render>
line 17:
<stripes:errors
field
=
"game.mainTitle"
></
stripes:errors
>
Displays the error message for the field "mainTitle" of the property "game" (if an error exists).
Feel free to have a look at our real Source Code at Github: