> -----Original Message----- > From: Ciaran Hanley [mailto:[EMAIL PROTECTED] > Sent: Thursday, December 02, 2004 11:15 AM > To: 'Struts Users Mailing List'; [EMAIL PROTECTED] > Subject: RE: Checking radio button based on object value > > > Ok so I've tried the following but still I get the default > values on the > form when it's forwarded to the JSP. > > <action path="/options" > type="ie.sentenial.application.actions.UserAction" > name="optionsForm" > scope="request" > input="/templates/optionsForm.jsp" > attribute="optionsForm" > > </action> > > My action class has the following: > > public ActionForward execute(ActionMapping mapping, ActionForm form, > HttpServletRequest request, HttpServletResponse response) throws > IOException, ServletException > { > > if(request.getParameter("action").equals("useroptions")) > { > // set the options form values to those of the current user
This bugs me: > ClientOptionsForm optionsForm = setOptions(request); You shouldn't have to set options from the request to fill the form. ClientOptionsForm optionsForm = (ClientOptionsForm)form; putYourOptionsFromDatabase( optionsForm); > > form = (ClientOptionsForm) optionsForm; > return(mapping.findForward("viewoptions")); > } > > The saving part of the action works fine, all the new values > overwrite the > old. The problem is still showing the previously chosen > values upon viewing > the JSP. > > Any help would be appreciated. > Thanks > > -----Original Message----- > From: Lee Harrington [mailto:[EMAIL PROTECTED] > Sent: 02 December 2004 16:13 > To: Struts Users Mailing List > Subject: Re: Checking radio button based on object value > > Struts handles the creating of the form for you. You should not be > "creating" a form nor "storing it" in the session scope. > > Look at the parameters on your Action's execute. There is a > "ActionForm form" -- you cast that form to your form's type: > > MyFormClass myform = (MyFormClass) form; > > then you manipulate it's properties. You don't have to put it back in > the session -- it exists in the request scope and is managed by > struts. > > Lee > > > On Thu, 2 Dec 2004 14:59:54 -0000, Ciaran Hanley > <[EMAIL PROTECTED]> wrote: > > Thanks for your replies. > > > > I followed your suggestions, now I create a form in my > action class, set > its > > values based on the session object, store it in session > scope and forward > to > > the JSP but the form produced has the default values of my > action form > > instead of the values in the form object I have created. > Any ideas why > this > > happens? > > > > Thanks > > > > > > > > -----Original Message----- > > From: Jim Barrows [mailto:[EMAIL PROTECTED] > > Sent: 01 December 2004 19:52 > > To: Struts Users Mailing List > > Subject: RE: Checking radio button based on object value > > > > > -----Original Message----- > > > From: Ciaran Hanley [mailto:[EMAIL PROTECTED] > > > Sent: Wednesday, December 01, 2004 12:11 PM > > > To: 'Struts Users Mailing List'; [EMAIL PROTECTED] > > > Subject: RE: Checking radio button based on object value > > > > > > > > > Ok sounds like this could solve my problem. How do I get the > > > object from the > > > session and populate the form? My ActionForm does not have the > > > HttpServletRequest visible to it as it is created with a > no parameter > > > constructor. > > > > Simple... in the action that forwards to the jsp.... you do > have an action > > forwarding to the jsp right? :) > > Something like > > if( object in session) { > > copy object to form; > > } > > forward to jsp > > > > > > > > public OptionsForm() > > > { > > > } > > > > > > My question now is how/where can I call > > > > > > Options options = > > > (Options)request.getSession().getAttribute("userOptions"); > > > > > > From within my ActionForm class > > > > > > Thanks > > > > > > -----Original Message----- > > > From: Lee Harrington [mailto:[EMAIL PROTECTED] > > > Sent: 01 December 2004 18:58 > > > To: Struts Users Mailing List > > > Subject: Re: Checking radio button based on object value > > > > > > I'll describe the scenario where you are using a database. > > > > > > In the action that is displaying "existing values" (ones in > > > the database) > > > 1. Retrieve record from database > > > 2. Populate form bean with values from database > > > 3. Forward to the jsp > > > > > > If you are not getting your values from the database, but > rather from > > > a session variable -- then replace step 2 with "populate form bean > > > with values from session object" > > > > > > Lee > > > > > > > > > On Wed, 1 Dec 2004 18:50:20 -0000, Ciaran Hanley > > > <[EMAIL PROTECTED]> wrote: > > > > optionOne, optionTwo are two groups consisting of two > buttons each. > > > > Basically each is an on and off switch, "true" or "false". > > > > > > > > I can set the default values in my form bean ok, I set them > > > all to false > > > > initially. > > > > > > > > The problem is once updated options have been submitted and > > > saved in the > > > > session I need to reproduce the users choices the next time > > > they visit the > > > > same JSP. > > > > > > > > So the next time into the JSP "true" and "false" values > > > should be checked > > > to > > > > reflect the users options. I am trying to figure out > how to do this > > > > > > > > CH > > > > > > > > -----Original Message----- > > > > From: t t [mailto:[EMAIL PROTECTED] > > > > Sent: 01 December 2004 18:39 > > > > To: Struts Users Mailing List > > > > Subject: Re: Checking radio button based on object value > > > > > > > > Not sure if your optionOne and optionTwo is two groups of > > > radio button or > > > > two radio button in one group. I give you an example to > > > illustrate how to > > > > set default values: > > > > > > > > Suppose I have a group (group1) of radio buttons, say > 3. I want to > > > preselect > > > > the first one. > > > > In my JSP file. I do this: > > > > > > > > <html:radio property="group1" value="rb1" /> > > > > <html:radio property="group1" value="rb2" /> > > > > <html:radio property="group1" value="rb3" /> > > > > > > > > In the form bean file, I will have a property called > > > "group1", and default > > > > value is "rb1" > > > > private String group1="rb1"; > > > > > > > > Hope this helps. > > > > > > > > Tong > > > > > > > > > > > > Ciaran Hanley <[EMAIL PROTECTED]> wrote: > > > > Hi, > > > > > > > > I have a form consisting of several radio buttons. Upon > > > form generation I > > > > need radio buttons in the form to be checked based on the > > > attribute of a > > > > bean stored in the session. If the beans property is true then a > > > particular > > > > radio button value of "true" should be checked. > > > > > > > > Option One > > > > > > > > > > > > Option Two > > > > > > > > > > > > I want these preselected based on a bean which has > > > variables corresponding > > > > to each radio button > > > > > > > > boolean optionOne = false; > > > > > > > > boolean optionTwo = true; > > > > > > > > How can I achieve this? > > > > > > > > Thanks, > > > > > > > > CH > > > > > > > > > > > > --------------------------------- > > > > Do you Yahoo!? > > > > Meet the all-new My Yahoo! - Try it today! > > > > > > > > > > > > --------------------------------------------------------------------- > > > > 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] > > > > > --------------------------------------------------------------------- > > 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]