dynamically change struts' form's action

C

ctyberg

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?
 
T

Tom Arne Orthe

ctyberg said:
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
 
C

ctyberg

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}" >
 
C

ctyberg

Thanks for replying. Originally it was a dispatchAction, but then I
split it out because each action had different validations.
 
C

ctyberg

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}" >
 
C

ctyberg

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}" >
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top