Skip to content

Commit

Permalink
WW-3872 adds Tiles support to portlet example app
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1394440 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
lukaszlenart committed Oct 5, 2012
1 parent b83b858 commit 2784e24
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.2//EN" "http://struts.apache.org/dtds/xwork-validator-1.0.2.dtd">
<validators>
<field name="firstName">
<field-validator type="requiredstring">
<message>You must enter a first name</message>
</field-validator>
</field>
<field name="lastName">
<field-validator type="requiredstring">
<message>You must enter a last name</message>
</field-validator>
</field>
</validators>
27 changes: 27 additions & 0 deletions src/main/resources/struts-tiles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
<package name="tiles" extends="struts-portlet-tiles-default" namespace="/tiles">
<default-action-ref name="index"/>

<action name="index" class="org.apache.struts2.portlet.example.FormExample">
<result type="tiles">formExampleTiles.index</result>
<result name="success" type="tiles">formExampleTiles.index</result>
</action>

<action name="processTilesFreemarkerExample" class="org.apache.struts2.portlet.example.FormExample" method="input">
<result name="success" type="tiles">formExampleTiles.freemarker</result>
</action>

<action name="processTilesFreemarkerExample" class="org.apache.struts2.portlet.example.FormExample" method="execute">
<result name="input" type="tiles">formExampleTiles.freemarker</result>
<result name="success" type="tiles">formExampleTiles.freemarkerResult</result>
</action>

</package>
</struts>


46 changes: 46 additions & 0 deletions src/main/webapp/WEB-INF/tiles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
-->

<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">

<tiles-definitions>

<definition name="formExampleTiles.index" template="/WEB-INF/tiles/layout.jsp">
<put-attribute name="title" value="Portlet Tiles FormExample"/>
<put-attribute name="header" value="/WEB-INF/tiles/header.jsp"/>
<put-attribute name="body" value="/WEB-INF/tiles/index.jsp"/>
<put-attribute name="footer" value="/WEB-INF/tiles/footer.jsp"/>
</definition>

<definition name="formExampleTiles.freemarker" extends="formExampleTiles.index">
<put-attribute name="title" value="Portlet Tiles/Freemarker FormExample"/>
<put-attribute name="body" value="/WEB-INF/tiles/formExampleInputValidation.jsp"/>
</definition>

<definition name="formExampleTiles.freemarkerResult" extends="formExampleTiles.freemarker">
<put-attribute name="body" value="/WEB-INF/tiles/formExample.jsp"/>
</definition>

</tiles-definitions>
5 changes: 5 additions & 0 deletions src/main/webapp/WEB-INF/tiles/footer.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<hr/>
<@s.url id="home" action="index" namespace="/view" />
<div>
<p>Powered by Struts2 Portlet/Tiles Plugin | <@s.a href="${home}">Back to front page</@s.a></p>
</div>
6 changes: 6 additions & 0 deletions src/main/webapp/WEB-INF/tiles/footer.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%@ taglib prefix="s" uri="/struts-tags" %>
<hr/>
<s:url id="home" action="index" namespace="/view" />
<div>
<p>Powered by Struts2 Portlet/Tiles Plugin | <s:a href="%{home}">Back to front page</s:a></p>
</div>
5 changes: 5 additions & 0 deletions src/main/webapp/WEB-INF/tiles/formExample.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%@ taglib prefix="s" uri="/struts-tags" %>

<H2>Hello <s:property value="firstName"/> <s:property value="lastName"/></H2>
<p/>

8 changes: 8 additions & 0 deletions src/main/webapp/WEB-INF/tiles/formExampleInputValidation.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%@ taglib prefix="s" uri="/struts-tags" %>
<link rel="stylesheet" type="text/css" href="<s:url value="/styles/styles.css"/>">
<H2>Input your name</H2>
<s:form action="processTilesFreemarkerExample" namespace="/tiles" method="POST" >
<s:textfield label="First name" name="firstName" value="%{firstName}"/>
<s:textfield label="Last name" name="lastName" value="%{lastName}"/>
<s:submit value="Submit the form"/>
</s:form>
2 changes: 2 additions & 0 deletions src/main/webapp/WEB-INF/tiles/header.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Struts2 Portlet Tiles App Example</h1>
<hr/>
13 changes: 13 additions & 0 deletions src/main/webapp/WEB-INF/tiles/index.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%@taglib prefix="s" uri="/struts-tags" %>
<div>
<p>This example illustrates the Struts/Portlet/Tiles Plugin.</p>

<h4>Features</h4>
<ul>
<li>
<s:url id="freemarker" namespace="/tiles" action="processTilesFreemarkerExample" method="input" />
<s:a href="%{freemarker}">View FreeMarker Example</s:a>
</li>
</ul>

</div>
13 changes: 13 additions & 0 deletions src/main/webapp/WEB-INF/tiles/layout.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<tiles:importAttribute name="title" scope="request"/>

<tiles:insertAttribute name="header"/>
<h2><tiles:insertAttribute name="title"/></h2>
<p id="body">
<tiles:insertAttribute name="body"/>
</p>

<p>Notice that this is a layout made in JSP</p>

<tiles:insertAttribute name="footer"/>

0 comments on commit 2784e24

Please sign in to comment.