I have a project created with Spring roo and I have a number field in one of my entities. I need to add some logic that this field can only take numbers that are powers of two and if it isn't then an error should be thrown to the user when trying to submit i.e. "Invalid input: not a power of two". I know what formula to use I'm just having trouble executing it on a spring/roo project. i.e. Where/what file does this piece of code go into? How do I make sure an error is thrown so the user sees it.
I asked around and got a couple answers, namely this
1) client side way: In the entity create.jspx using javascript. 2)
server side way. In entity controller loading the message error in the
returning model object.
But I don't really understand how to do this.
Thanks.
You can use a custom validator for Spring with Spring Roo.
Take a look at the change password validator in the following article by Sujit Pal.
http://sujitpal.blogspot.com/2010/07/ktm-customizing-roo-security.html
All the best with Roo.
Related
I want to logically separate all my Graphql schemas into diff. entities. I am doing this in a spring-boot project.
I do not want to use Appolo or any other 3rd party libraries.
E.g.
book.graphql
author.graphql
I tried the solution provided, and I got no compile error but I am also not getting results from the query anymore.
Spring GraphQLmultiple schemas with Query per file
Please see below:
Can someone pls point me out if I am doing something incorrectly?
The solution provided here enter link description here works as is.
The reason I was getting errors was that I had not implemented the endpoint.
I am new to Spring validation. Recently I have been exploring different approaches of validation utilities available in Spring. I found there are basically two approaches: 1. with JSR-303 and 2. by implementing Validator interface in Spring.
What I understood, with first approach one can achieve model level validation whereas the latter is more appropriate to validate String, Integer types of inputs. Is there something more, that I am missing here?
Here is an open source alternative to JSR-303.
This solution can perform all validation of the request message, but no hassle coding is required.
https://github.com/ckpoint/CheckPoint
With Check-Point, all validation is possible without further code, just by changing the annotation of the Controller method.
After that, all validation settings can be easily made in Admin Page.
I think this video can help your understand. https://youtu.be/I1aEIztXlhE
Check-Point Admin-Page Setting Screen
I have a spring flow project. On the form I want to add a check box, like "I confirm that I have provided correct details" and want to stop the flow if this check box is not checked. I don't want to add this as a DB field (validation through that is pretty simple). I cant find a way to validate the check box at client side. Any examples/options are appreciated.
jsr-303 or jsr-349 are the standards for bean validation, and is the reference yoou're looking for, from a high point of view. Youcan start reading from Wikipedia: https://en.wikipedia.org/wiki/Bean_Validation
When it comes to implement this in Spring, you have to annotate the parameter passed to the MVC handler method as #Valid and implement a Validator. The best example you could look at, initially, is the Spring official documentation:http://docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html
I'm new to java and web apps and after trying out a few things I went with a set up of Spring webmvc using annotations and velocity as templating engine. It's not that hard to do simple #RequestMapping annotations to controller methods and returning ModelAndView instances filled with data, however I was wondering how things are done when you have data you need in the model that occurs on every page, for example "latest 5 news items" or something similar. You could of course always fill the model with such data in every method that is handled by a #RequestMapping, but I'm quite sure that that is not the way to do it.
What is the correct way of filling the model with recurring data, without poluting your controller methods with calls to the same method for this recurring data.
Any help is appreciated.
You could use a servlet filter or a Spring interceptor, and get the recurring data from this filter or interceptor and place it in a request attribute.
Another solution is to let the page call more than one controller, for example by using multiple ajax requests. Then one controller could is responsible for the specific page and another is responsible for "latest 5 news items", see related question.
Good question dude. In my current app i am using sessions to store my username which is appearing on all the rest of the app.
#JB Nizet thanks for the link.. now ill go for spring interceptor
Here is my question: does anyone know how to set up custom validation for NetTiers entities?
I have a NetTiers web solution that was generated with the EntLib 4.1 validation app block. The actual entities' properties are decorated with the validation attributes to ensure that the dataase integrity is maintained. What I need to do is add custom validation to the entities.
I know how to write the custom validators. I'm just not sure how to wire them up to the each entities so that I can perform custom validation. What I am looking for is an overview on how to do this.
Any help would be appreciated.
Thanks,
Joe
Are you using the latest release of .netTiers? Support for data annotations was added in this patch and committed to core.
I would take a look at the following documentation. I'm thinking that this is something that you would need to wire up programmatically. Well make sure that this scenario works in v3.