You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by di...@jpmorgan.com on 2006/02/23 22:22:19 UTC

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

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);
}





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


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

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
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