Page 1 of 1

Calculator and decimal separator

Posted: 28 Jan 2019, 13:35
by tdtappe
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

Re: Calculator and decimal separator

Posted: 28 Jan 2019, 14:33
by Melloware
Can you paste your snippet of the calculator so I can see it?

Also have you tried setting the locale="" of the Calculator?

Re: Calculator and decimal separator

Posted: 29 Jan 2019, 10:10
by tdtappe
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>

Re: Calculator and decimal separator

Posted: 29 Jan 2019, 14:23
by Melloware
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?

Re: Calculator and decimal separator

Posted: 31 Jan 2019, 09:32
by tdtappe
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

Re: Calculator and decimal separator

Posted: 31 Jan 2019, 14:15
by Melloware
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