Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiple Form Validation  RSS feed

 
Carlos Conti
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am developing an app with IceFaces and am facing the following problem. If I have a page with several forms, is there any way of selectively deciding which form validates when?. I neet to stick to a scenario with multiple forms and a kindof "SaveAll" command button which fires a last overall validation, before finally saving the data. On the other hand I need to verify directly after data being inputed some business logic. So in a way, I need depending on the section being edited, to be able to fire selective validation processes, in order to discard or include error validation messages. Sometimes I am interested on displaying inline error messages (<ice:message for="whatever".../>) and sometimes I need to display them within a popup dialog, either as an overall or section specific validation process.

I must be missing something because I find myself facing conflicts all the time. Since IceFaces doesn'tseem to support embedded forms or subforms, I am not able to selectively disable one form or another for veriication.

If you could share any ideas it would be great!
Many thanks in advance.
Carlos.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Carlos.

JSF Forms generate HTML FORMs, and therefore they have to obey the same rules. One of those rules is that exactly one and ONLY one form can be submitted to the server per HTTP request. So when you click the SUBMIT button (meaning a commandButton or commandLink in JSF), ONLY the form that contains that SUBMIT will be sent to the server, and therefore only that form will be validated and (if valid) processed.

FORMs can't be nested, incidentally.

It's difficult to process data from multiple forms. Most of the tricks involve JavaScript. For example, if you're using an AJAX-supporting framework such as RichFaces, you can define controls which validate immediately rather than being saved up until SUBMIT time. Actually what happens is a limited submit request is generated behind the scenes using a dynamically modified form. The technical term for this process is "magic".

At a larger scale, you can validate data from multiple forms but using JavaScript to dynamically move the interesting fields from the secondary form to the primary form as part of the submit request. It tends to get ugly, though.
 
Carlos Conti
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm yes more or less I guessed that already. However I preferred to wait until more experienced jsf developers confirmed that guess. Well in such cases I think the best choice is the one that minimizes maintenance costs, and since NO JAVASCRIPT is a priority, I think I will have to use one form per page and show mostly inline errors as they are fired in the ProcessValidation phase. It will be a bit annoying but at least the easiest way to do it until we figure out a better approach.

Many thanks for your advise.
Carlos.
 
Brad Kroeger
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can achieve your goal with a lot of work on the server. In your action or actionListener method, you can kick off validation of other forms in the page by checking their values and manually generating messages:

addErrorMessage("customerForm:customerType",requiredMsg);

public static void addErrorMessage(String clientId, String msg) {
FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
}
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brad Kroeger wrote:You can achieve your goal with a lot of work on the server. In your action or actionListener method, you can kick off validation of other forms in the page by checking their values and manually generating messages:

addErrorMessage("customerForm:customerType",requiredMsg);

public static void addErrorMessage(String clientId, String msg) {
FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
}


Except that that won't capture the CURRENT state of the View. Like I said, ONLY the data values in the form being submitted are sent to the server when you click "submit".
 
Brad Kroeger
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using ICEfaces 'partialSubmit' attribute on your components, all fields that have been visited in any form in the page would have been set (if they are valid).
 
Carlos Conti
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

thanks for your answers. I have adopted a single form per page strategy. As said a bit annoying but until improved, it will do evenwith complex pages with many sections.
Carlo.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!