Skip to content

Commit ccff762

Browse files
committed
Potential fix for #190
1 parent 7901752 commit ccff762

File tree

5 files changed

+230
-164
lines changed

5 files changed

+230
-164
lines changed

config-prettyfaces/src/main/java/org/ocpsoft/rewrite/prettyfaces/PrettyFacesActionUrlProvider.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@
1616
package org.ocpsoft.rewrite.prettyfaces;
1717

1818
import javax.faces.context.FacesContext;
19+
import javax.servlet.ServletContext;
20+
import javax.servlet.http.HttpServletRequest;
1921

22+
import org.ocpsoft.common.services.ServiceLoader;
2023
import org.ocpsoft.rewrite.faces.spi.FacesActionUrlProvider;
24+
import org.ocpsoft.rewrite.servlet.DispatcherType;
25+
import org.ocpsoft.rewrite.servlet.spi.DispatcherTypeProvider;
2126

2227
import com.ocpsoft.pretty.PrettyContext;
2328
import com.ocpsoft.pretty.faces.beans.ExtractedValuesURLBuilder;
@@ -28,7 +33,27 @@
2833
*/
2934
public class PrettyFacesActionUrlProvider implements FacesActionUrlProvider
3035
{
31-
public String getActionURL(final FacesContext context, final String viewId)
36+
@SuppressWarnings("unchecked")
37+
private final Iterable<DispatcherTypeProvider> providers = ServiceLoader.load(DispatcherTypeProvider.class);
38+
39+
@Override
40+
public String getActionURL(FacesContext context, String viewId)
41+
{
42+
HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
43+
44+
for (DispatcherTypeProvider provider : providers)
45+
{
46+
DispatcherType type = provider.getDispatcherType(request, (ServletContext) FacesContext
47+
.getCurrentInstance().getExternalContext().getContext());
48+
49+
if (type == null || type != DispatcherType.ERROR) {
50+
return _getActionURL(context, viewId);
51+
}
52+
}
53+
return null;
54+
}
55+
56+
public String _getActionURL(final FacesContext context, final String viewId)
3257
{
3358
PrettyContext prettyContext = PrettyContext.getCurrentInstance(context);
3459
String result = null;

impl-servlet-2.5/src/main/java/org/ocpsoft/rewrite/servlet/impl/Servlet25DispatcherTypeProvider.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,17 @@ public DispatcherType getDispatcherType(ServletRequest request, ServletContext c
4242
if (request.getAttribute("javax.servlet.forward.request_uri") != null) {
4343
return DispatcherType.FORWARD;
4444
}
45+
4546
if (request.getAttribute("javax.servlet.include.request_uri") != null) {
4647
return DispatcherType.INCLUDE;
4748
}
48-
return DispatcherType.REQUEST;
4949

50+
Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception");
51+
if (throwable != null) {
52+
return DispatcherType.ERROR;
53+
}
54+
55+
return DispatcherType.REQUEST;
5056
}
5157

5258
}

0 commit comments

Comments
 (0)