dynamically change struts' form's action

Discussion in 'Java' started by ctyberg, Dec 13, 2004.

  1. ctyberg

    ctyberg Guest

    I'd like to dynamically change the form's action based on a request
    parameter.

    For ex.
    <c:if test="${param.isNew == 'true'}>
    <html:form action="/saveNew.do" >
    </c:if>
    <c:if test="${param.isNew == 'false'}>
    <html:form action="/saveExisting.do" >
    </c:if>

    However, the above would generate a nesting error since the form's end
    tag is not within the c:if tag.
    How else can I achieve the same idea? Any ideas?
    ctyberg, Dec 13, 2004
    #1
    1. Advertising

  2. ctyberg wrote:

    > I'd like to dynamically change the form's action based on a request
    > parameter.
    >
    > For ex.
    > <c:if test="${param.isNew == 'true'}>
    > <html:form action="/saveNew.do" >
    > </c:if>
    > <c:if test="${param.isNew == 'false'}>
    > <html:form action="/saveExisting.do" >
    > </c:if>
    >
    > However, the above would generate a nesting error since the form's end
    > tag is not within the c:if tag.
    > How else can I achieve the same idea? Any ideas?


    You might want to look at letting you Action classes
    extend DispatchAction instead of Action. Then you can
    get away with using one action and letting the parameter
    decide which method to use in the action class. Take a
    look at the struts documentation for DispatchAction class.


    Best regards,
    Tom Arne Orthe
    Tom Arne Orthe, Dec 14, 2004
    #2
    1. Advertising

  3. ctyberg

    ctyberg Guest

    I want to have two separate actions because the validtions are
    different.

    I ended up setting a variable using c:set and then using
    html-el:form.

    <c:if test="${param.isNew=='true'}"><c:set var="formAction"
    value="/saveNew.do"/></c:if>
    <c:if test="${param.isNew=='false'}"><c:set var="formAction"
    value="/saveExisting.do"/></c:if>
    <html-el:form action="${formAction}" >
    ctyberg, Dec 14, 2004
    #3
  4. ctyberg

    ctyberg Guest

    Thanks for replying. Originally it was a dispatchAction, but then I
    split it out because each action had different validations.
    ctyberg, Dec 14, 2004
    #4
  5. ctyberg

    ctyberg Guest

    I want to have two separate actions because the validtions are
    different.

    I ended up setting a variable using c:set and then using html-el:form.


    <c:if test="${param.isNew=='true'}"><c:set var="formAction"
    value="/saveNew.do"/></c:if>
    <c:if test="${param.isNew=='false'}"><c:set var="formAction"
    value="/saveExisting.do"/></c:if>
    <html-el:form action="${formAction}" >
    ctyberg, Dec 15, 2004
    #5
  6. ctyberg

    ctyberg Guest

    I need to have two actions because the validations are different for
    each one.

    Here's what I did -

    <c:if test="${param.isNew == 'true'}">
    <c:set var="formAction" value="/saveNew.do"/>
    </c:if>
    <c:if test="${param.isNew == 'false'}">
    <c:set var="formAction" value="/saveExisting.do"/>
    </c:if>

    <html-el:form action="${formAction}" >
    ctyberg, Dec 15, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Bloggs
    Replies:
    1
    Views:
    719
    Sudsy
    Aug 3, 2003
  2. rjweytens
    Replies:
    6
    Views:
    16,047
    rjweytens
    Jun 25, 2004
  3. runescience

    Struts mapping action to action???

    runescience, Feb 6, 2006, in forum: Java
    Replies:
    3
    Views:
    1,806
    runescience
    Feb 7, 2006
  4. vyshu
    Replies:
    1
    Views:
    2,523
    Richard Senior
    Apr 27, 2007
  5. John
    Replies:
    0
    Views:
    844
Loading...

Share This Page