IModel<List<String>> choices = new AbstractReadOnlyModel<List<String>> {
    public List<String> getObject() {
        List<String> selectionDescription = new ArrayList<String>();
selectionDescription.add(getString("forms.cf37.question8.oneTime"));
selectionDescription.add(getString("forms.cf37.question8.otherSourcemonthly"));
        return selectionDescription;
    }
};

DropDownChoice<String> selector = new DropDownChoice<String>(fieldName, choices){
}

Have fun
Sven


Am 25.01.2018 um 18:38 schrieb extraquoo:
Hi, I try to use GetString / StringResourceModel and put the key
selectionDescription.add(new
StringResourceModel("forms.cf37.question8.oneTime",this,parent).getObject());
or
selectionDescription.add(getString("forms.cf37.question8.oneTime"));

Both of them will return the values from xml
however ,it doesn't support locale change in the pape because  it will
execute the wicket library class AbstractChoice and run below method:

/**
         * 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>");
        }

Here, localizeDisplayValues is overrided to return true, so it will run
display = getLocalizer().getString(displayValue, this, displayValue);
displayValue is the key so in the DropDownChoice options ,it needs to put
the key instead of value to support i18n.
any advice ?


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

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



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

Reply via email to