[GitHub] struts pull request: New result 'JSONActionRedirectResult' in json...

2016-01-19 Thread cnenning
Github user cnenning commented on the pull request:

https://github.com/apache/struts/pull/72#issuecomment-172772942
  
> Merged #72.


Yay, I got it landed :)



This Email was scanned by Sophos Anti Virus



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@struts.apache.org
For additional commands, e-mail: dev-h...@struts.apache.org



[GitHub] struts pull request: New result 'JSONActionRedirectResult' in json...

2016-01-14 Thread cnenning
Github user cnenning commented on a diff in the pull request:

https://github.com/apache/struts/pull/72#discussion_r49698088
  
--- Diff: 
plugins/json/src/main/java/org/apache/struts2/json/JSONValidationInterceptor.java
 ---
@@ -72,8 +74,8 @@
 
 private static final Logger LOG = 
LogManager.getLogger(JSONValidationInterceptor.class);
 
-private static final String VALIDATE_ONLY_PARAM = 
"struts.validateOnly";
-private static final String VALIDATE_JSON_PARAM = 
"struts.enableJSONValidation";
+static final String VALIDATE_ONLY_PARAM = "struts.validateOnly";
+static final String VALIDATE_JSON_PARAM = 
"struts.enableJSONValidation";
--- End diff --

oh yes, that they are private was a pain as I started this new result in an 
app project :laughing:


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@struts.apache.org
For additional commands, e-mail: dev-h...@struts.apache.org



[GitHub] struts pull request: New result 'JSONActionRedirectResult' in json...

2016-01-13 Thread lukaszlenart
Github user lukaszlenart commented on a diff in the pull request:

https://github.com/apache/struts/pull/72#discussion_r49608079
  
--- Diff: 
plugins/json/src/main/java/org/apache/struts2/json/JSONActionRedirectResult.java
 ---
