You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Laurie Harper <la...@holoweb.net> on 2006/02/24 18:50:43 UTC

Re: checkbox member of form Bean doesn't pass/get value from my DispatchAction.

digant.k.joshi@jpmorgan.com wrote:
> Thanks Niali:
>         Do you have any examples or pointers for writing reset  method of 
> ActionForm ?

Just override ActionForm.reset() in your ActionForm subclass and include 
the code to clear your checkbox property to whatever value corresponds 
to the checkbox not being selected.

>         Should checkbox attribute in question in my ActionForm be Boolean 
> or it can be String type?

Either, so long as you clear it in reset() to false or whatever other 
value you choose to represent false.

>         Right now I have it as String and value coming from DAO are 
> "Y"/"N" which I change it to "yes"/"no" before/after talking to form from 
> Action.

As long as the values in the form and the values in the JSP match up 
that's fine.

L.

>         Thanks.
> Digant
> 
> 
> 
> 
> 
> 
> 
> "Niall Pemberton" <ni...@blueyonder.co.uk>
> 02/23/2006 09:14 PM
> Please respond to "Struts Users Mailing List"
> 
>  
>         To:     "Struts Users Mailing List" <us...@struts.apache.org>
>         cc: 
>         Subject:        Re: checkbox member of form Bean doesn't pass/get value from my 
> DispatchAction.
> 
> 
> Browsers only transmit values when the checkbox is "checked" - in the 
> reset
> method of your ActionForm set the "lockedFlag" to the false value.
> 
> Niall
> 
> ----- Original Message ----- 
> From: <di...@jpmorgan.com>
> Sent: Thursday, February 23, 2006 9:22 PM
> 
> 
>> I have problem with checkbox property not communicating with my Action.
>> I have String property with "Y"/"N" in FormBean populated from DAO , I
>> convert it to "yes"/"no" before sending it to form and I do conversion
>> back from "yes"/"no" to "Y"/"N" after I receive from form and send it to
>> DAO.
>> What is missing here ?
>> Pls. Help  !!
>>
>> In my FormBean it is String element
>> as under
>>
>> public class InstrumentForm extends ActionForm {
>> ....
>> private String lockedFlag;
>> ....
>> }
>>
>>
>>
>> My jsp lines for checkbox is as follows:
>>
>>
>>
>> <td class="tdLabel"><fmt:message key="label.lockedFlag"/>:</td>
>>                 <td><html:checkbox property="lockedFlag"
>> value="${lockedFlag}"/></td>
>>
>>
>>
>>
>>
>> As my dao returns "Y" or "N"
>>
>> I do following conversion when I send data to form.
>>
>>
>>     public ActionForward setUpForInsertOrUpdate(ActionMapping mapping,
>> ActionForm form, HttpServletRequest request, HttpServletResponse 
> response)
>> throws Exception {
>>
>>         InstrumentForm instForm = (InstrumentForm)form;
>>
>>             if (instrument.getLockedFlag().equalsIgnoreCase("Y"))
>>             {
>>                 instrument.setLockedFlag("yes");
>>             }
>>             else
>>             {
>>                 instrument.setLockedFlag("no");
>>             }
>>             BeanUtils.copyProperties(instForm, instrument);
>>         }
>>         prep(request,initMap);
>>         return mapping.findForward(Constants.SUCCESS);
>> }
>>
>>
>> On its way back from form I do following conversion
>>
>>  public ActionForward insertOrUpdate(ActionMapping mapping, ActionForm
>> form, HttpServletRequest request,               HttpServletResponse
>> response) throws Exception
>> {
>>         InstrumentForm instForm = (InstrumentForm)form;
>>         if (instForm.getLockedFlag().equalsIgnoreCase("yes"))
>>         {
>>                 instForm.setLockedFlag("Y");
>>         }
>>         else
>>         {
>>                 instForm.setLockedFlag("N");
>>         }
>>         instService.updateInstrument(instrument);
>> }
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> 
> 
> This communication is for informational purposes only. It is not intended
> as an offer or solicitation for the purchase or sale of any financial
> instrument or as an official confirmation of any transaction. All market prices,
> data and other information are not warranted as to completeness or accuracy and
> are subject to change without notice. Any comments or statements made herein 
> do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries 
> and affiliates.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org