This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!

Nathan Pruett

Bartender
+ Follow
since Oct 18, 2000
Nathan likes ...
IntelliJ IDE Java Spring
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
14
Received in last 30 days
0
Total given
19
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Nathan Pruett

The problem is that the range (10 ... 5) isn't doing what you think it is - it's *not* giving you a reverse range (i.e. - How many numbers are between 10 and 5?), it's giving you an empty range (i.e. How many numbers are between 10 and 5 that are greater than 10 and less than 5?).

You can use (4..10).to_a.reverse, or (10.downto(4)).to_a to get the range of values you're expecting. (I'm assuming that you meant to use the '...' exclusive range rather than the '..' inclusive range, so the last value should be 4.) These options produce an Array instead of a Range, but they work the same in the for loop (or with each() or many of the other ways to iterate in Ruby).
6 years ago
I believe this is expected behavior - what's happening is that no "name=value" parameter is being sent through the request for that property, so when Spring goes to bind the parameters to the model, that property gets skipped.
One way to fix it is to add a "default" value like you did, so there's always a "name=value" parameter sent for that property.

There are a couple of things on the controller side to address this if you don't like the "default form value" approach -

  • You can make a custom Converter class for your model object that loads the model and then always clears the potentially-empty property. Register this custom Converter in an @initBinder method in your controller. This works because it clears the value before the request parameters are bound to the model - so if the value is present, it's set, if it's not, it's been cleared.


  • Instead of always loading the model right away, you can create a brand new instance of your class each time in your controller and have the request values bound to it, then later load the real object you want and "manually" set the properties from the brand new form backing object.
  • 6 years ago

    In your UserController -


    Instead of just the String "userForm", you're probably wanting to place an instance of the model class here... something like -



    You also probably want to pass a User instance into the method that handles your form POST -
    6 years ago
    Yes - Spring is a separate set of libraries - it's completely separate from an IDE.
    6 years ago
    Your session isn't expiring - your LPTA token is expiring, meaning you are no longer authenticated via third-party authentication. This is configured in WAS, and is not part of Spring, so moving the question to a more appropriate forum.
    6 years ago
    What's your spring context file named? When you specify your DispatcherServlet in your web.xml, it assumes that it's named "<servlet-name-of-dispatcher-servlet>-servlet.xml".

    I'm assuming yours is defined something like:

    which looks for "SpringMVCTutorial-servlet.xml".

    You can change your DispatcherServlet's servlet-name to match your context file, rename the context file to match the servlet-name of the DispatcherServlet, or specify the name of the context file using either the "contextConfigLocation" init-param (to specify the path and full name of the file) or "namespace" init-param (to specify a name other than the servlet-name) on the DispatcherServlet.
    6 years ago
    The stack trace mentions this file is causing the error - /jsp/home/homepage.jsp Does this page exist in your app?
    6 years ago
    In theory, the timer resolution should be the same - theoretically, I suppose the actual hardware clock could affect this number too, but nothing's going to have a hardware clock slow enough to affect this.

    In practice, though, lots of different things can affect the numbers you get - for one thing, hardware could be different (i.e. faster/slower CPUs; more RAM preventing things swapping in/out of memory) and/or one system could be under heavier load than the other.

    Also, System.currentTimeMillis() is affected by what time the OS thinks it is - so if you change the time through "Set time and date" - you will get different millisecond values. i.e. you're running a program computing the difference between System.currentTimeMills() calls and while running it you set the time forward on your system by one day, as soon as that is applied, System.currentTimeMills() returns something close to a 86,400,000ms difference.

    If you can use a JVM >= 1.5, you can use System.nanoTime() - this is more precise, and it's not based on what the OS thinks the date/time is - i.e. it's a timer, not a clock.
    6 years ago
    1.) "differences" isn't really the way to think about this - it's really an issue of "timer resolution". System.currentTimeMillis() just returns the current count of milliseconds since midnight, January 1, 1970 - it gets this from the underlying OS. In some OSes (the versions of Windows you mentioned) the OS doesn't update the millisecond count every millisecond, but every 20 or 40 milliseconds. So if you had code like this:



    On a system that updates every 1 millisecond, you'd end up with something like this:

    0
    0
    0
    1
    0
    0
    1
    .
    .
    .

    Mostly 0s and 1s (maybe some higher numbers every so often if you had lots other programs running, or heavy processing going on in the background). The 0s are there because lines of code run faster than 1ms a line, the 1s show up when the system millisecond counter updates.

    On a computer that has a 20ms timer resolution you'd end up with output like this:

    0
    0
    0
    .
    .
    .
    0
    15
    0
    0
    .
    .
    .

    *Lots* more 0s and rarely a 15 (again, usually around 15 - you might end up with some 16/17/etc. because other things are running, etc.). Again, the 0s show up both because operations take less than 1ms, but also because even though more than 1ms has passed in real time, the OS timer keeps returning the same value until it updates.

    2.) To understand this code plug in some fake values that are easy to work with - let's say DEMO_TIME is 5 (which means we want it to run a duration of 5ms), and assume a 1ms timer resolution (System.currentTimeMillis() returns a new value every 1ms).

    The code starts, System.currentTimeMillis() is called and returns 100. This value is saved in the variable startTime and copied into currTime.

    We enter the loop and test the condition: currTime (100) - startTime (100) is 0, which is less than DEMO_TIME (5), so we enter the loop.

    We call System.currentTimeMillis() again, this time we get 102. We subtract the value in currTime (100), so we get 2 and save it into elapsedTime (2ms have passed since we set currTime).

    We then add elapsedTime (2) to currTime (100) and save 102 into currTime.

    The loop tests the values again - currTime (102) - startTime (100) is 2, which is less than DEMO_TIME (5), so we start the loop code again.

    We call System.currentTimeMillis() again and get 105. We subtract the value in currTime (102), and get 3, and save it into elapsedTime (3ms have passed since we last set currTime - last time in the loop.)

    We then add elapsedTime (3) to currTime (102) and save 105 into currTime.

    The loop test the values - currTime (105) - startTime (100) is 5 - this isn't less than DEMO_TIME (5), so the loop ends and exits.


    I don't completely understand this myself. All I know is that it gives the correct time to put a thread in a game to sleep. If it doesn't have this mysterious value, a character might animate too fast on a fast computer.



    Try reading about Time-Based vs. Frame-Based Animation - the example on the site is in ActionScript, but the concepts are the same no matter what language you're using (and ActionScript is pretty close to Java syntax-wise anyway).
    6 years ago
    This isn't a Spring issue - it's a web design issue. Apparently Safari 5.1 changed the way it does layouts and other people are complaining about it too.

    Moving this to the Web Design forum.
    GIMP - has builds for any OS.
    Seashore - based on GIMP, but with an easier interface. OS X only.
    Paint.NET - Windows only.
    7 years ago

    Singleton class, traditionally called as PrivilegesMgr.getInstance() and not privilegesMgr.getInstance()



    Yes, it's considered bad form to call a static method through it's class rather than an object reference, but there is really no difference in Java - it works either way. There's also no need to call "getInstance()" explicitly in your code - Spring has already called "getInstance()" for you - you can just call it as:



    when, try to do PrivilegesMgr.getInstance(), i get null pointer, which is logical, as their is no bean available.



    Why do you think there is no bean available? The code you posted looked OK - are you sure you're loading the beans XML configuration containing your "privilegesMgr" bean? Can you post relevant sections from your web.xml deployment descriptor?
    7 years ago
    Since you mentioned Android - I'm betting the problem has more to do with how you're trying to draw elements. Check out the Graphics section of the Android documentation. There are several ways to draw graphics in Android, and from slowest to fastest they are:
  • Drawing to a View
  • Drawing to a Canvas
  • Drawing via OpenGL


  • Which are you using?
    7 years ago
    This question doesn't have anything to do with Spring. This is something you need to ask someone else on the project you're working on.
    7 years ago
    This is handled by the JVM - Spring doesn't really have anything to do with it.

    Is this your code or a third party library you are using? If it's your code, you can use System.load() instead of System.loadLibrary() - System.loadLibrary() only loads from the java.library.path, but System.load() can load from any location. Some libraries package their native dependencies inside their JAR, extract them to a pre-defined location, and use System.load() to load them from that location.

    If it's a third party library using System.loadLibrary(), it's probably easier to just add to the java.library.path - you can either set the PATH environment variable to point to the directory that contains the library, or specify java.library.path when starting the JVM - this is done by setting the property - by passing -Djava.library.path=... as a command-line argument.
    7 years ago