Sheet component numeric formatting

Community Driven Extensions Project
Post Reply
Posts: 1
Joined: 09 Mar 2018, 19:10

22 Aug 2018, 18:59

Hello everyone.

I'm building an application that required a functionality like excel sheets and I found at primefaces extensions a good choice to go.
Everything is going fine, but I have some fields that must be filled with 8 digits numeric codes and here I have a problem:

I set this colType as numeric to avoid user typing letters, but than every number typed that goes beyond 1000 is showed as "1k". Since all the numeric codes have 8 digits, I thought that applying the numericPattern="00000000" should resolve this.

Code: Select all

<pe:sheetcolumn headerText="#{app.label_code}" value="#{c.code}" colWidth="120"   
                sortBy="#{c.code}" filterBy="#{c.code}" colType="numeric" numericPattern="00000000"/>
The problem is that I have another field that receives a 3 digit numeric code and some codes are like "001" or "002"... I set this colType as numeric and numericPattern="000", but if the user types "001" the backing bean is reading as "1". Is there any way to force the backing bean to read all the characters typed by the user? I know this problem can be easily resolved at backing bean but I wanted to know if I am doing something wrong here, or if there is another (and better) way to define a pattern.

Code: Select all

<pe:sheetcolumn headerText="#{app.label_code_ex}" value="#{c.codeEx}" colWidth="90"   
                sortBy="#{c.codeEx}" filterBy="#{c.codeEx}" colType="numeric" numericPattern="000"/>
I'm using Primefaces 6.2 and Extensions 6.2.7.

User avatar
Posts: 1178
Joined: 22 Apr 2013, 15:48

24 Aug 2018, 14:37

OK because numeric is a number it will always make 001 into 1. What you need to do is leave it as a string and do this...

Code: Select all

<script type="text/javascript">  
var threeDigitRegex= /^\d{3}$/; // regex only 3 digits  
Then in your sheet column use the "onvalidate" method which will apply your regex.

Code: Select all

<pe:sheetcolumn value="#{c.codeEx}" onvalidate="threeDigitRegex">
See this page for more details of this example: ... dation.jsf
PrimeFaces Extensions Developer
GitHub Profile:
PrimeFaces Elite 7.0.4 / PF Extensions 7.0.1

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests