You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Sven Meier (JIRA)" <ji...@apache.org> on 2018/08/18 20:59:00 UTC

[jira] [Comment Edited] (WICKET-6580) org.apache.wicket.util.lang.Bytes - toString()

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

Sven Meier edited comment on WICKET-6580 at 8/18/18 8:58 PM:
-------------------------------------------------------------

You'll have to override Form#createConverter(), otherwise the value will not be formatted in the client's locale anyway:
{code:java}
@Override
protected IConverter<?> createConverter(Class<?> type) {
    if (type == Bytes.class) {
        return new IConverter<Bytes>() {
            @Override
            public Bytes convertToObject(String value, Locale locale) throws ConversionException {
               throw new UnsupportedOperationException();
            }
            public String convertToString(Bytes value, Locale locale) {
                return /* format bytes as string */;
            }
        };
    }
    return super.createConverter(type);
}{code}


was (Author: svenmeier):
You'll have to overrider Form#createConverter(), otherwise the value will not be formatted in the client's locale anyway:
{code:java}
@Override
protected IConverter<?> createConverter(Class<?> type) {
    if (type == Bytes.class) {
        return new IConverter<Bytes>() {
            @Override
            public Bytes convertToObject(String value, Locale locale) throws ConversionException {
               throw new UnsupportedOperationException();
            }
            public String convertToString(Bytes value, Locale locale) {
                return /* format bytes as string */;
            }
        };
    }
    return super.createConverter(type);
}{code}

> org.apache.wicket.util.lang.Bytes - toString()
> ----------------------------------------------
>
>                 Key: WICKET-6580
>                 URL: https://issues.apache.org/jira/browse/WICKET-6580
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket
>    Affects Versions: 7.9.0
>            Reporter: Peter Bozik
>            Priority: Major
>
> It is not possible to override how the Bytes class is translated to String.
> we would like to override wicket message *uploadSingleFileTooLarge* about big file and we would like to use form field ${fileMaxSize}. Our max limit is specified in megabytes and as it is specified in wiki ([https://en.wikipedia.org/wiki/Megabyte)] - the recommended unit symbol is *MB*, not *M*
> we know, we can change our message to ...${fileMaxSize}B ... but then in case of value in bytes we would get ... 10 bytesB ...
>  
> also there is no space between value and units except bytes so we would like to add it there so we would get e.g. (10 MB, 10 KB, 10 bytes). Current state is (10M, 10K, 10 bytes)
>  
> thank you for consideration of this kind of improvement



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)