Spring validation in multiple forms - spring

Can we display error messages in one jsp but in 2 different forms.I am validating my bean using spring validation.Its working fine but if there is an error in the binding results then I am able to display the error message in the form from where action is executed but not in the other resultant form.
is the error tag in spring validation is mapped to jsp form from where that action is called.

Your BindingResults is just an object, which you can put in your Model and use on the page however you want. You may need to put it into Session if you plan to use it on a separate form.

Related

f:param in p:ajax with p:selectonemenu

I have a JSF project using Java 8, JSF 2.2 and primefaces 5.3 running on Tomcat 8.
I have pages with parameters (http://server/app/page?x=1).
I have a form with p:commandButton updating some page parts with AJAX. When I submit the form the POST request is built correctly and contains also the page parameters (x = 1) passed with f:param.
I have however other form with p:selectOneMenu with an p:ajax and an AJAX listener changing some other form components. BUT the AJAX call does NOT include the page f:param parameters (x = 1) in this case into the POST message and thus the backing bean is unable to read proper data from DB and build requested page parts.
The question is: how to pass the page parameters to the p:ajax call...?
I know there is an option to pass the parameters as arguments to the listener, but in this case the parameters are not visible to other beans and components used to build the page.
I'm using #RequestScoped beans and #ManagedProperty to set up the page parameters and it makes the code clean and simple. Using parameters for ALL XHTML calls would be a mess...

Spring webflow validator with no error message

I have spring webflow applicaiton, which has a contact info page and while submitting the form, it goes to spring validator.
And executing validations, if any wrong data then we adding a error message to validationcontext. Using ${errorMessags} we list the error messages.
But I have a scenario where I need to show a warning message to user in middle of page.
Either through spring validation or spring flowscope variable in Spring Validator
Is there any way to do it?
Thanks in Advance!!!
Why do you want to do that on validator? Do you want to show that warning in next view?
I guess you could set message in or in to flashScope variable and show it on next page.

Spring MVC Load page automatically

I have a quick question about how to use the Spring MVC.
I just started with it and i was used to have pages that always had their data loaded calling some controller that you setted ON THE PAGE.. calling some methods on controllers to load objects at the page at load time.
Is it the same in Spring MVC? Cuz what im seeing so far is that if you want to load a page with data, you always have to use a modelandview object which is loaded by a method that you must call before... and them you return the modelandview object with its destination to the view that you want.
What im trying to know is if there is a way that the page requests some data from the controller before it gets loaded... automatically...
Dont know if im making my self clear... thanks anyway for the help!
in spring mvc, using Controllers, it is always Request->Controller(populates model and chooses view)->Response.
you could use ajax to load data from any resource (even Controllers) or jsp:useBean to explicitly call some business logic or jsp:include to include a certain fragment or a custom jsp tag.
I also face the same situation.
check the below link for getting the data from the controller before view(JSP) load.
how to load the data into index page

Passing messages from AuthenticationFailureHandler and LogoutHandler to JSP

I my application I have created custom AuthenticationFailureHandler and LogoutSuccess handler classes.
Now I want to pass messages from these classes to JSP which should be accessed using struts2 jstl tags.
I dont want to use url parameters for passing messages to jsp page.(login.action?msg=abc)
Any ideas on this?
One of the way to do it, is to put your message to session. In JSP you can access session like that:
<s:property value="#session.message"/>

JSF 2 - clearing component attributes on page load?

The real question: Is there a way to clear certain attributes for all components on an initial page load?
Background info:
In my application, I have a JSF 2.0 frontend layer that speaks to a service layer (the service layer is made up of Spring beans that get injected to the managed beans).
The service layer does its own validation, and I do the same validation in the frontend layer using my own validator classes to try and avoid code duplication somehow. These validator classes aren't JSF validators, they're just POJOs.
I'm only doing validation on an action, so in the action method, I perform validation, and only if it's valid do I call through to the service layer.
When I do my validation, I set the styleClass and title on the UIComponents using reflection (so if the UIComponent has the setStyleClass(:String) or setTitle(:String) methods, then I use them).
This works nicely, and on a validation error I see a nicely styled text box with a popup containing the error message if I hover over it. However, since the component is bound to a Session Scoped Managed Bean, it seems that these attributes stick. So if I navigate away and come back to the same page, the styleClass and title are still in the error state.
Is there a way to clear the styleClass and title attributes on each initial page load?
Thanks,
James
P.S. I'm using the action method to validate because of some issues I had before with JSF 1.2 and it's validation methods, but can't remember why... so that's why I'm using the action method to validate.
Ok, so I must use a PhaseListener, see this blog entry by BalusC and this other blog entry, that's a much better way of doing what I'm doing already - setting the styleClass manually using reflection - which gets all components with messages and highlights them... I'm gonna do the same, however think it's possible to add an attribute instead, haven't tried it yet.

Resources