@@ -0,0 +1,70 @@
+package org.apache.struts2.json;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.result.ServletActionRedirectResult;
+
+/**
+ * Specialized form of {@link ServletActionRedirectResult} which takes 
care of
+ * situation that browser has a JS/AJAX context, there are no validation 
errors
+ * and action is executed. In this case a http redirect is harmful as 
browsers
+ * don't pass them to JS handlers. So this result produces a JSON response
+ * containing redirect data.
+ *
+ * To be used along with {@link JSONValidationInterceptor}.
+ *
+ * Response JSON looks like this:
+ * 
+ * {"location": "$redirect url$"}
+ * 
+ *
+ */
+public class JSONActionRedirectResult extends ServletActionRedirectResult {
+
+private static final long serialVersionUID = 3107276294073879542L;
+
+@Override
+protected void sendRedirect(HttpServletResponse response, String 
finalLocation) throws IOException {
+if (sendJsonInsteadOfRedirect()) {
+printJson(response, finalLocation);
+} else {
+super.sendRedirect(response, finalLocation);
+}
+}
+
+/**
+ * If browser has called action in a JS/AJAX context we cannot send a
+ * redirect as response.
+ *
+ * @return true if a JSON response shall be generated, false if a 
redirect
+ * shall be sent.
+ */
+private boolean sendJsonInsteadOfRedirect() {
+HttpServletRequest request = ServletActionContext.getRequest();
+return isJsonEnabled(request) && !isValidateOnly(request);
+}
+
+private void printJson(HttpServletResponse response, String 
finalLocation) throws IOException {
--- End diff --

Could you make this function `protected`? This allow further extensions by 
users.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@struts.apache.org
For additional commands, e-mail: dev-h...@struts.apache.org



[GitHub] struts pull request: New result 'JSONActionRedirectResult' in json...

2016-01-13 Thread lukaszlenart
Github user lukaszlenart commented on a diff in the pull request:

https://github.com/apache/struts/pull/72#discussion_r49608066
  
--- Diff: 
plugins/json/src/main/java/org/apache/struts2/json/JSONActionRedirectResult.java
 ---
@@ -0,0 +1,70 @@
+package org.apache.struts2.json;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.result.ServletActionRedirectResult;
+
+/**
+ * Specialized form of {@link ServletActionRedirectResult} which takes 
care of
+ * situation that browser has a JS/AJAX context, there are no validation 
errors
+ * and action is executed. In this case a http redirect is harmful as 
browsers
+ * don't pass them to JS handlers. So this result produces a JSON response
+ * containing redirect data.
+ *
+ * To be used along with {@link JSONValidationInterceptor}.
+ *
+ * Response JSON looks like this:
+ * 
+ * {"location": "$redirect url$"}
+ * 
+ *
+ */
+public class JSONActionRedirectResult extends ServletActionRedirectResult {
+
+private static final long serialVersionUID = 3107276294073879542L;
+
+@Override
+protected void sendRedirect(HttpServletResponse response, String 
finalLocation) throws IOException {
+if (sendJsonInsteadOfRedirect()) {
+printJson(response, finalLocation);
+} else {
+super.sendRedirect(response, finalLocation);
+}
+}
+
+/**
+ * If browser has called action in a JS/AJAX context we cannot send a
+ * redirect as response.
+ *
+ * @return true if a JSON response shall be generated, false if a 
redirect
+ * shall be sent.
+ */
+private boolean sendJsonInsteadOfRedirect() {
--- End diff --

Could you make this function `protected`? This allow further extensions by 
users.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@struts.apache.org
For additional commands, e-mail: dev-h...@struts.apache.org



[GitHub] struts pull request: New result 'JSONActionRedirectResult' in json...

2016-01-13 Thread lukaszlenart
Github user lukaszlenart commented on the pull request:

https://github.com/apache/struts/pull/72#issuecomment-171341227
  
Overall looks nice, good job :)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@struts.apache.org
For additional commands, e-mail: dev-h...@struts.apache.org



[GitHub] struts pull request: New result 'JSONActionRedirectResult' in json...

2016-01-12 Thread cnenning
Github user cnenning commented on the pull request:

https://github.com/apache/struts/pull/72#issuecomment-170908683
  
> Why static?

There was no reason. In the app where that result was originaly implemented 
there was some other class calling that methods. I changed it.


> Problem with indent?

I re-formatted javadoc. Or were you refering to something else?




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@struts.apache.org
For additional commands, e-mail: dev-h...@struts.apache.org



[GitHub] struts pull request: New result 'JSONActionRedirectResult' in json...

2016-01-11 Thread cnenning
GitHub user cnenning opened a pull request:

https://github.com/apache/struts/pull/72

New result 'JSONActionRedirectResult' in json-plugin

Adds new result 'JSONActionRedirectResult' to json-plugin. Contains tests 
and example in showcase app. The new result type is intended to be used along 
with existing JSONValidationInterceptor. It makes it possible to do form 
validation via ajax and handle form submitting, action execution and redirect 
evaluation all in one request inside JS context.

The sample Action is called `AjaxFormSubmitAction`. That example is by far 
longer that the change to json-plugin itself (not just that action class but 
other files that it requires). Here is an excerpt of it's javadoc, that shows 
what can be done with the new result:

* Depends on `json-plugin`.
* Requires `jsonValidationInterceptor` to be on stack.
* Uses a special json redirect result type.
* Uses http parameters `struts.enableJSONValidation=true` and 
`struts.validateOnly=false`.
* Uses a customized theme to make sure html elements required as error 
containers are always present and easily selectable in JS.
* Uses some custom JS code depending on jQuery to issue AJAX request and to 
render errors in html.
* Shows visual feedback while waiting for AJAX response.



You can merge this pull request into a Git repository by running:

$ git pull https://github.com/cnenning/struts ajax-form

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/struts/pull/72.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #72


commit cb11898416949c4028d99651e9697671797f1b99
Author: cnenning 
Date:   2016-01-11T13:36:32Z

Adds new result 'JSONActionRedirectResult' to json-plugin. Contains tests 
and example in showcase app. The new result type is intended to be used along 
with existing JSONValidationInterceptor. It makes it possible to do form 
validation via ajax and handle form submitting, action execution and redirect 
evaluation all in one request inside JS context.




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@struts.apache.org
For additional commands, e-mail: dev-h...@struts.apache.org



[GitHub] struts pull request: New result 'JSONActionRedirectResult' in json...

2016-01-11 Thread lukaszlenart
Github user lukaszlenart commented on a diff in the pull request:

https://github.com/apache/struts/pull/72#discussion_r49329379
  
--- Diff: 
plugins/json/src/main/java/org/apache/struts2/json/JSONActionRedirectResult.java
 ---
@@ -0,0 +1,71 @@
+package org.apache.struts2.json;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.result.ServletActionRedirectResult;
+
+/**
+ * Specialized form of {@link ServletActionRedirectResult} which takes 
care of
+ * situation that browser has a JS/AJAX context, there are no validation 
errors
+ * and action is executed. In this case a http redirect is harmful as 
browsers
+ * don't pass them to JS handlers. So this result produces a JSON response
+ * containing redirect data.
+ *
+ *
+ * To be used along with {@link JSONValidationInterceptor}.
+ *
+ *
+ * Response JSON looks like this:
+ * {"location": "$redirect url$"}
+ *
+ *
+ */
+public class JSONActionRedirectResult extends ServletActionRedirectResult {
+
+private static final long serialVersionUID = 3107276294073879542L;
+
+@Override
+   protected void sendRedirect(HttpServletResponse response, String 
finalLocation) throws IOException {
+if (sendJsonInsteadOfRedirect()) {
+printJson(response, finalLocation);
+} else {
+super.sendRedirect(response, finalLocation);
+}
+}
+
+/**
+ * If browser has called action in a JS/AJAX context we cannot send a
+ * redirect as response.
+ *
+ * @return true if a JSON response shall be generated, false if a 
redirect
+ * shall be sent.
+ */
+static boolean sendJsonInsteadOfRedirect() {
--- End diff --

Why static?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@struts.apache.org
For additional commands, e-mail: dev-h...@struts.apache.org



[GitHub] struts pull request: New result 'JSONActionRedirectResult' in json...

2016-01-11 Thread lukaszlenart
Github user lukaszlenart commented on a diff in the pull request:

https://github.com/apache/struts/pull/72#discussion_r49329166
  
--- Diff: 
plugins/json/src/main/java/org/apache/struts2/json/JSONActionRedirectResult.java
 ---
@@ -0,0 +1,71 @@
+package org.apache.struts2.json;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.result.ServletActionRedirectResult;
+
+/**
+ * Specialized form of {@link ServletActionRedirectResult} which takes 
care of
+ * situation that browser has a JS/AJAX context, there are no validation 
errors
+ * and action is executed. In this case a http redirect is harmful as 
browsers
+ * don't pass them to JS handlers. So this result produces a JSON response
+ * containing redirect data.
+ *
+ *
+ * To be used along with {@link JSONValidationInterceptor}.
+ *
+ *
+ * Response JSON looks like this:
+ * {"location": "$redirect url$"}
+ *
+ *
+ */
+public class JSONActionRedirectResult extends ServletActionRedirectResult {
+
+private static final long serialVersionUID = 3107276294073879542L;
+
+@Override
+   protected void sendRedirect(HttpServletResponse response, String 
finalLocation) throws IOException {
--- End diff --

Problem with indent?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: dev-unsubscr...@struts.apache.org
For additional commands, e-mail: dev-h...@struts.apache.org