Re: getting non-struts form elements
There are 2 problems with this - First (and biggest) it doesn't seem to work for me. I setup a test page, and am attempting to print out the form element names using request.getParameterNames(). This is the code I have: System.out.println("before"); for(Enumeration e = request.getParameterNames(); e.hasMoreElements(); ) { String curr = (String) e.nextElement(); System.out.println("curr: " + curr); } System.out.println("after"); And the only output I get is: before after None of the fields in my form are being displayed. Any idea what I'm doing wrong? Perhaps does the form have to GET instead of POST? (In which case that won't work, because it would involve changing the form... The second problem is - even if I could get this to work, how do I read in FILE parameters - that was one of the specifications of my original problem - I had to be able to read both string and file form field types. Thanks, Matt - Original Message - From: "Avinash Gangadharan" <[EMAIL PROTECTED]> To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]> Sent: Friday, May 14, 2004 5:08 PM Subject: RE: getting non-struts form elements > Matt, > In your action class, you have the request and the response object which > will get you all your form elements > > public ActionForward execute(ActionMapping mapping, ActionForm form, > HttpServletRequest request, HttpServletResponse response) > throws java.lang.Exception { > String xxx = ( String ) request.getParameter("xxx"); > // now do anything with xxx > } > > As far as configuring your action in the struts-config, you can associate an > empty form to your action : > > name="emptyForm" > type="org.apache.struts.action.DynaActionForm"/> > > > and then add 'name="emptyForm"' in your action mapping: > > type="your.action.type" > name="emptyForm" > scope="request" > > >name="..." > path="..."/> > > > > I hope this is what you are looking for. > > Avinash > > > > > -Original Message- > From: Matt Bathje [mailto:[EMAIL PROTECTED] > Sent: Friday, May 14, 2004 2:45 PM > To: Struts Users Mailing List > Subject: getting non-struts form elements > > > Hi all. > > I have a form that is not a struts form bean (no actionform, no dynaform, > nothing...) > > Is it possible to have this submit to a struts action, and read the form > elements somehow? I need to be able to read simple (String) elements as well > as multi-part (formfile) elements from the form. > > Any way to do it in struts, or do I just need to give up and make something > non-struts to do it? > > > > Thanks, > Matt Bathje > > > - > 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: getting non-struts form elements
Good, that's what I had assumed was the case. The app I'm converting next week was based on a home-grown framework, and at least in the first iteration it's easiest to not even think about ActionForms. We have Value Object classes that are akin to ActionForms, except that they are just transfer mechanisms, no notion of validation whatsoever, and then we have App Controllers, which are Actions. So, my conversion should mostly just amount to changing the classes these extend from (the Actions anyway), and then converting my Profile XML to struts-config.xml form, not too big a deal in theory. Knowing that this assumption was correct removes one potential hassle. Thanks! From: Avinash Gangadharan <[EMAIL PROTECTED]> Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> To: 'Struts Users Mailing List' <[EMAIL PROTECTED]> Subject: RE: getting non-struts form elements Date: Fri, 14 May 2004 15:46:24 -0700 Exactly, that's true. If you just want a struts action performing your request processing you do not need any form. Your mapping will look something like. And in your action class you can then do the same thing as earlier : public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws java.lang.Exception { String xxx = ( String ) request.getParameter("xxx"); // now do anything with xxx } But as pointed out in one of the mails in the thread, without an ActionForm, you won't be able to use the Struts and related tags and form validation. -Original Message- From: Joe Hertz [mailto:[EMAIL PROTECTED] Sent: Friday, May 14, 2004 3:27 PM To: 'Struts Users Mailing List' Subject: RE: getting non-struts form elements Actually, it's not at all the case. To merge a couple of simultaneous threads here, my app has a link that lets the user toggle between languages. It calls an action that cares nothing about any form. It just looks at the current Locale and goes on :-) You only need an ActionForm in your action if you need to get told something about what to do by the user. If the fact the action is being called is sufficient knowledge, then dispense with the form declaration. > -Original Message- > From: None None [mailto:[EMAIL PROTECTED] > Sent: Friday, May 14, 2004 6:12 PM > To: [EMAIL PROTECTED] > Subject: RE: getting non-struts form elements > > > Is it the case that every Action MUST be associated with an > ActionForm? > Next week I have to start converting an app to Struts, and one of the > assumptions I've been making is that I can just NOT associate > any ActionForm > with the Actions. As you say it's not a big deal, I can just > do the empty > form like you said, but I'd like to know if that's the only way... > > > >From: Avinash Gangadharan <[EMAIL PROTECTED]> > >Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> > >To: 'Struts Users Mailing List' <[EMAIL PROTECTED]> > >Subject: RE: getting non-struts form elements > >Date: Fri, 14 May 2004 15:08:10 -0700 > > > >Matt, > >In your action class, you have the request and the response object > >which will get you all your form elements > > > >public ActionForward execute(ActionMapping mapping, ActionForm form, > > HttpServletRequest request, HttpServletResponse response) > > throws java.lang.Exception { > > String xxx = ( String ) request.getParameter("xxx"); > > // now do anything with xxx > >} > > > >As far as configuring your action in the struts-config, you can > >associate > >an > >empty form to your action : > > > > > name="emptyForm" > > type="org.apache.struts.action.DynaActionForm"/> > > > > > >and then add 'name="emptyForm"' in your action mapping: > > > > > type="your.action.type" > > name="emptyForm" > > scope="request" > > > > >> name="..." > > path="..."/> > > > > > > > >I hope this is what you are looking for. > > > >Avinash > > > > > > > > > >-Original Message- > >From: Matt Bathje [mailto:[EMAIL PROTECTED] > >Sent: Friday, May 14, 2004 2:45 PM > >To: Struts Users Mailing List > >Subject: getting non-struts form elements > > > > > >Hi all. > > > >I have a form that is not a struts form bean (no actionform, no > >dynaform, > >nothing.
RE: getting non-struts form elements
Exactly, that's true. If you just want a struts action performing your request processing you do not need any form. Your mapping will look something like. And in your action class you can then do the same thing as earlier : public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws java.lang.Exception { String xxx = ( String ) request.getParameter("xxx"); // now do anything with xxx } But as pointed out in one of the mails in the thread, without an ActionForm, you won't be able to use the Struts and related tags and form validation. -Original Message- From: Joe Hertz [mailto:[EMAIL PROTECTED] Sent: Friday, May 14, 2004 3:27 PM To: 'Struts Users Mailing List' Subject: RE: getting non-struts form elements Actually, it's not at all the case. To merge a couple of simultaneous threads here, my app has a link that lets the user toggle between languages. It calls an action that cares nothing about any form. It just looks at the current Locale and goes on :-) You only need an ActionForm in your action if you need to get told something about what to do by the user. If the fact the action is being called is sufficient knowledge, then dispense with the form declaration. > -Original Message- > From: None None [mailto:[EMAIL PROTECTED] > Sent: Friday, May 14, 2004 6:12 PM > To: [EMAIL PROTECTED] > Subject: RE: getting non-struts form elements > > > Is it the case that every Action MUST be associated with an > ActionForm? > Next week I have to start converting an app to Struts, and one of the > assumptions I've been making is that I can just NOT associate > any ActionForm > with the Actions. As you say it's not a big deal, I can just > do the empty > form like you said, but I'd like to know if that's the only way... > > > >From: Avinash Gangadharan <[EMAIL PROTECTED]> > >Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> > >To: 'Struts Users Mailing List' <[EMAIL PROTECTED]> > >Subject: RE: getting non-struts form elements > >Date: Fri, 14 May 2004 15:08:10 -0700 > > > >Matt, > >In your action class, you have the request and the response object > >which will get you all your form elements > > > >public ActionForward execute(ActionMapping mapping, ActionForm form, > > HttpServletRequest request, HttpServletResponse response) > > throws java.lang.Exception { > > String xxx = ( String ) request.getParameter("xxx"); > > // now do anything with xxx > >} > > > >As far as configuring your action in the struts-config, you can > >associate > >an > >empty form to your action : > > > > > name="emptyForm" > > type="org.apache.struts.action.DynaActionForm"/> > > > > > >and then add 'name="emptyForm"' in your action mapping: > > > > > type="your.action.type" > > name="emptyForm" > > scope="request" > > > > >> name="..." > > path="..."/> > > > > > > > >I hope this is what you are looking for. > > > >Avinash > > > > > > > > > >-Original Message- > >From: Matt Bathje [mailto:[EMAIL PROTECTED] > >Sent: Friday, May 14, 2004 2:45 PM > >To: Struts Users Mailing List > >Subject: getting non-struts form elements > > > > > >Hi all. > > > >I have a form that is not a struts form bean (no actionform, no > >dynaform, > >nothing...) > > > >Is it possible to have this submit to a struts action, and read the > >form elements somehow? I need to be able to read simple (String) > >elements as well as multi-part (formfile) elements from the form. > > > >Any way to do it in struts, or do I just need to give up and make > >something non-struts to do it? > > > > > > > >Thanks, > >Matt Bathje > > > > > >- > >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] > > > > _ > Check out the coupons and bargains on MSN Offers! http://youroffers.msn.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] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: getting non-struts form elements
Actually, it's not at all the case. To merge a couple of simultaneous threads here, my app has a link that lets the user toggle between languages. It calls an action that cares nothing about any form. It just looks at the current Locale and goes on :-) You only need an ActionForm in your action if you need to get told something about what to do by the user. If the fact the action is being called is sufficient knowledge, then dispense with the form declaration. > -Original Message- > From: None None [mailto:[EMAIL PROTECTED] > Sent: Friday, May 14, 2004 6:12 PM > To: [EMAIL PROTECTED] > Subject: RE: getting non-struts form elements > > > Is it the case that every Action MUST be associated with an > ActionForm? > Next week I have to start converting an app to Struts, and one of the > assumptions I've been making is that I can just NOT associate > any ActionForm > with the Actions. As you say it's not a big deal, I can just > do the empty > form like you said, but I'd like to know if that's the only way... > > > >From: Avinash Gangadharan <[EMAIL PROTECTED]> > >Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> > >To: 'Struts Users Mailing List' <[EMAIL PROTECTED]> > >Subject: RE: getting non-struts form elements > >Date: Fri, 14 May 2004 15:08:10 -0700 > > > >Matt, > >In your action class, you have the request and the response object > >which will get you all your form elements > > > >public ActionForward execute(ActionMapping mapping, ActionForm form, > > HttpServletRequest request, HttpServletResponse response) > > throws java.lang.Exception { > > String xxx = ( String ) request.getParameter("xxx"); > > // now do anything with xxx > >} > > > >As far as configuring your action in the struts-config, you can > >associate > >an > >empty form to your action : > > > > > name="emptyForm" > > type="org.apache.struts.action.DynaActionForm"/> > > > > > >and then add 'name="emptyForm"' in your action mapping: > > > > > type="your.action.type" > > name="emptyForm" > > scope="request" > > > > >> name="..." > > path="..."/> > > > > > > > >I hope this is what you are looking for. > > > >Avinash > > > > > > > > > >-Original Message- > >From: Matt Bathje [mailto:[EMAIL PROTECTED] > >Sent: Friday, May 14, 2004 2:45 PM > >To: Struts Users Mailing List > >Subject: getting non-struts form elements > > > > > >Hi all. > > > >I have a form that is not a struts form bean (no actionform, no > >dynaform, > >nothing...) > > > >Is it possible to have this submit to a struts action, and read the > >form elements somehow? I need to be able to read simple (String) > >elements as well as multi-part (formfile) elements from the form. > > > >Any way to do it in struts, or do I just need to give up and make > >something non-struts to do it? > > > > > > > >Thanks, > >Matt Bathje > > > > > >- > >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] > > > > _ > Check out the coupons and bargains on MSN Offers! http://youroffers.msn.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: getting non-struts form elements
You can use request.getParameter()/getParameterValues() inside an Action to retrieve form values without using an ActionForm. However, without an ActionForm, you won't be able to use the Struts and related tags and form validation. --- None None <[EMAIL PROTECTED]> wrote: > Is it the case that every Action MUST be associated with an ActionForm? > Next week I have to start converting an app to Struts, and one of the > assumptions I've been making is that I can just NOT associate any > ActionForm > with the Actions. As you say it's not a big deal, I can just do the empty > form like you said, but I'd like to know if that's the only way... > > > >From: Avinash Gangadharan <[EMAIL PROTECTED]> > >Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> > >To: 'Struts Users Mailing List' <[EMAIL PROTECTED]> > >Subject: RE: getting non-struts form elements > >Date: Fri, 14 May 2004 15:08:10 -0700 > > > >Matt, > >In your action class, you have the request and the response object which > >will get you all your form elements > > > >public ActionForward execute(ActionMapping mapping, ActionForm form, > > HttpServletRequest request, HttpServletResponse response) > > throws java.lang.Exception { > > String xxx = ( String ) request.getParameter("xxx"); > > // now do anything with xxx > >} > > > >As far as configuring your action in the struts-config, you can associate > >an > >empty form to your action : > > > > > name="emptyForm" > > type="org.apache.struts.action.DynaActionForm"/> > > > > > >and then add 'name="emptyForm"' in your action mapping: > > > > > type="your.action.type" > > name="emptyForm" > > scope="request" > > > > >> name="..." > > path="..."/> > > > > > > > >I hope this is what you are looking for. > > > >Avinash > > > > > > > > > >-Original Message- > >From: Matt Bathje [mailto:[EMAIL PROTECTED] > >Sent: Friday, May 14, 2004 2:45 PM > >To: Struts Users Mailing List > >Subject: getting non-struts form elements > > > > > >Hi all. > > > >I have a form that is not a struts form bean (no actionform, no dynaform, > >nothing...) > > > >Is it possible to have this submit to a struts action, and read the form > >elements somehow? I need to be able to read simple (String) elements as > >well > >as multi-part (formfile) elements from the form. > > > >Any way to do it in struts, or do I just need to give up and make > something > >non-struts to do it? > > > > > > > >Thanks, > >Matt Bathje > > > > > >- > >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] > > > > _ > Check out the coupons and bargains on MSN Offers! http://youroffers.msn.com > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > __ Do you Yahoo!? SBC Yahoo! - Internet access at a great low price. http://promo.yahoo.com/sbc/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: getting non-struts form elements
Is it the case that every Action MUST be associated with an ActionForm? Next week I have to start converting an app to Struts, and one of the assumptions I've been making is that I can just NOT associate any ActionForm with the Actions. As you say it's not a big deal, I can just do the empty form like you said, but I'd like to know if that's the only way... From: Avinash Gangadharan <[EMAIL PROTECTED]> Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> To: 'Struts Users Mailing List' <[EMAIL PROTECTED]> Subject: RE: getting non-struts form elements Date: Fri, 14 May 2004 15:08:10 -0700 Matt, In your action class, you have the request and the response object which will get you all your form elements public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws java.lang.Exception { String xxx = ( String ) request.getParameter("xxx"); // now do anything with xxx } As far as configuring your action in the struts-config, you can associate an empty form to your action : name="emptyForm" type="org.apache.struts.action.DynaActionForm"/> and then add 'name="emptyForm"' in your action mapping: I hope this is what you are looking for. Avinash -Original Message- From: Matt Bathje [mailto:[EMAIL PROTECTED] Sent: Friday, May 14, 2004 2:45 PM To: Struts Users Mailing List Subject: getting non-struts form elements Hi all. I have a form that is not a struts form bean (no actionform, no dynaform, nothing...) Is it possible to have this submit to a struts action, and read the form elements somehow? I need to be able to read simple (String) elements as well as multi-part (formfile) elements from the form. Any way to do it in struts, or do I just need to give up and make something non-struts to do it? Thanks, Matt Bathje - 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] _ Check out the coupons and bargains on MSN Offers! http://youroffers.msn.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getting non-struts form elements
At 4:44 PM -0500 5/14/04, Matt Bathje wrote: Hi all. I have a form that is not a struts form bean (no actionform, no dynaform, nothing...) Is it possible to have this submit to a struts action, and read the form elements somehow? I need to be able to read simple (String) elements as well as multi-part (formfile) elements from the form. Any way to do it in struts, or do I just need to give up and make something non-struts to do it? you can always use request.getParameter(String) Any other solution to get a populated ActionForm would be way too much trouble to even consider. Joe -- Joe Germuska [EMAIL PROTECTED] http://blog.germuska.com "Imagine if every Thursday your shoes exploded if you tied them the usual way. This happens to us all the time with computers, and nobody thinks of complaining." -- Jef Raskin - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: getting non-struts form elements
Matt, In your action class, you have the request and the response object which will get you all your form elements public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws java.lang.Exception { String xxx = ( String ) request.getParameter("xxx"); // now do anything with xxx } As far as configuring your action in the struts-config, you can associate an empty form to your action : and then add 'name="emptyForm"' in your action mapping: I hope this is what you are looking for. Avinash -Original Message- From: Matt Bathje [mailto:[EMAIL PROTECTED] Sent: Friday, May 14, 2004 2:45 PM To: Struts Users Mailing List Subject: getting non-struts form elements Hi all. I have a form that is not a struts form bean (no actionform, no dynaform, nothing...) Is it possible to have this submit to a struts action, and read the form elements somehow? I need to be able to read simple (String) elements as well as multi-part (formfile) elements from the form. Any way to do it in struts, or do I just need to give up and make something non-struts to do it? Thanks, Matt Bathje - 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: getting non-struts form elements
Unless I'm missing something in your question, the answer is that you can access the elements in the request object, they should still be there when the submission gets to your Action. From: "Matt Bathje" <[EMAIL PROTECTED]> Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> To: "Struts Users Mailing List" <[EMAIL PROTECTED]> Subject: getting non-struts form elements Date: Fri, 14 May 2004 16:44:44 -0500 Hi all. I have a form that is not a struts form bean (no actionform, no dynaform, nothing...) Is it possible to have this submit to a struts action, and read the form elements somehow? I need to be able to read simple (String) elements as well as multi-part (formfile) elements from the form. Any way to do it in struts, or do I just need to give up and make something non-struts to do it? Thanks, Matt Bathje - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] _ Getting married? Find tips, tools and the latest trends at MSN Life Events. http://lifeevents.msn.com/category.aspx?cid=married - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: getting non-struts form elements
If you want to submit it to a struts action, then presumably you can control the action element of the form tag. If so, why can't you associate the action with a struts form too? It would help to have more information. -Joe > -Original Message- > From: Matt Bathje [mailto:[EMAIL PROTECTED] > Sent: Friday, May 14, 2004 5:45 PM > To: Struts Users Mailing List > Subject: getting non-struts form elements > > > Hi all. > > I have a form that is not a struts form bean (no actionform, > no dynaform, > nothing...) > > Is it possible to have this submit to a struts action, and > read the form elements somehow? I need to be able to read > simple (String) elements as well as multi-part (formfile) > elements from the form. > > Any way to do it in struts, or do I just need to give up and > make something non-struts to do it? > > > > Thanks, > Matt Bathje > > > - > 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]
getting non-struts form elements
Hi all. I have a form that is not a struts form bean (no actionform, no dynaform, nothing...) Is it possible to have this submit to a struts action, and read the form elements somehow? I need to be able to read simple (String) elements as well as multi-part (formfile) elements from the form. Any way to do it in struts, or do I just need to give up and make something non-struts to do it? Thanks, Matt Bathje - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]