Skip to content

Commit d800206

Browse files
committed
Hacked to work with Seam MVC
1 parent 63e5df8 commit d800206

8 files changed

Lines changed: 149 additions & 107 deletions

File tree

‎prototype/pom.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
<artifactId>seam-mvc</artifactId>
2929
<version>1.0.0-SNAPSHOT</version>
3030
</dependency>
31+
<dependency>
32+
<groupId>org.jboss.seam.servlet</groupId>
33+
<artifactId>seam-servlet</artifactId>
34+
<version>3.0.0.Final</version>
35+
</dependency>
3136

3237
<dependency>
3338
<groupId>javax.enterprise</groupId>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2011, Red Hat, Inc., and individual contributors
4+
* by the @authors tag. See the copyright.txt in the distribution for a
5+
* full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
package com.ocpsoft.rewrite.prototype;
23+
24+
/**
25+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
26+
*
27+
*/
28+
// @RequestFlow
29+
public enum Flow
30+
{
31+
// @Redirect
32+
INDEX,
33+
RESULT
34+
}

‎prototype/src/main/java/com/ocpsoft/rewrite/prototype/IndexBean.java‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,53 @@
11
package com.ocpsoft.rewrite.prototype;
22

3+
import java.io.IOException;
4+
35
import javax.enterprise.context.RequestScoped;
6+
import javax.enterprise.event.Observes;
47
import javax.inject.Named;
58

9+
import com.ocpsoft.rewrite.servlet.http.event.HttpInboundServletRewrite;
10+
import com.ocpsoft.rewrite.servlet.http.event.HttpOutboundServletRewrite;
11+
612
@Named
713
@RequestScoped
814
public class IndexBean
915
{
1016
private String name;
1117
private String selected;
1218

13-
public String handleSubmit(final Object i)
19+
// @RequestMapping(url="/index/{param}")
20+
public void get(@Observes final HttpInboundServletRewrite event
21+
// ,@RequestParam String param
22+
) throws IOException
23+
{
24+
// The code in these two methods will be replaced with framework annotations
25+
// on the class or action method itself
26+
String requestURL = event.getRequestURL();
27+
28+
if ("/index".equals(requestURL)) {
29+
event.forward("/index.mvc");
30+
}
31+
if ("/result".equals(requestURL)) {
32+
event.forward("/result.mvc");
33+
}
34+
}
35+
36+
public void rewriteOutbound(@Observes final HttpOutboundServletRewrite event) throws IOException
37+
{
38+
String outboundURL = event.getOutboundURL();
39+
if (outboundURL.endsWith(".mvc"))
40+
{
41+
event.setOutboundURL(outboundURL.substring(0, outboundURL.lastIndexOf(".mvc")));
42+
}
43+
}
44+
45+
// This is our action method
46+
public Object handleSubmit(final Object i)
1447
{
1548
System.out.println("IndexBean.handleSubmit(" + i + ")");
16-
return "submitted";
49+
50+
return Flow.RESULT;
1751
}
1852

1953
public String getName()

‎prototype/src/main/java/com/ocpsoft/rewrite/prototype/RewriteBean.java‎

Lines changed: 0 additions & 99 deletions
This file was deleted.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2011, Red Hat, Inc., and individual contributors
4+
* by the @authors tag. See the copyright.txt in the distribution for a
5+
* full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
package com.ocpsoft.rewrite.prototype;
23+
24+
import java.io.IOException;
25+
26+
import javax.servlet.http.HttpServletRequest;
27+
import javax.servlet.http.HttpServletResponse;
28+
29+
import org.jboss.seam.mvc.spi.NavigationProvider;
30+
31+
/**
32+
* This class will be provided by the MVC framework, and will use whatever kind of configuration we decide to go with.
33+
*
34+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
35+
*
36+
*/
37+
public class RewriteNavigationProvider implements NavigationProvider<Flow>
38+
{
39+
@Override
40+
public boolean handles(final Object result)
41+
{
42+
return (result instanceof Flow);
43+
}
44+
45+
@Override
46+
public boolean navigate(final HttpServletRequest req, final HttpServletResponse resp, final Flow result)
47+
{
48+
// Always redirect. Otherwise, we have form issues.
49+
resp.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
50+
resp.setHeader("Location",
51+
resp.encodeRedirectURL(req.getContextPath() + "/" + result.name().toLowerCase() + ".mvc"));
52+
try {
53+
resp.flushBuffer();
54+
}
55+
catch (IOException e) {
56+
throw new RuntimeException(e);
57+
}
58+
return true;
59+
}
60+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.ocpsoft.rewrite.prototype.RewriteNavigationProvider

‎prototype/src/main/webapp/WEB-INF/faces-config.xml‎

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3+
4+
<html>
5+
<head>
6+
<title>Seam MVC - Result</title>
7+
</head>
8+
<body>
9+
10+
<h1>This is your result!</h1>
11+
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)