Author: nilsga
Date: Tue Jan 8 00:18:23 2008
New Revision: 609901
URL: http://svn.apache.org/viewvc?rev=609901&view=rev
Log:
WW-2370 Using the name of the current executing action in the url when no
action is specified.
Modified:
struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java
struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java
Modified:
struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java?rev=609901&r1=609900&r2=609901&view=diff
==
---
struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java
(original)
+++
struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java
Tue Jan 8 00:18:23 2008
@@ -20,6 +20,8 @@
*/
package org.apache.struts2.components;
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.util.TextUtils;
import org.apache.struts2.StrutsException;
import org.apache.struts2.portlet.util.PortletUrlHelper;
@@ -46,11 +48,14 @@
}
String result;
-if (urlComponent.value == null && urlComponent.action != null) {
+if (onlyActionSpecified(urlComponent)) {
result = PortletUrlHelper.buildUrl(urlComponent.action,
urlComponent.namespace, urlComponent.method, urlComponent.parameters,
urlComponent.portletUrlType, urlComponent.portletMode,
urlComponent.windowState);
-} else {
+} else if(onlyValueSpecified(urlComponent)){
result = PortletUrlHelper.buildResourceUrl(urlComponent.value,
urlComponent.parameters);
}
+else {
+ result = createDefaultUrl(urlComponent);
+}
if ( urlComponent.anchor != null && urlComponent.anchor.length() > 0 )
{
result += '#' + urlComponent.anchor;
}
@@ -71,14 +76,34 @@
}
}
+ private String createDefaultUrl(URL urlComponent) {
+ String result;
+ ActionInvocation ai =
(ActionInvocation)urlComponent.getStack().getContext().get(
+ ActionContext.ACTION_INVOCATION);
+ String action = ai.getProxy().getActionName();
+ result = PortletUrlHelper.buildUrl(action,
urlComponent.namespace, urlComponent.method, urlComponent.parameters,
urlComponent.portletUrlType, urlComponent.portletMode,
urlComponent.windowState);
+ return result;
+ }
+
+ private boolean onlyValueSpecified(URL urlComponent) {
+ return urlComponent.value != null && urlComponent.action ==
null;
+ }
+
+ private boolean onlyActionSpecified(URL urlComponent) {
+ return urlComponent.value == null && urlComponent.action !=
null;
+ }
+
/**
* [EMAIL PROTECTED]
*/
public void renderFormUrl(Form formComponent) {
String action = null;
if (formComponent.action != null) {
-// if it isn't specified, we'll make somethig up
action = formComponent.findString(formComponent.action);
+}
+else {
+ ActionInvocation ai = (ActionInvocation)
formComponent.getStack().getContext().get(ActionContext.ACTION_INVOCATION);
+ action = ai.getProxy().getActionName();
}
String type = "action";
Modified:
struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java?rev=609901&r1=609900&r2=609901&view=diff
==
---
struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java
(original)
+++
struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java
Tue Jan 8 00:18:23 2008
@@ -20,7 +20,6 @@
*/
package org.apache.struts2.views.jsp;
-import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
@@ -48,11 +47,14 @@
import com.mockobjects.servlet.MockJspWriter;
import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.ValueStackFactory;
/**
*/
[EMAIL PROTECTED]("unchecked")
public class PortletUrlTagTest extends MockObjectTestCase {
URLTag tag