Yep, you read that right. I just found out that if you explicitly
define an id attribute on your component, getMarkupId still just
returns a generated one. This suprises me; I'm pretty sure we always
agreed that if an explicit id is provided in the markup, that should
be used. See the date picker in wicket-examples/forminput for example:
it doesn't work now because the id is set to "dateProperty" but
getMarkupId, which is used by the date picker, returns
"dateProperty1".

The fix is easy[1], but results in a failing unit test. Imho, that
unit test is just too fragile, and I'm thinking about implementing a
quick fix for it and submit this change. But I wanted to check here
first in case I'm overlooking something.

Eelco

[1]
Index: 
/Users/eelcohillenius/Documents/workspace_wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Component.java
===================================================================
--- 
/Users/eelcohillenius/Documents/workspace_wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Component.java
        (revision
550266)
+++ 
/Users/eelcohillenius/Documents/workspace_wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/Component.java
        (working
copy)
@@ -1181,10 +1181,13 @@

        /**
         * Retrieves id by which this component is represented within the 
markup.
+        * This is either the id attribute if it is set explicitly in the 
markup, or
+        * a generated id.
         * <p>
         * The point of this function is to generate a unique id to make it 
easy to
         * locate this component in the generated markup for post-wicket 
processing
-        * such as javascript or an xslt transform.
+        * such as javascript or an xslt transform in case no explicit id was 
set
+        * yet.
         * <p>
         * Note: This method should only be called after the component or its 
parent
         * have been added to the page.
@@ -1204,7 +1207,13 @@
                                                                + "to find the page 
it is supposed to operate in before you can call "
                                                                + "this method 
(Component#getMarkupId)");
                        }
-                       markupId = getId() + page.getAutoIndex();
+                       // try to read from markup
+                       markupId = getMarkupAttributes().getString("id");
+                       if (markupId == null)
+                       {
+                               // if not in the markup, generate one
+                               markupId = getId() + page.getAutoIndex();
+                       }
                        setMetaData(MARKUP_ID_KEY, markupId);
                }
                return markupId;

Reply via email to