Skip to content

Commit 10be32c

Browse files
authored
Merge pull request eugenp#8192 from SmartyAnsh/master
BAEL-1112 - Apache Tapestry
2 parents d6f9b92 + b07360c commit 10be32c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+10670
-0
lines changed

apache-tapestry/pom.xml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.baeldung</groupId>
5+
<artifactId>apache-tapestry</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<packaging>war</packaging>
8+
<name>apache-tapestry</name>
9+
<dependencies>
10+
<!-- To set up an application with a database, change the artifactId below to
11+
tapestry-hibernate, and add a dependency on your JDBC driver. You'll also
12+
need to add Hibernate configuration files, such as hibernate.cfg.xml. -->
13+
<dependency>
14+
<groupId>org.apache.tapestry</groupId>
15+
<artifactId>tapestry-core</artifactId>
16+
<version>${tapestry-release-version}</version>
17+
</dependency>
18+
19+
<!-- Include the Log4j implementation for the SLF4J logging framework -->
20+
<dependency>
21+
<groupId>org.slf4j</groupId>
22+
<artifactId>slf4j-log4j12</artifactId>
23+
<version>${slf4j-release-version}</version>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>org.apache.tapestry</groupId>
28+
<artifactId>tapestry-webresources</artifactId>
29+
<version>${tapestry-release-version}</version>
30+
</dependency>
31+
32+
<!-- Uncomment this to add support for file uploads: -->
33+
<!--
34+
<dependency>
35+
<groupId>org.apache.tapestry</groupId>
36+
<artifactId>tapestry-upload</artifactId>
37+
<version>${tapestry-release-version}</version>
38+
</dependency>
39+
-->
40+
41+
<!-- A dependency on either JUnit or TestNG is required, or the surefire plugin (which runs the tests)
42+
will fail, preventing Maven from packaging the WAR. Tapestry includes a large number
43+
of testing facilities designed for use with TestNG (http://testng.org/), so it's recommended. -->
44+
<dependency>
45+
<groupId>org.testng</groupId>
46+
<artifactId>testng</artifactId>
47+
<version>${testng-release-version}</version>
48+
<scope>test</scope>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>org.apache.tapestry</groupId>
53+
<artifactId>tapestry-test</artifactId>
54+
<version>${tapestry-release-version}</version>
55+
<scope>test</scope>
56+
</dependency>
57+
58+
<!-- Provided by the servlet container, but sometimes referenced in the application
59+
code. -->
60+
<dependency>
61+
<groupId>javax.servlet</groupId>
62+
<artifactId>servlet-api</artifactId>
63+
<version>${servlet-api-release-version}</version>
64+
<scope>provided</scope>
65+
</dependency>
66+
67+
<!-- Provide dependency to the Tapestry javadoc taglet which replaces the Maven component report -->
68+
<dependency>
69+
<groupId>org.apache.tapestry</groupId>
70+
<artifactId>tapestry-javadoc</artifactId>
71+
<version>${tapestry-release-version}</version>
72+
<scope>provided</scope>
73+
</dependency>
74+
75+
</dependencies>
76+
<build>
77+
<finalName>apache-tapestry</finalName>
78+
<plugins>
79+
<plugin>
80+
<groupId>org.apache.maven.plugins</groupId>
81+
<artifactId>maven-compiler-plugin</artifactId>
82+
<version>2.3.2</version>
83+
<configuration>
84+
<source>1.8</source>
85+
<target>1.8</target>
86+
<optimize>true</optimize>
87+
</configuration>
88+
</plugin>
89+
90+
<plugin>
91+
<groupId>org.apache.maven.plugins</groupId>
92+
<artifactId>maven-surefire-plugin</artifactId>
93+
<version>2.7.2</version>
94+
<configuration>
95+
<systemPropertyVariables>
96+
<tapestry.execution-mode>Qa</tapestry.execution-mode>
97+
</systemPropertyVariables>
98+
</configuration>
99+
</plugin>
100+
101+
<!-- Run the application using "mvn jetty:run" -->
102+
<plugin>
103+
<groupId>org.mortbay.jetty</groupId>
104+
<artifactId>maven-jetty-plugin</artifactId>
105+
<version>6.1.16</version>
106+
<configuration>
107+
<!-- Log to the console. -->
108+
<requestLog implementation="org.mortbay.jetty.NCSARequestLog">
109+
<!-- This doesn't do anything for Jetty, but is a workaround for a Maven bug
110+
that prevents the requestLog from being set. -->
111+
<append>true</append>
112+
</requestLog>
113+
<systemProperties>
114+
<systemProperty>
115+
<name>tapestry.execution-mode</name>
116+
<value>development</value>
117+
</systemProperty>
118+
</systemProperties>
119+
</configuration>
120+
</plugin>
121+
</plugins>
122+
</build>
123+
124+
<reporting/>
125+
126+
<repositories>
127+
<repository>
128+
<id>jboss</id>
129+
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
130+
</repository>
131+
132+
<!-- This repository is only needed when the Tapestry version is a preview release, rather
133+
than a final release. -->
134+
<repository>
135+
<id>apache-staging</id>
136+
<url>https://repository.apache.org/content/groups/staging/</url>
137+
</repository>
138+
</repositories>
139+
140+
<properties>
141+
<tapestry-release-version>5.4.5</tapestry-release-version>
142+
<servlet-api-release-version>2.5</servlet-api-release-version>
143+
<testng-release-version>6.8.21</testng-release-version>
144+
<slf4j-release-version>1.7.19</slf4j-release-version>
145+
146+
</properties>
147+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.tapestry.components;
2+
3+
import org.apache.tapestry5.BindingConstants;
4+
import org.apache.tapestry5.annotations.Parameter;
5+
import org.apache.tapestry5.annotations.Property;
6+
7+
/**
8+
* Layout component for pages of application.
9+
*/
10+
public class Layout {
11+
12+
@Property
13+
@Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
14+
private String title;
15+
16+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.tapestry.pages;
2+
3+
public class Error404 {
4+
5+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.baeldung.tapestry.pages;
2+
3+
import java.util.Date;
4+
5+
import org.apache.tapestry5.Block;
6+
import org.apache.tapestry5.annotations.Log;
7+
import org.apache.tapestry5.annotations.Property;
8+
import org.apache.tapestry5.ioc.annotations.Inject;
9+
import org.apache.tapestry5.services.ajax.AjaxResponseRenderer;
10+
import org.slf4j.Logger;
11+
12+
public class Home {
13+
14+
@Property
15+
private String appName = "apache-tapestry";
16+
17+
public Date getCurrentTime() {
18+
return new Date();
19+
}
20+
21+
@Inject
22+
private Logger logger;
23+
24+
@Inject
25+
private AjaxResponseRenderer ajaxResponseRenderer;
26+
27+
@Inject
28+
private Block ajaxBlock;
29+
30+
@Log
31+
void onCallAjax() {
32+
logger.info("Ajax call");
33+
ajaxResponseRenderer.addRender("ajaxZone", ajaxBlock);
34+
}
35+
36+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.baeldung.tapestry.pages;
2+
3+
4+
import org.apache.tapestry5.Block;
5+
import org.apache.tapestry5.EventContext;
6+
import org.apache.tapestry5.SymbolConstants;
7+
import org.apache.tapestry5.annotations.InjectPage;
8+
import org.apache.tapestry5.annotations.Log;
9+
import org.apache.tapestry5.annotations.Property;
10+
import org.apache.tapestry5.ioc.annotations.Inject;
11+
import org.apache.tapestry5.ioc.annotations.Symbol;
12+
import org.apache.tapestry5.services.HttpError;
13+
import org.apache.tapestry5.services.ajax.AjaxResponseRenderer;
14+
import org.slf4j.Logger;
15+
16+
import java.util.Date;
17+
18+
/**
19+
* Start page of application apache-tapestry.
20+
*/
21+
public class Index {
22+
@Inject
23+
private Logger logger;
24+
25+
@Inject
26+
private AjaxResponseRenderer ajaxResponseRenderer;
27+
28+
@Property
29+
@Inject
30+
@Symbol(SymbolConstants.TAPESTRY_VERSION)
31+
private String tapestryVersion;
32+
33+
@Inject
34+
private Block block;
35+
36+
// Handle call with an unwanted context
37+
Object onActivate(EventContext eventContext) {
38+
return eventContext.getCount() > 0 ?
39+
new HttpError(404, "Resource not found") :
40+
null;
41+
}
42+
43+
@Log
44+
void onComplete() {
45+
logger.info("Complete call on Index page");
46+
}
47+
48+
@Log
49+
void onAjax() {
50+
logger.info("Ajax call on Index page");
51+
52+
ajaxResponseRenderer.addRender("middlezone", block);
53+
}
54+
55+
public Date getCurrentTime() {
56+
return new Date();
57+
}
58+
59+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.baeldung.tapestry.pages;
2+
3+
import org.apache.tapestry5.alerts.AlertManager;
4+
import org.apache.tapestry5.annotations.InjectComponent;
5+
import org.apache.tapestry5.annotations.Property;
6+
import org.apache.tapestry5.corelib.components.Form;
7+
import org.apache.tapestry5.ioc.annotations.Inject;
8+
import org.slf4j.Logger;
9+
10+
public class Login {
11+
@Inject
12+
private Logger logger;
13+
14+
@Inject
15+
private AlertManager alertManager;
16+
17+
@InjectComponent
18+
private Form login;
19+
20+
@Property
21+
private String email;
22+
23+
@Property
24+
private String password;
25+
26+
void onValidateFromLogin() {
27+
if(email == null || password == null) {
28+
alertManager.error("Email/Password is null");
29+
login.recordError("Validation failed");
30+
}
31+
}
32+
33+
Object onSuccessFromLogin() {
34+
alertManager.success("Welcome! Login Successful");
35+
return Home.class;
36+
}
37+
38+
void onFailureFromLogin() {
39+
alertManager.error("Please try again with correct credentials");
40+
}
41+
42+
}

0 commit comments

Comments
 (0)