This is an automated email from the ASF dual-hosted git repository.

doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git


The following commit(s) were added to refs/heads/master by this push:
     new 7e2f5e3b EMPIREDB-440 ParameterMap improvments
7e2f5e3b is described below

commit 7e2f5e3bce3d5633e4d6dcf4ac7290c6c7d65b60
Author: Rainer Döbele <[email protected]>
AuthorDate: Thu Oct 10 23:49:22 2024 +0200

    EMPIREDB-440
    ParameterMap improvments
---
 .../org/apache/empire/jsf2/components/LinkTag.java    | 17 ++++++++++++-----
 .../org/apache/empire/jsf2/pages/PageDefinition.java  | 11 ++++++-----
 .../org/apache/empire/jsf2/utils/ParameterMap.java    | 19 +++++++++++++++----
 3 files changed, 33 insertions(+), 14 deletions(-)

diff --git 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/LinkTag.java 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/LinkTag.java
index 73e5ed1e..1c1eb74f 100644
--- 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/LinkTag.java
+++ 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/LinkTag.java
@@ -36,6 +36,7 @@ import javax.faces.context.ResponseWriter;
 
 import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.commons.StringUtils;
+import org.apache.empire.exceptions.InvalidArgumentException;
 import org.apache.empire.exceptions.InvalidPropertyException;
 import org.apache.empire.jsf2.app.FacesUtils;
 import org.apache.empire.jsf2.controls.InputControl;
@@ -202,7 +203,7 @@ public class LinkTag extends UIOutput // implements 
NamingContainer
             }
             // set params
             setLinkProperties(linkComponent);
-            addOrSetParam(linkComponent, "idparam", "id");
+            addOrSetParams(linkComponent);
             // encode link
             this.encodeLinkChildren = 
isEncodeLinkChildren(linkComponent.getChildCount()>0 ? null : 
linkComponent.getValue());
             if (this.encodeLinkChildren)
@@ -333,13 +334,19 @@ public class LinkTag extends UIOutput // implements 
NamingContainer
         // include view param
         link.setIncludeViewParams(false);
     }
+
+    protected void addOrSetParams(HtmlOutcomeTargetLink link)
+    {
+        addOrSetParam(link, "id", 
StringUtils.toString(getAttributes().get("idparam")));
+    }
     
-    protected void addOrSetParam(HtmlOutcomeTargetLink link, String attribute, 
String paramName)
+    protected void addOrSetParam(HtmlOutcomeTargetLink link, String paramName, 
String paramValue)
     {
-        // Get Attribute
-        String paramValue = 
StringUtils.toString(getAttributes().get(attribute));
+        // Check params
         if (StringUtils.isEmpty(paramValue))
-            return; 
+            return; // nothing to do 
+        if (paramName==null || paramName.length()==0)
+            throw new InvalidArgumentException("paramName", paramName);
         // find attribute
         List<UIComponent> l = link.getChildren();
         for (UIComponent c : l)
diff --git 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinition.java 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinition.java
index 7e3b1fee..1a559b99 100644
--- 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinition.java
+++ 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinition.java
@@ -33,6 +33,7 @@ public class PageDefinition // *Deprecated* implements 
Serializable
        private static final Logger log = 
LoggerFactory.getLogger(PageDefinitions.class);
 
     private static final String ACTION_PARAMETER_TYPE = "ACTION";
+    private static final String ACTION_PARAMETER_NAME = "action";
     
     private final String path;
     private final String fileExtension;
@@ -62,12 +63,12 @@ public class PageDefinition // *Deprecated* implements 
Serializable
     }
     */
 
-    private static String encodeActionParam(String action)
+    private static String encodeActionParam(PageDefinition pageDef, String 
action)
     {
         ParameterMap pm = FacesUtils.getParameterMap(FacesUtils.getContext());
         if (pm==null)
             return action;
-        return pm.put(ACTION_PARAMETER_TYPE, action, true);
+        return pm.put(ACTION_PARAMETER_TYPE, 
StringUtils.concat(pageDef.getPageBeanName(), ":", action), action, true);
     }
     
     public static String decodeActionParam(String param)
@@ -184,7 +185,7 @@ public class PageDefinition // *Deprecated* implements 
Serializable
     {
         PageOutcome outcome = getOutcome();
         if (StringUtils.isNotEmpty(action))
-            outcome = outcome.addParam("action", encodeActionParam(action));
+            outcome = outcome.addParam(ACTION_PARAMETER_NAME, 
encodeActionParam(this, action));
         return outcome;
     }
     
@@ -199,7 +200,7 @@ public class PageDefinition // *Deprecated* implements 
Serializable
     {   
         PageOutcome outcome = getRedirect();
         if (StringUtils.isNotEmpty(action))
-            outcome = outcome.addParam("action", encodeActionParam(action));
+            outcome = outcome.addParam(ACTION_PARAMETER_NAME, 
encodeActionParam(this, action));
         return outcome;
     }
     
@@ -214,7 +215,7 @@ public class PageDefinition // *Deprecated* implements 
Serializable
     {
         PageOutcome outcome = getRedirectWithViewParams();
         if (StringUtils.isNotEmpty(action))
-            outcome = outcome.addParam("action", encodeActionParam(action));
+            outcome = outcome.addParam(ACTION_PARAMETER_NAME, 
encodeActionParam(this, action));
         return outcome;
     }
 
diff --git 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/ParameterMap.java 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/ParameterMap.java
index 30250d2b..130439b3 100644
--- 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/ParameterMap.java
+++ 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/ParameterMap.java
@@ -173,10 +173,10 @@ public class ParameterMap // *Deprecated* implements 
Serializable
      * @param useCache true if the keys should be cached
      * @return the encoded key
      */
-    public String put(String type, String key, boolean useCache)
+    public String put(String type, String key, String value, boolean useCache)
     {
         // Generate id and put in map
-        return encodeAndStore(type, key, key, useCache);
+        return encodeAndStore(type, key, value, useCache);
     }
 
     public Object get(String type, String id)
@@ -195,9 +195,10 @@ public class ParameterMap // *Deprecated* implements 
Serializable
     /**
      * Puts an object into the paramter map that implements the 
ParameterObject interface  
      * @param paramObject the param object
+     * @param useCache flag whether to cache the objectKey
      * @return the encoded object
      */
-    public String put(ParameterObject paramObject)
+    public String put(ParameterObject paramObject, boolean useCache)
     {
         String objectKey;
         // check param
@@ -205,7 +206,17 @@ public class ParameterMap // *Deprecated* implements 
Serializable
             throw new InvalidArgumentException("paramObject", paramObject);
         // Generate id and put in map
         String type = paramObject.getClass().getName();
-        return encodeAndStore(type, objectKey, paramObject, false);
+        return encodeAndStore(type, objectKey, paramObject, useCache);
+    }
+    
+    /**
+     * Puts an object into the paramter map that implements the 
ParameterObject interface  
+     * @param paramObject the param object
+     * @return the encoded object
+     */
+    public String put(ParameterObject paramObject)
+    {
+        return put(paramObject, false);
     }
 
     /**

Reply via email to