Re: the choices is key instead of value when using DropDownChoice component

2018-01-29 Thread extraquoo
Hi ,just ignore my last reply. 

I should not override localizeDisplayValues to return true so as not to
execute
display = getLocalizer().getString(displayValue, this, displayValue);.

your code is really helpful. Thank you very much indeed.

--
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



Re: the choices is key instead of value when using DropDownChoice component

2018-01-29 Thread extraquoo
yes, it is hard to explain the issue. 
the situation is if I put the key in the choices, then the i18n works fine
for the front page ( when I click the locale change button ,the option got
translated correctly), however ,since the key is in the choices, in pdf, it
prints the verbiage key "forms.cf37.question8.oneTimeOrMonthly" instead of
exact verbiages.

if I put the value in the choices, then the verbiage prints on the pdf is
correct because the value is rendered.
however, the i18n does not work because the value is in the choices and when
executing

"display = getLocalizer().getString(displayValue, this, displayValue);"

Here, displayValue carries the value and getString method will not work
appropriately. which means the verbiage of the options will not change
correspondingly  when I click the button.

I am think is it possible to put the key
"forms.cf37.question8.oneTimeOrMonthly"  in the choices, and then when
selecting the option in the page, render the exact value to the
dropdownchoice object ?


--
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



Re: the choices is key instead of value when using DropDownChoice component

2018-01-29 Thread Sven Meier
You wrote: "However, the choices object carries the key instead of the 
value in the backend."


What do you want written into your object? The key, e.g. 
"forms.cf37.question8.oneTimeOrMonthly"? Then your first solution should 
work.


If you want the value in your object's property, e.g. "One time or 
ongoing payment:", then my suggestion should work.


I'm confused what you're looking for. Can you create a quickstart?

Sven


Am 29.01.2018 um 19:06 schrieb extraquoo:

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 selector = new DropDownChoice(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 objectClass = (Class)(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");

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


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-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



Re: the choices is key instead of value when using DropDownChoice component

2018-01-29 Thread extraquoo
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 selector = new DropDownChoice(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 objectClass = (Class)(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");

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


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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: the choices is key instead of value when using DropDownChoice component

2018-01-26 Thread Sven Meier

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


    return selectionDescription;
    }
};

DropDownChoice selector = new DropDownChoice(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 objectClass = (Class)(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");

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

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



Re: the choices is key instead of value when using DropDownChoice component

2018-01-25 Thread 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 objectClass = (Class)(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");

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

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



Re: the choices is key instead of value when using DropDownChoice component

2018-01-24 Thread Sven Meier
Hi,

put the localized values into the choices:

selectionDescription.add(getString("forms.cf37.question8.oneTime"));

Even better, put the above inside a ReadOnlyModel's getObject().

Have fun
Sven


⁣Gesendet mit Blue ​

Am 25. Jan. 2018, 07:50, um 07:50, extraquoo  schrieb:
>Hi
>I am adding a FormComponent DropDownChoice to display a dropdown list
>on
>the page like below
>
>
>
>To support the i18n, I  add the key to a list of choices and override
>the
>localizeDisplayValues, the code is below
>
>private FormComponent getQuestion8Select(String fieldName,
>   IModel parent) {
>
>   List selectionDescription = new ArrayList();
>   selectionDescription.add("forms.cf37.question8.oneTime");
>   
> selectionDescription.add("forms.cf37.question8.otherSourcemonthly");
>   DropDownChoice selector = new
>DropDownChoice(fieldName,
>selectionDescription){
>   private static final long serialVersionUID = 1L;
>   @Override
>   protected boolean 
> localizeDisplayValues() {
>   return true;
> }
>   };
>
>return selector;
>   }
>
>the key forms.cf37.question8.oneTime and
>forms.cf37.question8.otherSourcemonthly has different values in
>corresponding XML files.
>  .xml
>One time or ongoing
>payment:
>One time payment
>_es.xml
>Pago de solo una vez
>o
>pago mensual:
>Pago de solo una vez
>
>When I switch the locale to Spanish, the verbiage changes well on the
>HTML.
>
>
>
>However, the choices object carries the key instead of the value in the
>backend.
>
>Is there anything I miss to code for the DropDownChoice?  The choices
>need
>to carry the exact values.
>
>
>
>--
>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