Re: ANYONE Know How To Validate Nested Form Beans?
Okay Sorry i took a while i forgot about it. So we've a nested user bean as a form property //struts config form-property name=user type=com.sparrow.UserBean / //in validator field property=user.email depends=required,email .. //jsp html:text property=user.email / Cheers Mark On Monday, September 1, 2003, at 05:55 PM, Terry Brick wrote: Well it seems to be a mystery still whether it does or does not. Sounds like Mark has done it but he's checking to see if it was custom or using built in functionality. I guess it was just an assumption on my part that it DID have it built in because it seems pretty fundamental/basic to me... compared to some of the much more advanced capabilities it has built in. Anyway, thanks for the code sample. It looks like I may end up using some of that. I'll wait and see what Mark digs up. I think worst case scenario, I'll use some bean instrospection upon submission to look for all property values that are instances of ValidatorForm or Collections... then recursively invoke the validator on each one it finds, and add the errors collection to each form bean (a property they all implement through an interface). I guess that wouldn't be bad... but I just thought it was built in. --- Richard Mixon [EMAIL PROTECTED] wrote: Terry, Thanks for asking the question - I've asked a similar question in the past. I did not realize that validator has some collection support, I may look further into that. __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: ANYONE Know How To Validate Nested Form Beans?
Programming jakarta struts is a nice introduction to webapp development in general and struts development too. The only problem is as soon as you want to do anything vaguely useful there's no detail. Its not a criticism of the book as such just that its scope is different to these sorts of problems. There's and indexedListProperty attribute in validator for the purpose of which you speak, and it works although not for the javascript generation. The array of form elements aren't generated in the javascript, but the js itself does handle indexed properties.. for example if you hard code myobj[0].myproperty in validator it works. So the only piece of the validator puzzle thats missing is generating the js array of indexed form elements .. If i'm not making any sense, have a before and after look at the javascript. I think fixing the validator to generate indexed elements would be the fastest way of dealing with this, or add this to bugzilla. A hack could be to just layer some most js onto the page. If you using the html:errors stuff and cant get it to spit them out, you could try bean:messages and spit out the errors like that, they are there (the errors) they're just hiding. logic:messagesPresent pre html:messages id=error bean:write name=error/ /html:messages pre /logic:messagesPresent rather than pre html:errors / /pre Cheers Mark Hello, I'm using struts 1.1. I thought this would be relatively simple, but I can't figure it out. I've checked my book Programming Jakarta Struts and searched the archives. All got from the archives is a bunch of people asking this same question, but NO responses. Please help if you've got the secret. Basically I have a form bean which has some properties that are collections (Vectors) of other form beans (indexed properties of collections). These nested form beans also need to be validated. The page displays fine, and upon submission, all the data is populated correctly in the form (nested props and all). However, the validator just totally ignores the nested beans. What do I need to do in my validations.xml to get it to validate nested form beans? I've tried the following (totally made it up)... field property=my_collection_property indexedListProperty=form_bean_name .. and that form_bean_name is the name of another form entry in my validation.xml. Anybody know where I'm going wrong? Thank you! __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: ANYONE Know How To Validate Nested Form Beans?
Thank you much for your response. Two things 1) Sorry, I left out a big piece of detail. I'm interested in doing this validation only on the server side (no javascript). Yet I still can't get it to work. Are you saying that I'm doing it correctly as show here? field property=my_collection_property indexedListProperty=form_bean_name Your html:messages code was helpful in getting the errors for the top level bean, but there are still no errors for the nested beans... but that's because it's not validating them. I know this because validation will pass if the top level bean has the correct properties... regardless of what's in the nested beans. The nested beans just aren't being checked for validation. 2) About the book. I completely agree. Glad to know it's not just me ;) --- Mark Lowe [EMAIL PROTECTED] wrote: Programming jakarta struts is a nice introduction to webapp development in general and struts development too. The only problem is as soon as you want to do anything vaguely useful there's no detail. Its not a criticism of the book as such just that its scope is different to these sorts of problems. There's and indexedListProperty attribute in validator for the purpose of which you speak, and it works although not for the javascript generation. The array of form elements aren't generated in the javascript, but the js itself does handle indexed properties.. for example if you hard code myobj[0].myproperty in validator it works. So the only piece of the validator puzzle thats missing is generating the js array of indexed form elements .. If i'm not making any sense, have a before and after look at the javascript. I think fixing the validator to generate indexed elements would be the fastest way of dealing with this, or add this to bugzilla. A hack could be to just layer some most js onto the page. If you using the html:errors stuff and cant get it to spit them out, you could try bean:messages and spit out the errors like that, they are there (the errors) they're just hiding. logic:messagesPresent pre html:messages id=error bean:write name=error/ /html:messages pre /logic:messagesPresent rather than pre html:errors / /pre Cheers Mark __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: ANYONE Know How To Validate Nested Form Beans?
Terry, Thanks for asking the question - I've asked a similar question in the past. I did not realize that validator has some collection support, I may look further into that. I used a different approach by putting together a little glue code in my main form bean's validate method. For example, I have a composite form bean that has properties for a base form bean and two collections of multiple line item form beans. Both the base and line item form beans have their own validator validations. Below is an example. Note that I have to lookup the ActionMapping for a utility action that uses the line item form to update a single line item. I would go with Mark's idea if it works for you - much less manual glue code, but at least this reuses your validations. - Richard public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { // Let standard validation run first. ActionErrors errors = null; // errors = super.validate(mapping, request); ActionError error = null; ActionErrors currLineItemsErrors = null; ActionErrors newLineItemsErrors = null; if (errors == null) errors = new ActionErrors(); LineItemForm li = null; ActionMapping liMapping = (ActionMapping)mapping.getModuleConfig().findActionConfig(/config/LineItemA ction); // Check each new currLineItems formbean if (newLineItems != null newLineItems.size() 0) { if (log.isDebugEnabled()) log.debug(Validate - count of newLineItems=+newLineItems.size()); for (int i = 0; i newLineItems.size(); i++) { // Do not consider if some part of form is not filled in if ( newLineItems.get(i) == null ) { if (log.isDebugEnabled()) log.debug(Validate - newLineItem[+i+] is null, skipping.); continue; } li = (LineItemForm)newLineItems.get(i); if (log.isDebugEnabled()) log.debug(Validate - newLineItem[+i+]='+li+'); if ( li.isEmpty() ) { if (log.isDebugEnabled()) log.debug(Validate - newLineItem[+i+] is empty, skipping.); continue; } li.setServlet(getServlet()); newLineItemsErrors = li.validate(liMapping,request); if (!newLineItemsErrors.isEmpty()) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(error.in.new.line.num, Integer.toString(i+1))); errors.add(newLineItemsErrors); } } } if (currLineItems != null currLineItems.size() 0) { if (log.isDebugEnabled()) log.debug(Validate - count of currLineItems=+currLineItems.size()); for (int i = 0; i currLineItems.size(); i++) { // Do not consider if some part of form is not filled in if ( currLineItems.get(i) == null ) { if (log.isDebugEnabled()) log.debug(Validate - currLineItem[+i+] is null, skipping.); errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(error.in.curr.line.num, Integer.toString(i+1))); errors.add(currLineItemsErrors); continue; } li = (LineItemForm)currLineItems.get(i); if (log.isDebugEnabled()) log.debug(Validate - currLineItem[+i+]='+li+'); if ( li.isEmpty() ) { if (log.isDebugEnabled()) log.debug(Validate - currLineItem[+i+] is empty, skipping.); errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(error.in.curr.line.num, Integer.toString(i+1))); errors.add(currLineItemsErrors); continue; } li.setServlet(getServlet()); currLineItemsErrors = li.validate(liMapping,request); if (!currLineItemsErrors.isEmpty()) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(error.in.curr.line.num, Integer.toString(i+1))); errors.add(currLineItemsErrors); } } } return errors; } - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: ANYONE Know How To Validate Nested Form Beans?
Thats strange I'll have to check how i was getting them working. I'll have a look over where i've got it working (I don't think there were any hacks in there but its possible). Cheers Mark On Monday, September 1, 2003, at 04:28 PM, Terry Brick wrote: Thank you much for your response. Two things 1) Sorry, I left out a big piece of detail. I'm interested in doing this validation only on the server side (no javascript). Yet I still can't get it to work. Are you saying that I'm doing it correctly as show here? field property=my_collection_property indexedListProperty=form_bean_name Your html:messages code was helpful in getting the errors for the top level bean, but there are still no errors for the nested beans... but that's because it's not validating them. I know this because validation will pass if the top level bean has the correct properties... regardless of what's in the nested beans. The nested beans just aren't being checked for validation. 2) About the book. I completely agree. Glad to know it's not just me ;) --- Mark Lowe [EMAIL PROTECTED] wrote: Programming jakarta struts is a nice introduction to webapp development in general and struts development too. The only problem is as soon as you want to do anything vaguely useful there's no detail. Its not a criticism of the book as such just that its scope is different to these sorts of problems. There's and indexedListProperty attribute in validator for the purpose of which you speak, and it works although not for the javascript generation. The array of form elements aren't generated in the javascript, but the js itself does handle indexed properties.. for example if you hard code myobj[0].myproperty in validator it works. So the only piece of the validator puzzle thats missing is generating the js array of indexed form elements .. If i'm not making any sense, have a before and after look at the javascript. I think fixing the validator to generate indexed elements would be the fastest way of dealing with this, or add this to bugzilla. A hack could be to just layer some most js onto the page. If you using the html:errors stuff and cant get it to spit them out, you could try bean:messages and spit out the errors like that, they are there (the errors) they're just hiding. logic:messagesPresent pre html:messages id=error bean:write name=error/ /html:messages pre /logic:messagesPresent rather than pre html:errors / /pre Cheers Mark __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: ANYONE Know How To Validate Nested Form Beans?
Well it seems to be a mystery still whether it does or does not. Sounds like Mark has done it but he's checking to see if it was custom or using built in functionality. I guess it was just an assumption on my part that it DID have it built in because it seems pretty fundamental/basic to me... compared to some of the much more advanced capabilities it has built in. Anyway, thanks for the code sample. It looks like I may end up using some of that. I'll wait and see what Mark digs up. I think worst case scenario, I'll use some bean instrospection upon submission to look for all property values that are instances of ValidatorForm or Collections... then recursively invoke the validator on each one it finds, and add the errors collection to each form bean (a property they all implement through an interface). I guess that wouldn't be bad... but I just thought it was built in. --- Richard Mixon [EMAIL PROTECTED] wrote: Terry, Thanks for asking the question - I've asked a similar question in the past. I did not realize that validator has some collection support, I may look further into that. __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]