[ 
https://issues.apache.org/jira/browse/WICKET-2772?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12924304#action_12924304
 ] 

Hudson commented on WICKET-2772:
--------------------------------

Integrated in Apache Wicket 1.5.x #449 (See 
[https://hudson.apache.org/hudson/job/Apache%20Wicket%201.5.x/449/])
    WICKET-2776 Enhancing RadioChoice input items with individual title and css 
class attributes

Merge from 1.4.x:
and WICKET-2772
Issue: WICKET-2776
Files Changed
MODIFY 
/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioChoice.java

ASF     #922649 Sat Mar 13 13:50:47 EST 2010    jdonnerstag      added 
additional attributes to allow for index dependent attributes
Issue: WICKET-2776
Files Changed
MODIFY 
/wicket/branches/wicket-1.4.x/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioChoice.java


> Generate wicketpath attribute for RadioChoice
> ---------------------------------------------
>
>                 Key: WICKET-2772
>                 URL: https://issues.apache.org/jira/browse/WICKET-2772
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.4.7
>            Reporter: Julian Sinai
>            Assignee: Juergen Donnerstag
>            Priority: Minor
>             Fix For: 1.4.8, 1.5-M1
>
>
> Wicket has a convenient feature to make using Selenium IDE easy to use. By 
> adding getDebugSettings().setOutputComponentPath(true) to your application, 
> the wicketpath attribute is emitted.
> Unfortunately, that does not hold for the radios inside a RadioChoice because 
> they are not proper Components.
> Also unfortunately, RadioChoice.onComponentTagBody() is final.
> The result is that you either have to write additional xpath selectors, or 
> clone RadioChoice and extend AjaxFormChoiceComponentUpdatingBehavior.
> The following code, added to RadioChoice.onComponentTagBody(), solves the 
> problem. It is similar to the same code in Component, but appends a bit more 
> to the path for the input tags:
> if (getApplication().getDebugSettings().isOutputComponentPath())
> {
>       String path = getPageRelativePath();
>       path = path.replace("_", "__");
>       path = path.replace(":", "_");
>       buffer.append(" wicketpath=\"")
>       .append(path)
>       .append("_input_")
>       .append(index)
>       .append("\"");
> }
> The full code for RadioChoice.onComponentTagBody() is as follows:
>       @Override
>       protected final void onComponentTagBody(final MarkupStream markupStream,
>               final ComponentTag openTag)
>       {
>               // Iterate through choices
>               final List<? extends T> choices = getChoices();
>               // Buffer to hold generated body
>               final AppendingStringBuffer buffer = new 
> AppendingStringBuffer((choices.size() + 1) * 70);
>               // The selected value
>               final String selected = getValue();
>               // Loop through choices
>               for (int index = 0; index < choices.size(); index++)
>               {
>                       // Get next choice
>                       final T choice = choices.get(index);
>                       Object displayValue = 
> getChoiceRenderer().getDisplayValue(choice);
>                       Class<?> objectClass = (displayValue == null ? null : 
> displayValue.getClass());
>                       // Get label for choice
>                       String label = "";
>                       if (objectClass != null && objectClass != String.class)
>                       {
>                               final IConverter converter = 
> getConverter(objectClass);
>                               label = converter.convertToString(displayValue, 
> getLocale());
>                       }
>                       else if (displayValue != null)
>                       {
>                               label = displayValue.toString();
>                       }
>                       // If there is a display value for the choice, then we 
> know that the
>                       // choice is automatic in some way. If label is /null/ 
> then we know
>                       // that the choice is a manually created radio tag at 
> some random
>                       // location in the page markup!
>                       if (label != null)
>                       {
>                               // Append option suffix
>                               buffer.append(getPrefix());
>                               String id = 
> getChoiceRenderer().getIdValue(choice, index);
>                               final String idAttr = getMarkupId() + "-" + id;
>                               boolean enabled = isEnabledInHierarchy() && 
> !isDisabled(choice, index, selected);
>                               // Add radio tag
>                               buffer.append("<input name=\"")
>                                       .append(getInputName())
>                                       .append("\"")
>                                       .append(" type=\"radio\"")
>                                       .append((isSelected(choice, index, 
> selected) ? " checked=\"checked\"" : ""))
>                                       .append((enabled ? "" : " 
> disabled=\"disabled\""))
>                                       .append(" value=\"")
>                                       .append(id)
>                                       .append("\" id=\"")
>                                       .append(idAttr)
>                                       .append("\"");
>                               // Should a roundtrip be made (have 
> onSelectionChanged called)
>                               // when the option is clicked?
>                               if (wantOnSelectionChangedNotifications())
>                               {
>                                       CharSequence url = 
> urlFor(IOnChangeListener.INTERFACE);
>                                       Form<?> form = findParent(Form.class);
>                                       if (form != null)
>                                       {
>                                               RequestContext rc = 
> RequestContext.get();
>                                               if (rc.isPortletRequest())
>                                               {
>                                                       // restore url back to 
> real wicket path as its going to be interpreted
>                                                       // by the form itself
>                                                       url = 
> ((PortletRequestContext)rc).getLastEncodedPath();
>                                               }
>                                               buffer.append(" 
> onclick=\"").append(form.getJsForInterfaceUrl(url)).append(
>                                                       ";\"");
>                                       }
>                                       else
>                                       {
>                                               // TODO: following doesn't work 
> with portlets, should be posted to a dynamic
>                                               // hidden form
>                                               // with an ActionURL or 
> something
>                                               // NOTE: do not encode the url 
> as that would give
>                                               // invalid JavaScript
>                                               buffer.append(" 
> onclick=\"window.location.href='")
>                                                       .append(url)
>                                                       .append(
>                                                               
> (url.toString().indexOf('?') > -1 ? "&amp;" : "?") + getInputName())
>                                                       .append("=")
>                                                       .append(id)
>                                                       .append("';\"");
>                                       }
>                               }
>                               //  ADDED BY JULIAN TO OUTPUT THE WICKET:PATH 
> ATTRIBUTE TO EASE SELENIUM TESTING.
>                               if 
> (getApplication().getDebugSettings().isOutputComponentPath())
>                               {
>                                       String path = getPageRelativePath();
>                                       path = path.replace("_", "__");
>                                       path = path.replace(":", "_");
>                                       buffer.append(" wicketpath=\"")
>                                       .append(path)
>                                       .append("_input_")
>                                       .append(index)
>                                       .append("\"");
>                               }
>                               buffer.append("/>");
>                               // Add label for radio button
>                               String display = label;
>                               if (localizeDisplayValues())
>                               {
>                                       display = 
> getLocalizer().getString(label, this, label);
>                               }
>                               final CharSequence escaped;
>                               if (getEscapeModelStrings())
>                               {
>                                       escaped = Strings.escapeMarkup(display, 
> false, true);
>                               }
>                               else
>                               {
>                                       escaped = display;
>                               }
>                               buffer.append("<label 
> for=\"").append(idAttr).append("\">").append(escaped).append(
>                                       "</label>");
>                               // Append option suffix
>                               buffer.append(getSuffix());
>                       }
>               }
>               // Replace body
>               replaceComponentTagBody(markupStream, openTag, buffer);
>       }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to