Skip to content

Commit a5dde9a

Browse files
committed
BAEL-1112 - Apache Tapestry
1 parent 9b43dfe commit a5dde9a

File tree

15 files changed

+165
-297
lines changed

15 files changed

+165
-297
lines changed
Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,16 @@
11
package com.baeldung.tapestry.components;
22

33
import org.apache.tapestry5.BindingConstants;
4-
import org.apache.tapestry5.ComponentResources;
5-
import org.apache.tapestry5.SymbolConstants;
6-
import org.apache.tapestry5.annotations.Import;
74
import org.apache.tapestry5.annotations.Parameter;
85
import org.apache.tapestry5.annotations.Property;
9-
import org.apache.tapestry5.ioc.annotations.Inject;
10-
import org.apache.tapestry5.ioc.annotations.Symbol;
116

127
/**
13-
* Layout component for pages of application test-project.
8+
* Layout component for pages of application.
149
*/
15-
@Import(module = "bootstrap/collapse")
1610
public class Layout {
1711

18-
@Inject
19-
private ComponentResources resources;
20-
21-
/**
22-
* The page title, for the <title> element and the
23-
* <h1>element.
24-
*/
25-
@Property
26-
@Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
27-
private String title;
28-
29-
@Property
30-
private String pageName;
31-
32-
@Property
33-
@Inject
34-
@Symbol(SymbolConstants.APPLICATION_VERSION)
35-
private String appVersion;
36-
37-
public String getClassForPageName() {
38-
return resources.getPageName().equalsIgnoreCase(pageName) ? "active" : null;
39-
}
40-
41-
public String[] getPageNames() {
42-
return new String[] { "Index", "About", "Contact" };
43-
}
12+
@Property
13+
@Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
14+
private String title;
4415

4516
}

apache-tapestry/src/main/java/com/baeldung/tapestry/pages/About.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

apache-tapestry/src/main/java/com/baeldung/tapestry/pages/Contact.java

Lines changed: 0 additions & 5 deletions
This file was deleted.
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+
}

apache-tapestry/src/main/java/com/baeldung/tapestry/pages/Index.java

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,41 @@
1919
* Start page of application apache-tapestry.
2020
*/
2121
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-
@InjectPage
34-
private About about;
35-
36-
@Inject
37-
private Block block;
38-
39-
// Handle call with an unwanted context
40-
Object onActivate(EventContext eventContext) {
41-
return eventContext.getCount() > 0 ?
42-
new HttpError(404, "Resource not found") :
43-
null;
44-
}
45-
46-
Object onActionFromLearnMore() {
47-
about.setLearn("LearnMore");
48-
49-
return about;
50-
}
51-
52-
@Log
53-
void onComplete() {
54-
logger.info("Complete call on Index page");
55-
}
56-
57-
@Log
58-
void onAjax() {
59-
logger.info("Ajax call on Index page");
60-
61-
ajaxResponseRenderer.addRender("middlezone", block);
62-
}
63-
64-
public Date getCurrentTime() {
65-
return new Date();
66-
}
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+
}
6758

6859
}

apache-tapestry/src/main/java/com/baeldung/tapestry/pages/Login.java

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,39 @@
44
import org.apache.tapestry5.annotations.InjectComponent;
55
import org.apache.tapestry5.annotations.Property;
66
import org.apache.tapestry5.corelib.components.Form;
7-
import org.apache.tapestry5.corelib.components.PasswordField;
8-
import org.apache.tapestry5.corelib.components.TextField;
97
import org.apache.tapestry5.ioc.annotations.Inject;
108
import org.slf4j.Logger;
119

1210
public class Login {
13-
@Inject
14-
private Logger logger;
11+
@Inject
12+
private Logger logger;
1513

16-
@Inject
17-
private AlertManager alertManager;
14+
@Inject
15+
private AlertManager alertManager;
1816

19-
@InjectComponent
20-
private Form login;
17+
@InjectComponent
18+
private Form login;
2119

22-
@InjectComponent("email")
23-
private TextField emailField;
20+
@Property
21+
private String email;
2422

25-
@InjectComponent("password")
26-
private PasswordField passwordField;
23+
@Property
24+
private String password;
2725

28-
@Property
29-
private String email;
26+
void onValidateFromLogin() {
27+
if(email == null || password == null) {
28+
alertManager.error("Email/Password is null");
29+
login.recordError("Validation failed");
30+
}
31+
}
3032

31-
@Property
32-
private String password;
33+
Object onSuccessFromLogin() {
34+
alertManager.success("Welcome! Login Successful");
35+
return Home.class;
36+
}
3337

34-
void onValidateFromLogin() {
35-
if (!email.equals("[email protected]"))
36-
login.recordError(emailField, "Try with user: [email protected]");
37-
38-
if ( !password.equals("Tapestry5"))
39-
login.recordError(passwordField, "Try with password: Tapestry5");
40-
}
41-
42-
Object onSuccessFromLogin() {
43-
logger.info("Login successful!");
44-
alertManager.success("Welcome aboard!");
45-
46-
return Index.class;
47-
}
48-
49-
void onFailureFromLogin() {
50-
logger.warn("Login error!");
51-
alertManager.error("I'm sorry but I can't log you in!");
52-
}
38+
void onFailureFromLogin() {
39+
alertManager.error("Please try again with correct credentials");
40+
}
5341

5442
}

0 commit comments

Comments
 (0)