Closed GoogleCodeExporter closed 9 years ago
Thank you for reporting.
I believe the FacesViewsViewHandler#getActionURL() needs to be altered to
always call super.getActionURL(context, viewId) and then make manipulations on
the return value if necessary.
Arjan, can you take a look at this?
Original comment by balusc
on 21 May 2013 at 4:09
Here's a diff of what I implemented for myself for now against the latest
version of Omnifaces:
# FacesViewsViewHandler.java
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -19,6 +19,7 @@
import static org.omnifaces.util.Faces.getRequestAttribute;
import static org.omnifaces.util.ResourcePaths.isExtensionless;
import static org.omnifaces.util.ResourcePaths.stripExtension;
+import static org.omnifaces.util.ResourcePaths.getQueryParameters;
import java.util.Map;
@@ -45,19 +46,20 @@
@Override
public String getActionURL(FacesContext context, String viewId) {
-
+ String actionURL = super.getActionURL(context, viewId);
+ String queryParameters = getQueryParameters(actionURL);
Map<String, String> mappedResources = getApplicationAttribute(context, FACES_VIEWS_RESOURCES);
if (mappedResources.containsKey(viewId)) {
if (isScannedViewsAlwaysExtensionless(context) || isOriginalViewExtensionless(context)) {
// User has requested to always render extensionless, or the requested viewId was mapped and the current
// request is extensionless, render the action URL extensionless as well.
- return context.getExternalContext().getRequestContextPath() +
stripExtension(viewId);
+ return context.getExternalContext().getRequestContextPath() +
stripExtension(viewId) + queryParameters;
}
}
// Not a resource we mapped or not a forwarded one, let the original view handler take care of it.
- return super.getActionURL(context, viewId);
\ No newline at end of file
+ return actionURL;
\ No newline at end of file
}
private boolean isOriginalViewExtensionless(FacesContext context) {
# ResourcePaths.java
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -101,4 +101,19 @@
return filteredResources;
}
+ /**
+ * Extracts the query string from a resource.
+ *
+ * @param resource A URL string
+ * @return the query string part of the URL
+ */
+ public static String getQueryParameters(final String resource) {
+ String queryParameters = "";
+ int questionMark = resource.indexOf('?');
+ if (questionMark != -1) {
+ queryParameters = resource.substring(questionMark);
}
+ return queryParameters;
+ }
+
+}
Original comment by rdcrng
on 21 May 2013 at 4:32
Guys, sorry for taking a bit longer to get back to you.
Indeed, the view handler should delegate to its parent handler and work with
the result. In general the parent view handler can do whatever it wants with
the view id, maybe exchanging it for another view and path altogether. I wasn't
quite sure how to handle this before so I didn't handle it at all for the
moment.
What I did now is checking the returned URL against the known FacesServlet
extension mappings + the extension of the given view id. If prefix mapping is
used, the action URL will most likely contain the view id extension and if
suffix mapping is used it should contain one of the known FacesServlet mappings.
Unfortunately this doesn't work for Servlet 2.5 users now, so I'll have to
think of something for that. Maybe the diff as given by rdcrng is a good
alternative for that environment.
See
https://code.google.com/p/omnifaces/source/detail?r=f3c434e1fb423e21c136f93e9099
55ef8af1b8d2 for the changes thus far.
Original comment by arjan.tijms
on 27 May 2013 at 9:54
Added rdcrng's idea as an alternative mode and made that the default for
Servlet 2.5 in
https://code.google.com/p/omnifaces/source/detail?r=ebb5ccb30ade7eb23cf0b1d1c1a7
fd904187a5cd
Original comment by arjan.tijms
on 27 May 2013 at 10:45
Arjan, I tested your changes against my project and it works as expected -
thanks.
Original comment by rdcrng
on 28 May 2013 at 2:47
rdcrng, great it works :) I'll close the issue then. Thanks again for reporting
this!
Original comment by arjan.tijms
on 28 May 2013 at 9:28
Glad I could be of help and thanks for the credit :)
Original comment by rdcrng
on 29 May 2013 at 11:38
Original issue reported on code.google.com by
rdcrng
on 21 May 2013 at 4:04