wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From extraquoo <extraq...@gmail.com>
Subject Re: the choices is key instead of value when using DropDownChoice component
Date Mon, 29 Jan 2018 18:06:27 GMT
thanks for replying. 
Looks like it still put the value in the choices object.
Maybe I am describing the issue incorrectly.

so if put value in the choices object , construct the DropDownChoice and
override localizeDisplayValues
DropDownChoice<String> selector = new DropDownChoice<String>(fieldName,
choices){

			private static final long serialVersionUID = 1L;

			@Override
			protected boolean localizeDisplayValues() {
				return true;
			}
		};

then it wont support i18n when executing below code of AbstractChoice.class

/**
	 * Generates and appends html for a single choice into the provided buffer
	 * 
	 * @param buffer
	 *            Appending string buffer that will have the generated html
appended
	 * @param choice
	 *            Choice object
	 * @param index
	 *            The index of this option
	 * @param selected
	 *            The currently selected string value
	 */
	@SuppressWarnings("unchecked")
	protected void appendOptionHtml(AppendingStringBuffer buffer, E choice, int
index,
		String selected)
	{
		T objectValue = (T)renderer.getDisplayValue(choice);
		Class<T> objectClass = (Class<T>)(objectValue == null ? null :
objectValue.getClass());

		String displayValue = "";
		if (objectClass != null && objectClass != String.class)
		{
			final IConverter converter = getConverter(objectClass);

			displayValue = converter.convertToString(objectValue, getLocale());
		}
		else if (objectValue != null)
		{
			displayValue = objectValue.toString();
		}
		buffer.append("\n<option ");
		if (isSelected(choice, index, selected))
		{
			buffer.append("selected=\"selected\" ");
		}
		if (isDisabled(choice, index, selected))
		{
			buffer.append("disabled=\"disabled\" ");
		}
		buffer.append("value=\"");
		buffer.append(Strings.escapeMarkup(renderer.getIdValue(choice, index)));
		buffer.append("\">");

		String display = displayValue;
		if (localizeDisplayValues())
		{
			*display = getLocalizer().getString(displayValue, this, displayValue);*
		}
		CharSequence escaped = display;
		if (getEscapeModelStrings())
		{
			escaped = escapeOptionHtml(display);
		}
		buffer.append(escaped);
		buffer.append("</option>");
	}


the bold line is using getString and here displayValue should be the key not
the value.



--
Sent from: http://apache-wicket.1842946.n4.nabble.com/Users-forum-f1842947.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Mime
View raw message