• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts 2 + validate int value.

 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hello All,

I am using Struts 2 and validate int value using code for this


<field name="maximumTitleSize">
<field-validator type="conversion" short-circuit="true">
<message>
Conversion Error (Integer Wanted) for Maximum Title Size
In Bytes.
</message>
</field-validator>
<field-validator type="int">
<param name="min">0</param>
<param name="max">2147483647</param>
<message>
Positive Integer value required for Maximum Title Size
In Bytes. Maximum value allowed is ${max}.
</message>
</field-validator>
</field>

as int max size is 2147483647 but if i insert 2147483647222 then it shows negative (-ve) value.

please let me know if any one know solution for this.


 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If a value is larger than Integer.MAX_VALUE, how is Struts supposed to cram it into an int so you can validate it?
 
Nishan Patel
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,

yes you are right how it cram in to int but what i mean to say it shows error message and pass validation but when it return back after fail validate it shows negative value. so how to make struts not show negative value.



 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure you see what's happening. When the form is submitted, Struts takes the request parameter for this field and turns it into an int. Since the number is too big to fit in the variable, it gets "wrapped" around and becomes negative. I think if you don't want to see a negative number, you'll have to validate before the form is submitted.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'd probably need to write an overflow-aware type converter.
 
Nishan Patel
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks for your reply,

But i have put my code please let me know how could i resolve my problem ..???

give solution for that ...... :roll:
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David and I have proposed two different ways to approach your problem. Now it is up to you to ShowSomeEffort
 
Nishan Patel
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Yes but i am not getting what you want to say technically.

please explain how to make it and give some reference for it and code.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a number of references on the internet about how Java handles (or doesn't) integer overflow.

The S2 documentation wiki gives the skeleton of a type converter; the XWork source contains many examples. A combination of those two sources should point you in the right direction.
 
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic