Re: Validation - Require One of Multiple Fields
Thanks, but that is for making sure two fields are the same - I have mastered that one... What I am after is making sure at least 1 of a group of fields has a value filled in. I don't care which one so long as at least one field is filled in... Dan Tran wrote: http://jakarta.apache.org/struts/userGuide/dev_validator.html may help. Look for twofield example. -D - Original Message - From: Joey Ebright [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, March 20, 2003 10:54 PM Subject: Validation - Require One of Multiple Fields Hello, I am looking for a way to validate that the user filled in at least one field of a possible many fields. These fields represent search criteria to use for constructing an SQL query to a database and I want to ensure the user gives me at least one item to search on... I looked at the requiredif validator but it is only server-side and I want both client side and server side validation. If I just wanted server side I could have written the validation code in my ActionForm myself... I did come up with some rudimentary JavaScript to do this but am lost at how to do this in the same manner in a generic fashion on the server side. The elegant approach of the validator framework on the client side is that it passes an array of fields that are to be validated and the validate method is only called once. This allowed me in my JavaScript to just see if the addition of all the fields put together equaled an empty string. On the server side, the framework differs in its approach to validation of fields and each field to be validated calls the validating method once. Hence without reworking the validator framework, the same approach cannot be used - unless of course I am mistaken. Anyone else got some ideas out there??? TIA, Joey - 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]
Validation - Require One of Multiple Fields
Hello, I am looking for a way to validate that the user filled in at least one field of a possible many fields. These fields represent search criteria to use for constructing an SQL query to a database and I want to ensure the user gives me at least one item to search on... I looked at the requiredif validator but it is only server-side and I want both client side and server side validation. If I just wanted server side I could have written the validation code in my ActionForm myself... I did come up with some rudimentary JavaScript to do this but am lost at how to do this in the same manner in a generic fashion on the server side. The elegant approach of the validator framework on the client side is that it passes an array of fields that are to be validated and the validate method is only called once. This allowed me in my JavaScript to just see if the addition of all the fields put together equaled an empty string. On the server side, the framework differs in its approach to validation of fields and each field to be validated calls the validating method once. Hence without reworking the validator framework, the same approach cannot be used - unless of course I am mistaken. Anyone else got some ideas out there??? TIA, Joey - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Control Access
The documentation that comes with Struts and the examples actually show a great example of doing this. Basically there is a tag that you place at the top of each JSP page that checks to see if the user has an object in session (has logged in) and if not, redirects them to the login page. Hope this helps... mahesh kagitha wrote: Can any one please explain the following... I'm developing an application which has login page(JSP) to access the application and I should allow only the successfully logged in users to navigate my application otherwise direct to login page. My question here is... How can I do that.? Thanks in Advance. - Do you Yahoo!? Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop! - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: File Upload with Invalid or Missing File Name
See the thread I started Problem with empty file upload field. I found mozilla was the problem. I was running 0.99 and upgrading fixed the problem. Let me know how it goes for you... Jörg Maurer wrote: Have you downloaded source or binary? Try like myself source und recompile YS?!?! -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Montag, 10. Februar 2003 20:00 To: [EMAIL PROTECTED] Subject: File Upload with Invalid or Missing File Name Here is what I did: 1. Downloaded Tomcat 4.1.18 and installed. 2. Downloaded Struts 1.1B3 and copied struts-upload.war to the webapps directory of my Tomcat install from step 1. 3. Set my JAVA_HOME environment variable to point to the location of my 1.3 Java (1.3.1_04). 4. Started Tomcat so that struts-upload is deployed. 5. From Mozilla, accessed http://localhost:8080/struts-upload;. 6. The file upload screen displays properly and if I browse to a legitimate file and press submit, then the file is uploaded without error. However, if I leave the file name empty or enter an invalid file name, then I get the error shown below: Others on this list have apparently had success with empty file names. So I am very confused as to why I still see the populate error. I have tried Struts 1.1B2 and Struts 1.1B3 and JDK 1.4.1 as well as 1.3.1 as well as earlier versions of Tomcat. All attempts with a blank file name lead to the same error. I have exhausted everything that I can try, so help would be greatly appreciated. Cynthia Jeness java.lang.IllegalArgumentException: argument type mismatch at java.lang.reflect.Method.invoke(Native Method) at org.apache.commons.beanutils.PropertyUtils.setSimpleProperty(PropertyUti ls.java:1789) at org.apache.commons.beanutils.PropertyUtils.setNestedProperty(PropertyUti ls.java:1684) at org.apache.commons.beanutils.PropertyUtils.setProperty(PropertyUtils.jav a:1713) at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:924) at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:729) at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1097) at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcess or.java:798) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java: 254) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1422) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:523) at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica tionFilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt erChain.java:193) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv e.java:260) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i nvokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4 80) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv e.java:191) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i nvokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4 80) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:241 5) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java :180) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i nvokeNext(StandardPipeline.java:643) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherVa lve.java:170) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i nvokeNext(StandardPipeline.java:641) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java :172) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i nvokeNext(StandardPipeline.java:641) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4 80) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve. java:174) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i nvokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4 80) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:43 2) at
Saving form data
Is there any piece of functionality in Struts that I can take advantage of in order to save and restore form data entered by the user as the page is reloaded. For example I am displaying an html table that shows a paged view of the data. The user can click on page 1,2,3, etc. Clicking on these links reloads the SAME page, but with the next subset of data in the html table. The problem I am running into is that the page in question also has a form area where the user is supposed to fill in information and submit it. When the user clicks on the links to page through the table, the data they entered in the form fields is lost. In the past, I have made round trips to the server and submitted the form data, storing it in session to later be retrieved. I want a better approach now though. I was considering passing the form data in a querystring but am afraid I will hit its size limit. Any ideas as to how this can best be accomplished? -Joey - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem with empty file upload field
I do not think it does, although I have not tested it - I don't run Windows, sorry. However after reading other people's posts and the bug report from mozilla I would make an assumption that it does not. It would be interesting to hear back from anyone if they can state otherwise. Peng Tuck Kwok wrote: Does it affect other browsers like ie ? Joey Ebright wrote: I found that my problem stemmed from a bug in Mozilla 0.99. Once I upgraded my Mozilla browser to version 1.2.1 the problem went away. You can find details on this bug here: http://bugzilla.mozilla.org/show_bug.cgi?id=132069 Thanks for all who offered feedback!!! Joey Ebright wrote: I too have the same problem - whenever the user does not supply a file to upload I get an exception. I have tried the 1.1-b3 release of struts and the 1.6 release of the commons and recieve the same error from BeanUtils.populate - IllegalArgumentException... Have you made any progress on this front? -Joey - 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] - 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: Problem with empty file upload field
What mozilla is doing is not populating the necessary information to the server for the file upload when the user does not enter a file at all (not just failing to use a FormFile versus a String) . If you read the thread on the bug report I attached below this will become more clear Cynthia. Mozilla fixed this bug in order to be compatible with other browsers so this leads me to believe this behavior is not present in other browsers. I have not confirmed this though on IE, but Netscape is probably okay since it is Mozilla-based. As for a workaround, the best I got before I found that upgrading Mozilla fixed my problem, was to do client-side validation with JavaScript. In the end though this only ensured the user did specify a value for the file to upload. It did not ensure the file was valid, which BTW if the file is not valid you will get the same error :( If I had to write a more elegant workaround, I would look specifically for this error condition in an exception handler and return a more sophisticated error to the user if the did not enter a file or entered an invalid file (e.g. file does not exist in path specified). Good luck, let me know how it turns out! -Joey Cynthia Jeness wrote: Since I am running Mozilla 0.99, this may be the cause of the problem; however, we have little control over what browsers our customers choose to run. If Mozilla does not send back a file name, then that piece of information can be missing from my error message to the client. However, the error itself needs to be handled more gracefully. It would be daunting to the normal user to be presented with an invalid argument exception on bean populate and a stack trace. I have tried to understand where the error occurs. It seems to me that when Mozilla cannot process the filename that the user has entered, the file name is sent back as part of the request parameter stream and the commons populate routine is handling it like a string. It fails because it cannot find a write method for the parameter which accepts a String. I have tried providing a setter which accepts an Object; however, then the file transfer does not occur when a proper file name is supplied. I have also tried two different setters -- one with a String and one with the FormFile. This also does not work. So, in short, are there any suggestions for a workaround or plans to handle the error situation more gracefully in Struts or the commons-beanutils routines? Of course, if Mozilla 0.99 is the only browser that has this problem and Netscape 4.6+ or IE work correctly along with later versions of Mozilla, then a workaround may not be as necessary. Cynthia Jeness Joey Ebright wrote: I found that my problem stemmed from a bug in Mozilla 0.99. Once I upgraded my Mozilla browser to version 1.2.1 the problem went away. You can find details on this bug here: http://bugzilla.mozilla.org/show_bug.cgi?id=132069 Thanks for all who offered feedback!!! Joey Ebright wrote: I too have the same problem - whenever the user does not supply a file to upload I get an exception. I have tried the 1.1-b3 release of struts and the 1.6 release of the commons and recieve the same error from BeanUtils.populate - IllegalArgumentException... Have you made any progress on this front? -Joey - 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] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how to Validate DATE?
Seems like it should work to me. Do you know your JavaScript is working properly? I might look there. Additionally, I think the Struts In Action book explains this rather well. Maybe you will find that you missed something. You can find Chapter 12 here: http://www.theserverside.com//resources/article.jsp?l=StrutsInAction [EMAIL PROTECTED] wrote: Hello, my date validation doesn't work on client (jsp) side. I need validate date in MM/dd/yy format. in validation.xml : formset form name=financeChartForm field property=startDate depends=required,date arg0 key=prompt.startDate/ msg name=required key=error.startDate.required/ /field field property=endDate depends=required,date arg0 key=prompt.endDate/ msg name=required key=error.endDate.required/ /field var var-namedatePattern/var-name var-valueMM/dd/yy/var-value /var /form /formset plugin includes in struts-config.xml and html:form action=/chart2 onsubmit=return validateFinanceChartForm(this); html:javascript formName=financeChartForm dynamicJavascript=true staticJavascript=false/ script language=Javascript1.1 src=jsp/staticJavascript.jsp/script into jsp. do I missing anything. Best Regards. Michael. - 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: Problem with empty file upload field
I found that my problem stemmed from a bug in Mozilla 0.99. Once I upgraded my Mozilla browser to version 1.2.1 the problem went away. You can find details on this bug here: http://bugzilla.mozilla.org/show_bug.cgi?id=132069 Thanks for all who offered feedback!!! Joey Ebright wrote: I too have the same problem - whenever the user does not supply a file to upload I get an exception. I have tried the 1.1-b3 release of struts and the 1.6 release of the commons and recieve the same error from BeanUtils.populate - IllegalArgumentException... Have you made any progress on this front? -Joey - 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: Problem with empty file upload field
I too have the same problem - whenever the user does not supply a file to upload I get an exception. I have tried the 1.1-b3 release of struts and the 1.6 release of the commons and recieve the same error from BeanUtils.populate - IllegalArgumentException... Have you made any progress on this front? -Joey - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem with empty file upload field
What happens if the user does not specify a file to upload and you submit the form? Do you get an error? How do you handle this? Jörg Maurer wrote: Just for info - I use struts 1.3b nb and built upload func into my current app - no problem. Remark what i corrected from wrong in first step : 1. html:form action=...enctype=multipart/form-data - !! 2. use as property a property of type FileForm from org.apache.struts - it was a crazy idea to me to put a Form into a Form first ;-) 3. erhm, and don´t open input stream on blank filename Ciao Jörg -Original Message- From: Joey Ebright [mailto:[EMAIL PROTECTED]] Sent: Sonntag, 09. Februar 2003 22:20 To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: Problem with empty file upload field I too have the same problem - whenever the user does not supply a file to upload I get an exception. I have tried the 1.1-b3 release of struts and the 1.6 release of the commons and recieve the same error from BeanUtils.populate - IllegalArgumentException... Have you made any progress on this front? -Joey - 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] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem with empty file upload field
Wow, surprised you never got an error!?! I am using struts 1.1b3 and recieve an IllegalArgumentException (argument type mismatch) from BeanUtils.populate when the user does not specify a file to upload (leaves form entry blank). I verified the following: - I have my form's enctype set to multipart/form-data - I have my form bean's property for the file to upload declared as type FormFile - Even though my struts-config says that my form bean should validate (validate=true), the validate() method is never called. The exception comes before the validate() method gets a change to be invoked. This leads me to assume that it is the binding of the html form values to the form bean that is the culprit... I have also verified this behavior under struts 1.02. If you do not receive this error, then can you tell me what version of struts you are running? Thanks!!! Jörg Maurer wrote: Never get an error- sorry! Send mor info? -Original Message- From: Joey Ebright [mailto:[EMAIL PROTECTED]] Sent: Montag, 10. Februar 2003 02:34 To: Struts Users Mailing List Subject: Re: Problem with empty file upload field What happens if the user does not specify a file to upload and you submit the form? Do you get an error? How do you handle this? Jörg Maurer wrote: Just for info - I use struts 1.3b nb and built upload func into my current app - no problem. Remark what i corrected from wrong in first step : 1. html:form action=...enctype=multipart/form-data - !! 2. use as property a property of type FileForm from org.apache.struts - it was a crazy idea to me to put a Form into a Form first ;-) 3. erhm, and don´t open input stream on blank filename Ciao Jörg -Original Message- From: Joey Ebright [mailto:[EMAIL PROTECTED]] Sent: Sonntag, 09. Februar 2003 22:20 To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: Problem with empty file upload field I too have the same problem - whenever the user does not supply a file to upload I get an exception. I have tried the 1.1-b3 release of struts and the 1.6 release of the commons and recieve the same error from BeanUtils.populate - IllegalArgumentException... Have you made any progress on this front? -Joey - 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] - 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: Problem with empty file upload field
Thanks Claude, I was beginning to think this might be the case. I guess it is time to brush up on my javascript :) Hopefully by the time I get the client side validation done, someone will come up with a solution to get the server side validation for the html:file to work. Apparently it works for Jörg but I am not sure which version of struts he is running... -Joey Claude Betancourt wrote: Joey, Since you need to cover your butt on both sides, client and server, do a simple javascript validation on the form as it is being submitted to make sure something was entered in the file input field. function validateUploadForm(theForm) { if (theForm.myFile.value==) { alert(Please select a file to upload from your workstation by clicking the Browse button.); theForm.myFile.focus(); return false; } } After that, your action should be smart enough to check for any of the obvious file (FileInputStream) properties, like contentType, fileName or fileSize (to be 0). Look at the API for java.io.FileInputStream -c - Original Message - From: Joey Ebright [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Sunday, February 09, 2003 8:33 PM Subject: Re: Problem with empty file upload field What happens if the user does not specify a file to upload and you submit the form? Do you get an error? How do you handle this? Jörg Maurer wrote: Just for info - I use struts 1.3b nb and built upload func into my current app - no problem. Remark what i corrected from wrong in first step : 1. html:form action=...enctype=multipart/form-data - !! 2. use as property a property of type FileForm from org.apache.struts - it was a crazy idea to me to put a Form into a Form first ;-) 3. erhm, and don´t open input stream on blank filename Ciao Jörg -Original Message- From: Joey Ebright [mailto:[EMAIL PROTECTED]] Sent: Sonntag, 09. Februar 2003 22:20 To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: RE: Problem with empty file upload field I too have the same problem - whenever the user does not supply a file to upload I get an exception. I have tried the 1.1-b3 release of struts and the 1.6 release of the commons and recieve the same error from BeanUtils.populate - IllegalArgumentException... Have you made any progress on this front? -Joey - 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] - 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]