String display = getLocalizer().getString(label, this, label);
String escaped = Strings.escapeMarkup(display, false, true);
buffer.append("<label for="" + idAttr + "\">" + escaped + "</label>");
johan
On 1/17/06,
Sven Meier <[EMAIL PROTECTED]> wrote:
Thanks Johan, I really think this change will prove itself useful.
I don't want to be picky, but one additional thing:
The converted value should be escaped too. Otherwise we might end up with invalid HTML, since AFAIK converters are not required to produce escaped strings.
This is why my initial proposal included splitting the current converting-AND-escaping functionality from
Component#getModelObjectAsString() into a new method and reuse it for the display of choices:
/**
* Gets a model object as a string.
*
* @return Model object for this component as a string
*/
public final String getModelObjectAsString()
{
return convert(getModelObject());
}
/**
* Convert the given object into a string.
*
* @param value
* The value to convert
* @return The converted value
*/
protected final String convert(Object object)
{
if (object != null)
{
// Get converter
final IConverter converter = getConverter();
// Model string from property
final String modelString = (String)converter.convert(object, String.class);
// If we should escape the markup
if (getFlag(FLAG_ESCAPE_MODEL_STRINGS))
{
// Escape it
return Strings.escapeMarkup(modelString);
}
return modelString;
}
return "";
}
Then in AbstractChoice (and similar in subclasses) instead of:
* final* String displayValue = (String)getConverter().convert(renderer.getDisplayValue(choice), String.*class*);
... we could just do:
final String displayValue = convert(renderer.getDisplayValue(choice));
Simpler to read and escaping already included. What do you think?
Sven
Johan Compagner wrote:
>ok i changed it so that the convert is being used to "format" the values
>once more:
>
>I didn't change a lot only a few falles to getDisplayValue:
>final String displayValue = (String)getConverter().convert(
>renderer.getDisplayValue(choice), String.class);
>
>And ofcourse the getDisplayValue() return type itself.
>
>johan
>
>
>On 1/16/06, Johan Compagner <[EMAIL PROTECTED]> wrote:
>
>
>>the only thing i could think of now is when you have a list of Dates or
>>numbers.
>>Then choice rendered getDisplayValue return just the date but the
>>converter converts it to the right type
>>that the date/number converters with a locale specifies.
>>That would be nice yes.
>>
>>The problem is that we do break api again then.. But we are on that way
>>anyway.
>>
>>johan
>>
>>
>>
>>
>>On 1/16/06, Johan Compagner <[EMAIL PROTECTED]> wrote:
>>
>>
>>>What do you want to convert?
>>>The id or the display value??
>>>
>>>The converter is used for things what a person can type and that is not
>>>the case with a drop down.
>>>So in the dropdown world the id would need to be converted because THAT
>>>is the model object.
>>>The display object has nothing to do with the model object it is just a
>>>visual representation.
>>>
>>>The id generation is just there because we need to push things to the
>>>client..
>>>
>>>But to make an example what do you expect or want to do here
>>>
>>>I have a List of persons that has a getName() and a getId()
>>>
>>>now i do just this
>>>
>>>new ChoiceRenderer("name", "id")
>>>
>>>What should the converter then do more? Should it go over the name? What
>>>should it do there?
>>>Again Normally with all other fields a convert works on the model object
>>>and that is more or less more
>>>the id then the display value.
>>>
>>>Just youre statement that
>>>"IMHO ChoiceRenderer could do better than simply using toString() to
>>>produce a display value (see line 152). Why not utilize converters
>>>instead?"
>>>
>>>is just not true the choice rendere doesn't use toString()
>>>
>>>But i would love to see an example where it would really be usefull.
>>>
>>>johan
>>>
>>>
>>>
>>>On 1/16/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>>>
>>>
>>>>>The renderer is just as in Swing so the renderer should return the
>>>>>display value.
>>>>>
>>>>>
>>>>A Swing renderer isn't responsible to generate ids.
>>>>
>>>>
>>>>
>>>>>Why would you go through the renderer then if you want to use the
>>>>>converter for this?
>>>>>
>>>>>
>>>>The renderer currently has three responsibilities:
>>>>-It has to generate an id.
>>>>-It has to locate the value to use for displaying, e.g. you're able to
>>>>select a customer but the name of the customer should be displayed.
>>>>-It has to format the display value.
>>>>
>>>>But why impose the latter?
>>>>
>>>>
>>>>
>>>>>The problem is then that the display value is easy. >
>>>>>
>>>>>
>>>>converter.convert(choice, String.class)
>>>>
>>>>
>>>>>but the id value how is that again got from it then we need a class
>>>>>
>>>>>
>>>>type >so that we can do converter.convert (choice,Int.class)
>>>>
>>>>I propose to reuse converters for generating the display value ONLY.
>>>>The id generation has nothing to do with formatting and is best left the way
>>>>it works now.
>>>>
>>>>
>>>>
>>>>>But i think this will be much harder to understand for people.
>>>>>
>>>>>
>>>>I find it difficult to understand that DropDownChoice and its
>>>>subclasses don't use the converter infrastructure.
>>>>Imagine prices, dates or currencies in an HTML select - why aren't
>>>>they formatted the same ways as in TextFields or Labels?
>>>>
>>>>Sven
>>>>
>>>>
>>>>-------------------------------------------------------
>>>>This SF.net email is sponsored by: Splunk Inc. Do you grep through log
>>>>files
>>>>for problems? Stop! Download the new AJAX search engine that makes
>>>>searching your log files as easy as surfing the web. DOWNLOAD
>>>>SPLUNK!
>>>>http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
>>>>_______________________________________________
>>>>Wicket-user mailing list
>>>>[email protected]
>>>> https://lists.sourceforge.net/lists/listinfo/wicket-user
>>>>
>>>>
>>>>
>>>
>>>
>
>
>
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user
