You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Narasimhan, Shyamala" <Sh...@Agilquest.com> on 2001/07/04 15:21:16 UTC
specifying multiple forms in an action mapping
hi
i would like to use two different forms in an action class... kindly advise
as to how to specify the action mapping
thanks
shyamala.
Re: specifying multiple forms in an action mapping
Posted by Martin Cooper <ma...@tumbleweed.com>.
If what you want is to have one Action class that can handle input from
multiple forms, then you just need to add a different action mapping in
struts-config.xml for each input form, giving each a distinct path. In the
Action itself, you would need to check to see which kind of form (or which
path) you were being invoked with.
For example:
<action path="/path1" name="form1" type="com.mycompany.MyAction"/>
<action path="/path2" name="form2" type="com.mycompany.MyAction"/>
would allow you to process requests for '/path1' or '/path2' with the same
Action class.
Hope this helps.
--
Martin Cooper
----- Original Message -----
From: "Narasimhan, Shyamala" <Sh...@Agilquest.com>
To: <st...@jakarta.apache.org>
Sent: Wednesday, July 04, 2001 6:21 AM
Subject: specifying multiple forms in an action mapping
> hi
>
> i would like to use two different forms in an action class... kindly
advise
> as to how to specify the action mapping
>
> thanks
>
> shyamala.
>
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
Radio Button Example using boolean?
Posted by Tim Colson <tc...@cisco.com>.
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: specifying multiple forms in an action mapping
Posted by Ted Husted <hu...@apache.org>.
The short answer is you can't.
Though, you could create a single ActionForm as a wrapper around other
forms and then access them through the infamous "dotted" syntax.
If that doesn't work for you, if you talked a bit more about why you
want multiple forms, someone may have a better answer ;-)
-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 737-3463.
-- http://www.husted.com/about/struts/
"Grassotti, Michael" wrote:
>
> Has anyone gotten back to you on this? I'm having the same problem...
>
> > -----Original Message-----
> > From: Narasimhan, Shyamala [mailto:Shyamala.Narasimhan@Agilquest.com]
> > Sent: Wednesday, July 04, 2001 9:21 AM
> > To: struts-user@jakarta.apache.org
> > Subject: specifying multiple forms in an action mapping
> >
> >
> > hi
> >
> > i would like to use two different forms in an action class...
> > kindly advise
> > as to how to specify the action mapping
> >
> > thanks
> >
> > shyamala.
RE: specifying multiple forms in an action mapping
Posted by "Grassotti, Michael" <mi...@tallan.com>.
Has anyone gotten back to you on this? I'm having the same problem...
> -----Original Message-----
> From: Narasimhan, Shyamala [mailto:Shyamala.Narasimhan@Agilquest.com]
> Sent: Wednesday, July 04, 2001 9:21 AM
> To: struts-user@jakarta.apache.org
> Subject: specifying multiple forms in an action mapping
>
>
> hi
>
> i would like to use two different forms in an action class...
> kindly advise
> as to how to specify the action mapping
>
> thanks
>
> shyamala.
Re: specifying multiple forms in an action mapping
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Wed, 4 Jul 2001, Narasimhan, Shyamala wrote:
> hi
>
> i would like to use two different forms in an action class... kindly advise
> as to how to specify the action mapping
>
Although it is not possible to have >1 form beans per action *mapping*, it
is definitely possible to have >1 form beans per action *class*. You
simply have to have more than one mapping that resolves to the same Action
class name.
Note that, in this scenario, Struts will still create a separate instance
of the Action class per mapping. Therefore, if you want to share data
between them, you'll need to use static variables, or some other
equivalent technique.
> thanks
>
> shyamala.
>
Craig McClanahan