You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tim Colson <tc...@cisco.com> on 2001/07/11 06:54:30 UTC

Radio Button Example using boolean?

Does someone have a simple example of using two radio buttons (YES / NO)?

Can they be populated from a boolean in the form?

 <input type="radio" name="LIKES_DONUTS" value="YES" checked> Yes
 <input type="radio" name="LIKES_DONUTS" value="NO">No

Side Question: What's the pro/con of simply using the standard HTML elements
with some <logic:> tags to do this?

Thanks,
Tim


Re: Radio Button Example using boolean?

Posted by suhas <su...@techmas.hcltech.com>.
Do something like this
in strtus-config.xml file -

  <!-- Do nut -->
  <action path="/donut"
     type="example.DoNutAction"
     name="doNutForm">
   <forward name="success"  path="/donut.jsp"/>
  </action>

In the donut.jsp -
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html:html>
<html:form action="/donut.do">
<html:radio property="donut" value="true" >
 <bean:message key="yes" />
</html:radio>
<html:radio property="donut" value="false" />
 <bean:message key="no" />
</html:radio>
<html:submit>
<bean:message key="button.submit" />
</html:submit>
</html:form>
</html:html>

In the DoNutForm.java

package example;
import org.apache.struts.action.*;
import javax.servlet.http.*;
public class DoNutForm extends ActionForm {
 private boolean donut;
 public DoNutForm() {
 }
 public void reset(ActionMapping mapping , HttpServletRequest req) {
  donut = true;
 }
 public void setDonut(boolean  donut) {
  System.out.println(" **in the setter donut** "+ donut);
  this.donut  = donut ;
 }
 public boolean getDonut() {
  System.out.println(" in the getter" + donut);
  return donut;
 }
}

In the DoNutAction.java
public final class DoNutAction extends Action {
   public ActionForward perform(ActionMapping mapping,
                               ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response)
   throws IOException, ServletException {
  return mapping.findForward("success");

 }
}


****************************************************************

----- Original Message -----
From: Tim Colson <tc...@cisco.com>
To: <st...@jakarta.apache.org>
Sent: Wednesday, July 11, 2001 5:54 AM
Subject: Radio Button Example using boolean?


> Does someone have a simple example of using two radio buttons (YES / NO)?
>
> Can they be populated from a boolean in the form?
>
>  <input type="radio" name="LIKES_DONUTS" value="YES" checked> Yes
>  <input type="radio" name="LIKES_DONUTS" value="NO">No
>
> Side Question: What's the pro/con of simply using the standard HTML
elements
> with some <logic:> tags to do this?
>
> Thanks,
> Tim