I'm working on a Spring MVC Project and ran into a problem with the internationalization in forms, especially the number formatting.
I already use fmt:formatNumber to format the numbers according to the current selected locale.
<fmt:formatNumber value="${object[field]}"/>
Like this, number formatting works well when I display numbers. But how about the forms?
At the moment, the input fields that are supposed to receive float values are prefilled with 0.0 and expect me to use "." as decimal separator, no matter what locale is selected. Values containing "," are refused by the server (...can not convert String to required type float...).
How can I make my input fields use and accept the appropriate number format as well?
Did you have a look at #NumberFormat? If you annotate the property the input field is bound to, this should result in the proper formatting. Something like:
#NumberFormat(style = Style.NUMBER)
private BigDecimal something;
This style is the "general-purpose number format for the current locale". I guess, the current locale is determined threadwise from the LocaleContextHolder.
Your app needs to be annotation-driven, also see the section "Annotation-driven Formatting" in the docs.
You might want to take a look at the DecimalFormatSymbols as suggested in this answer.
Related
TYPO3 8.7.x, Powermail 6.0.0
I'd like to override the receiver based on two subjects they can select.
Now I know that this works just fine:
[globalString = GP:tx_powermail_pi1|field|konsilbereich = 5]
But this does not seem to work:
[globalString = GP:tx_powermail_pi1|field|konsilbereich = "Some phrase"]
I read that some workarounds were to have a hidden field that's been filled by Javascript upon a users selection and instead of the actual field, the hidden field gets submitted. But that is not an option for us.
I checked the docs as well as many support forums but could not find a good answer to this.
Is this not possible, or if, how would I accomplish that I can use an actual string within the comparison?
The problem is a comparisation with a string in TypoScript conditions. Strings could have space, special characters or umlauts. That's why TypoScript works best with integers.
Two possibilities come into my mind for your case:
1) Building an own conditition is quite simple in TYPO3 (see https://docs.typo3.org/typo3cms/TyposcriptReference/latest/Conditions/Reference.html#custom-conditions for an easy example)
2) Use an integer together with GP: - but then I would use a selectbox with a text as label and a number as value
I am storing XBRL JSON using elasticsearch.
This xBRL-JSON OIM spec describes the oim:period property:
Otherwise, an ISO 8601 time interval representing the {interval}
property, expressed in one of the following forms:
<start>/<end>
<start>/<duration>
<duration>/<end>
Where <start> and <end> are valid according to the xsd:dateTime datatype, and <duration> is valid according to xsd:duration.
Examples from arelle's plugin look like this:
2016-01-01T00:00:00/PT0S
2015-01-01T00:00:00/P1Y
I notice that arelle's plugin exclusively produces this format:
<start>/<duration>
My question
Is there a way to save at least the <start> part as a date type in elasticsearch?
Ideas I had:
elastichsearch only (my preference)
Use a custom date format which anticipates the /<duration> part, but ignores it
I haven't checked Joda yet; will it ignore characters in the date format if they aren't part of the special character? Like the "/" delimiter or the "P" which precedes any duration value (like PT0S and P1Y above)?
EDIT So the single-quote character escapes literals; this works yyyy'/P' will accept a value '2015/P'. However, the rest of the duration could be more dynamic
Re: dynamic; will Joda accept regex or wildcard character like "\d" or "+" qualifier so I can ignore all the possible variations following the P?
Use a character filter to strip out the /<duration> part before saving only <start>as datetime. But I don't know if character filters happen before saving as type: date. If they don't, the '/`part isn't stripped, and I wouldn't be passing valid date strings.
Don't use date type: Use a pattern tokenizer to split on /, and at least the two parts will be saved as separate tokens. Can't use date math, though.
Use a transformation; although it seems like this is deprecated. I read about using copy_to instead, but that seems to combine terms, and I want to break this term apart
Some sort of plugin? Maybe a plugin which will fully support this "interval" datatype described by the OIM spec... maybe a plugin which will store its separate parts...?
change my application (I prefer to use elasticsearch-only techniques if possible)
I could edit this plugin or produce my own plugin which uses exclusively <start> and <end> parts, and saves both into separate fields;
But this breaks the OIM spec, which says they should be combined in a single field
Moreover it can be awkward to express an "instant" fact (with no duration; the PT0S examples above); I guess I just use the same value for end property as start property... Not more awkward than a 0-length duration (PT0S) I guess.
Not a direct answer, but it's worth noting that the latest internal drafts of the xBRL-JSON specification have moved away from the the single-field representation. Although the "/" separated notation is an ISO standard, tool support for it appears to be extremely poor, and so the working group has chosen to switch to separate fields for start and end dates. I would expect Arelle support to follow suit in due course.
I am pulling my head for below problem.
I have text box in my application that will take time in the format 1(days):23(hours): 15(minutes).
I want to apply validation for this field so it will take string in the format [01:05:15/ 1:4:30] only.
Please tell me the workaround for this.
You can use separator like below.
^([0-2]\d?|3[01]):([0-1]\d?|2[0-3]):(00?|15|30|45)$
If you need more information check below.
http://msdn.microsoft.com/en-us/library/hs600312(v=vs.110).aspx
http://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110).aspx
What is the default regular expression used by asp.net create user wizard?
According to the MSDN documentation, it should be something like this:
Regular Expression: #\"(?:.{7,})(?=(.*\d){1,})(?=(.*\W){1,})
Validation Message: Your password must be 7 characters long, and contain at least one number and one special character.
However, it does not work as it does not accept something like 3edc£edc, which is actually accepted when using the default create user wizard.
Any idea about how can I get this regular expression?
The error is in the ?: in (?:.{7,})(?=(.*\d){1,})(?=(.*\W){1,}) that is "consuming" the fist seven characters or more characters. It should be ?= OR you can invert the order: (?=(.*\d){1,})(?=(.*\W){1,})(?:.{7,})
Just change the order
^(?=(.*\d))(?=(.*\W)).{7,}
I additionally removed the {1,} and anchored it to the start of the string and you don't need a group around the last part
See it here on Regexr
My application is currently displaying negative numbers as -1. The users have changed the requirements (just for a change!) and now we will have to display the numbers as (1).
Can I enable that for the whole application say changing the web.config or even the app's CultureInfo ? Is there any side effect of doing that since we have lots of pages that contain number validators ?
Thanks !
For currency it is really easy:
String.Format("{0:C}", value)
This will use the culture info for the system.
For normal numbers being data bound, use Mark Glorie's sample.
MSDN Article
I'd use String formatting. Making a change to the application's configuration to satisfy a UI requirement is heavy-handed. SteveX wrote a great blog post about String formatting. It's also compatible with markup (aspx) instead of only relevant in code.
From his post:
String.Format(”{0:$#,##0.00;($#,##0.00);Zero}”, value);
This will output “$1,240.00″ if passed 1243.50. It will output the
same format but in parentheses if the number is negative, and will
output the string “Zero” if the number is zero.
Which isn't exactly what you want, but it's close.
Check this..
http://msdn.microsoft.com/en-us/library/91fwbcsb.aspx
Converts the string representation of a number in a specified style to its Decimal equivalent.
I've got the following page bookmarked for doing string formatting: http://idunno.org/archive/2004/14/01/122.aspx
About halfway down, it gives the answer:
String.Format("{0:£#,##0.00;(£#,##0.00);Nothing}", value);
To answer your other question, I wouldn't modify the app.config to make it global, for reasons given in the other answers.
String.Format(”{0:f;(f);0”, -1);
This works.
DataFormatString="{0:c0}"
Nagative amounts in paranthesis
Thousand separater - comma
$ symbol in front
You could always write your own custom ToString() method as an extension method, but like you mention, using CultureInfo is probably better. Take a look here:
http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.numbernegativepattern.aspx
Are you displaying your data in Gridview/Datagrids? If so then formatting can be applied per bound-column, something like:
<asp:BoundField DataFormatString="{##;(##)}"/>
This only works with integers however...