Check Using JSTL/Spring-MVC tag regarding Spring Binding Error - spring

I am trying to find a way by which i can check if there is any binding error and based on them i want to show some messages to the user in Spring-MVC. i know one way of this like
<spring:hasBindErrors name="userName">
</spring:hasBindErrors>
but this seems to be with respect to a specific filed of my form, what i want is to check if there is any binding error at all for the current input form or not?
i have also experience of Struts2 and they have a very convient method hasError() which allow a developer to see if there is any error at all for the input fields.
Is there such method defined for Spring-MVC validation or not?

Not an expert of Spring-MVC as i have used it very rarely but if i am correct all you want an equivalent of bindingResult.hasErrors() and if i am correct all you need to use
hasBindErrors tag. For more details refer to the doc
hasBindErrors
Hope this might help you

Related

FilterServletResponseWrapper replacement when migrating Richfaces to Primefaces. For file download

I am migrating a project from Richfaces to Primefaces and I am having problems getting file download to work again. The original uses a standard h:commandLink which tells the webflow to start the download by calling a function on the controller. The actual downloading is written to the output stream instead of being returned as a file.
Now my problem is the previous code sends a FilterServletResponseWrapper, but after changing the rich tags to prime, it now returns HttpSessionSecurityContextRepository$SaveToSessionResponseWrapper. These wrappers are not specified anywhere and I suspect rich sends such a type internally. So if I want to specify my own wrapper to send, how could I possibly go about that? In particular I want to use Spring's ContentCachingResponseWrapper since I need to use it's .getContentInputStream() method.
P.S. I have intentionally omitted the code, because of NDA, I am hoping this is enough information to represent the problem sufficiently. If not I will be glad to clear out any questions.
Thanks

asp.net-web-api using culture for returning errors in different languages

I'm using ASP.NET Web API 2,
I have resx files for errors, I need to return the error in the correct language (by user culture).
My solution is
1)I created BaseApiController that all the other controllers would inherit.
2)In BaseApiController I changed the Thread.CurrentThread.CurrentCulture for each request.
My question is if this is the correct way for doing it?
Thanks a lot!
There are lots of way doing this. It actually depends on your architecture. Your way is also acceptable. You will implement ResourceManager if you use your way. Let me give some other examples:
You can keep language code in request header and you don't need to
change Thread.CurrentThread.CurrentCulture.
You can store errors in database with language code and you can get
corresponding error with the active culture when the operation is
failed.
You can store errors in cache with language code and you can get
corresponding error with the active culture when the operation is
failed.
As you can see, there are lots of ways. As I said it depends on your architecture.
Good luck

How do I register an IBindingTypeConverter in ReactiveUI

I'm attempting to use the "new" binding code for ReactiveUI and when I do wire my view model property to my control I get the following error:
Additional information: Can't two-way convert between <type1> and <type2>. To fix this, register a IBindingTypeConverter
So... how do I register an IBindingTypeConverter ? I'm struggling to find an comprehensible example.
n.b. the code that's throwing the error is not relevant to this question, it may in itself be wrong but that is an entirely different issue
The way to do it is via Splat's service locator:
Locator.CurrentMutable.RegisterConstant(
new MyCoolTypeConverter(), typeof(IBindingTypeConverter));
Update: If you're using RxUI 5.x, it's "RxApp.CurrentMutable"

Redirecting back to Portlet from ResourceMapping in Spring 3 portlets

I am trying to work out a way to provide a CSV download through a Spring 3 Portlet. I have a method that uses the #ResourceMapping annotation to define a handler that takes some report params in the form of a #ModelAttribute, builds the report, and returns it. The catch-22 I am running into is validating the parameters being send in from the client form.
If I make the handler a #ResourceMapping, I can set the headers and write out the report as using the ResourceResponse, but I can't seem to figure out how to redirect the user back to the Portlet view with errors when their input fails validation. However, if I make it an #ActionMapping, I can then check the BindingResults and forward them back to the form as needed, but the ActionResponse doesn't allow me to set the Content-Disposition header nor write out the CSV bytes, which is sort of critical for sending the report back.
I am at a total loss here, as I don't even know what my options are. Is it even possible to do what I am trying to do with a Portlet? Are there other examples I could look at for a possible work-around?
I suggest you to use both #ActionMapping and #ResourceMapping to fulfill your requirement.
As you said you were able to handle the validation errors using the #ActionResponse, I'll tell you how to handle the Resource Streaming.
As you know every #ActionResponse is followed by a #RenderResponse, just return the same view but, with a hidden iframe this time whose src points to the ResourceURL.
Now the Request you receive in #ResourceMapping is something which is already Validated. So, you can now serve your CSV.
I dont know how complex is your UI and if you are using jsp as views in your application. If nicely managed, Validation can be handled by #ResourceMapping.
Thank you

Struts 2 validation - clearing the error message

Good day!
I used the Struts2 xml validation as instructed in this website.
The problem is when I clicked the submit button twice. The error message also appears twice...
My question is... how to clear the first error message before another action is processed to accommodate new set of error messages.
Thank you in advance.
If you are using the spring integration you have to define your bean as scope="prototype", then you get a new instance of your Action for every request.
The default scope for spring is singleton.
It's a good idea to do this for every Action.
Remove validate="true" from form tag.
There is a validator interceptor in the default stack. You just need to use that and using that is very simple. Just make a method in your action class by the name public void validate(). Within that validate() you can access the fields using their getters & then put the required validation onto them.
Also, with this implementation you would not have to worry about the multiple messages being shown, because it will show only the message what you set in the addFieldError method and removes any previously kept messages.
NOTE: Be sure to use getters of the variables in your validate(), because the variables in the action are not set at the time this interceptor is invoked.
Here is a link to a very nice tutorial.
http://www.vaannila.com/struts-2/struts-2-example/struts-2-validation-example-1.html
If you will keep validate=false, then validation xml will be called on submit action.
To clear messages on each submit click, if you are using table in your jsp then keep table outside of form. It will work.

Resources