Calculator and decimal separator

Community Driven Extensions Project
Post Reply
tdtappe
Posts: 29
Joined: 12 Sep 2011, 09:08

28 Jan 2019, 13:35

How can I explicitly set the decimal separator (and thousand separator) for a calculator bound to a p:inputText? Otherwise the calculator even "swallows" the decimal separator (for me: ",") when entered on the input field.

--Heiko
Using
Primefaces 6.2.14
Extensions 6.2.10
Mojarra 2.2.13
Wildfly 13.0.0.Final

User avatar
Melloware
Posts: 997
Joined: 22 Apr 2013, 15:48

28 Jan 2019, 14:33

Can you paste your snippet of the calculator so I can see it?

Also have you tried setting the locale="" of the Calculator?
PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 6.2.19 / PF Extensions 6.2.10

tdtappe
Posts: 29
Joined: 12 Sep 2011, 09:08

29 Jan 2019, 10:10

Yes. I also tried to set the locale. Without success.

I should have mentioned that I set the calculator on an inputText that's inside a composite in the first place (see below). Sorry for that!

Code: Select all

                   <tdInput:weight id="weight" value="#{orderListHandler.simpleOrderHandler.workingObject.currentOrder.orderControl.transportOrder.consignmentItemsRW[0].weight}" displayMode="compact" label="#{bundles.messages['weight']}" />
                   <pe:calculator for="weight:weight" showOn="button" />
Here's the composite "tdInput:weight":

Code: Select all

<composite:interface>
		<composite:attribute name="value" required="true" />
		<composite:attribute name="disabled" default="false" />
		<composite:attribute name="calculated" default="false" />
		<composite:attribute name="calculatedValue" />
		<composite:attribute name="calculatedLabel" default="#{bundles.messages['calculated']}" />
		<composite:attribute name="displayMode" required="false" shortDescription="Defines the size/width of the component. Possible values: 'compact', 'normal'. Default is 'normal'" />
		<composite:attribute name="unit" default="#{defaultWeightUnit}" type="net.transdata.komalog.ui.converter.WeightUnit" />
		<composite:attribute name="returnType" default="WEIGHT" shortDescription="Type of value object. WEIGHT and DOUBLE supported." />
		<composite:attribute name="style" required="false"/>
		<composite:attribute name="tooltip" required="false" />
		<composite:attribute name="styleClass" required="false"/>
		<composite:attribute name="label" />
		<composite:clientBehavior name="change" targets="weight" event="change" />
	</composite:interface>
	<composite:implementation>
		<div id="#{cc.clientId}" class="componentdiv">
			<p:inputText id="weight"
					label="#{empty cc.attrs.label ? component.clientId : cc.attrs.label}"
					value="#{cc.attrs.value}" disabled="#{cc.attrs.disabled}" readonly="#{cc.attrs.calculated}" validator="komalog.WeightValidator"
					style="#{cc.attrs.style} #{cc.attrs.displayMode == 'normal' || empty cc.attrs.displayMode ? 'width:140px;' : 'width:65px;'}"
					styleClass="#{cc.attrs.styleClass} #{cc.attrs.calculated ? 'ui-state-calculated' : ''}"
					placeholder="#{empty cc.attrs.calculatedValue ? 
						enumHelper.getDisplayValue('net.transdata.komalog.ui.converter.WeightUnit', cc.attrs.unit) : 
						weightToStringFormatter.getUntypedWeightAsString(cc.attrs.calculatedValue, cc.attrs.returnType, cc.attrs.unit)}"
					title="#{empty cc.attrs.calculatedValue ? 
						cc.attrs.tooltip : 
						cc.attrs.calculatedLabel.concat(': ').concat(weightToStringFormatter.getUntypedWeightAsString(cc.attrs.calculatedValue, cc.attrs.returnType, cc.attrs.unit))}" 
						onChange="#{cc.attrs.onChange}" >
				<td:weightConverter weightUnit="#{cc.attrs.unit}" returnType="#{cc.attrs.returnType}" />
			</p:inputText>
		</div>
	</composite:implementation>
Using
Primefaces 6.2.14
Extensions 6.2.10
Mojarra 2.2.13
Wildfly 13.0.0.Final

User avatar
Melloware
Posts: 997
Joined: 22 Apr 2013, 15:48

29 Jan 2019, 14:23

OK I just did this creating an InputText with a Calculator and using the French locale and the separator is a comma ","....

Code: Select all

        <p:inputText id="pInputText" value="#{calculatorController.pInputText}" />
       <pe:calculator for="pInputText" showOn="both" precision="2" locale="fr" />
Can you try that?
PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 6.2.19 / PF Extensions 6.2.10

tdtappe
Posts: 29
Joined: 12 Sep 2011, 09:08

31 Jan 2019, 09:32

Confirmed! It works with "fr". But not with "de" for instance.
But then there's still another problem: If set to "fr" and the input field contains a thousand separator let's say "5.000" for five thousand then the calulator shows up with a value of "5"!

--Heiko
Using
Primefaces 6.2.14
Extensions 6.2.10
Mojarra 2.2.13
Wildfly 13.0.0.Final

User avatar
Melloware
Posts: 997
Joined: 22 Apr 2013, 15:48

31 Jan 2019, 14:15

OK a couple of things.

1. You are right it looks like the german locale is using Decimal see here:
https://github.com/primefaces-extension ... ator-de.js

2. Looks like its a bug in the Keith Wood Calculator component as far as using both period and comma. You can report it here:
https://github.com/kbwood/calculator
PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 6.2.19 / PF Extensions 6.2.10

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest