Hi I am trying to validate IntegerField using Binder with this code:
binder.forField(number)
.withValidator(num -> num == null || (num >= 1 && num <= 999),
getTranslation("number_must_be_between_1_and_999"))
.bind(BusinessObject::getNumber, BusinessObject::setNumber);
The field is optional, but if entered, must be between 1 and 999.
It works fine until I try to enter a number greater than 2147483647 (the maximum Intger in Java).
For numbers greater than this, the validation passes without any warning, and the background business object gets a null value.
The field is in a dialog and what makes it even weirder is that the next time I open the same dialog, the IntegerField contains an invalid number entered even though null is written to the business object, Binder.readBean() stops working for that field.
How can I validate IntegerField correctly and avoid this bug and why is it not possible to limit the number of digits for an IntegerField? I am using Vaadin 23.3.0 .
Related
I have an integer(int a) whose value can be ranged between -30 to +30.so if the user selects a value from the range provided,(int a) value should change accordingly.but then sometimes,when the user does not select anything from the provided range and skips the option,(int a)is been set to null and automatically assigning the value by itself as 0.how can I differentiate this and and the user himself choosing 0 as the value of (int a) as it is also included in the provided range.
You could try setting the initial value of the integer into something that is clearly outside the range (-999, for example). So that when you re-check the integer, if the value is out of the range's bounds then you know the value has never been set.
Alternatively you could encapsulate the value in an object instead of using the primitive, i.e you could use NSNumber.
Hi all I have a situation where I have 3 columns which results in 3 results.
3 columns are empty, display "0"
First column has a date <= today(), 2nd and 3rd column empty, result is "1"
First column has a date > today(), 2nd and 3rd column empty, result is "0"
Second column has a date and third column is empty (First col can be empty or filled), result = "2"
Third column has a date, result = "3"
Here is my code below:
=if(and(ISBLANK(A6), ISBLANK(B6), ISBLANK(C6)),"0",IF(and(A6<=NOW(), ISBLANK(B6), ISBLANK(C6)),"1",if(and(NOT(ISBLANK(A6)),B6<=NOW(), ISBLANK(C6)),"2",IF(C6<=NOW(),"3","0"))))
However I am getting mixed results, especially if the date in the first column is greater than the today's date, it shows up a result of "2" and not the expected "0"
So despite your somewhat mismatched directives - here is a start - I am still unsure about which of your rules actually overrides - so when you updated that I will update the formula:
=if(counta(A1:C1)=0,0,IF(LEN(C1)>0,3,IF(LEN(B1)>0,2,IF(AND(LEN(A1)>0,COUNTA(B1:C1)=0,A1>TODAY()),0,IF(AND(LEN(A1)>0,COUNTA(B1:C1)=0,A1<=TODAY()),1,)))))
A couple things I am doing here:
Part of the reason your formula is having issues is two major things -
1) you need to reverse the order of your IF statements to allow the cells in C or B to trump the other rules, if that is the result you want. This way if you always want a 3 when anything is in column C, that should be the second check after checking if all 3 are blank
2) when using things like <= a date or time - it treats blank cells as always being less than. So change/add one more check within your AND function to check that the length of it is greater than 0 so make sure there is a valid value in there.
I have an Rdlc report
In this report I have a field which takes its values by this expression
(Round(((First(Fields!Occurs.Value) / First(Fields!TotalDistance.Value))* 10000),2)
but in some cases (TotalDistance.Value) = 0 so the previous expression returns Infinity,
So I need to get the next record in case of that field equals 0 ,
If also next field equals 0 , I want to get the next one
I looked for way of getting next record but didn't find
I only found (First , Last) methods,
How can I do that ?
instead of using First or Last if you don't care which record as long as it isn't 0 then couldn't you use an aggregate function. ex:
(Round(((First(Fields!Occurs.Value) / MAX(Fields!TotalDistance.Value))* 10000),2)
you could use Max, Min or Avg to get a value. I am unaware of any way within the rdlc to loop through the records like you are asking.
Another completely different way could be to load the data into a datatable then add a column to contain the calculated value and use some code to calculate the values before being passed to the report.
I am trying to do the following:
For each Row
If Cell A contains text "abc" then get value on column B and
if value on Column B is > than 0:03:00 return 0.9
else if value on Column B is < 0:03:00 and > 00:01:00 return 0.6
else return 0.3
Sum the returned value with all the others.
The result should be something like:
=IF(ISNUMBER(FIND("abc",INDIRECT(""&$A16&""&"!$D$2:$D"))),IF(INDIRECT(""&$A16&""&"!$D$2:$D")>"00:0300,???,???),?etc??)
??? are the missing parts. Also, INDIRECT() could be removed for testing, but the problem is that ??? part. I have no idea how to get the result of the IF statement and how to process it. I suppose I don't understand how to work with columns.
You could possibly use an "array formula" with LOOKUP like this in excel
=SUM(IF(ISNUMBER(FIND("abc",A2:A100)),LOOKUP(B2:B100,{0,1,3}/1440,{3,6,9}/10)))
confirmed with CTRL+SHIFT+ENTER
or this version with IFs [edited]
=SUM(IF(ISNUMBER(FIND("abc",A2:A100)),IF(B2:B100>="0:03"+0,0.9,IF(B2:B100>"0:01"+0,0.6,0.3))))
In Google spreadsheets use this version
=arrayformula(SUM(IF(ISNUMBER(FIND(ʺabcʺ,A2:A100)),IF(B2:B100>=ʺ0:03ʺ+0,0.9,IF(B2:B100>ʺ0:01ʺ+0,0.6,0.3)))))
That will add 0.3 for the total for every row where "abc" is found in the text in column A and column B is >=0 but < 0:01, 0.6. where B >=0:01 and < 0:03 and 0:09 if B >= 0:09
Using LOOKUP makes it easier to avoid multiple IFs but I'm not sure if it gives the correct values for you on the boundaries, that's more easily adjustable with the second version. You can adjust the range lengths and add INDIRECT if required.
Note: using FIND for the first condition means that the formula will look for "abc" (case-sensitive) anywhere in the text, if you only want to check for exactly "abc" with no other text you can use just range = "abc" [not case-sensitive] or EXACT(range "abc") [case-sensitive]
In my report viewer i have a table displaying data in different columns. I wanted to have a regular expression to check the content in a textbox of a table to see if it is NULL to place a 0 in the textbox. Currently if there is returned data it is displayed and if not then there is empty space which i would like to replace it with a 0
here is what i had for a regular expression for the textbox:
=IIf(Fields!FirstAmount.Value = " ","0",Fields!FirstAmount.Value)
Any ideas or other ways to resolve this issue.
I resolved my issue using the following expression:
=IIF(Fields!FirstAmount.Value Is Nothing, "0", Fields!FirstAmount.Value)
depending if the First Amount field is null or not it will be replaced by 0 if it is empty and if not it will show its data.