You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Jennings, Christofer J." <CJ...@Semprautilities.com> on 2002/05/10 18:18:59 UTC

Form action based on bean presence

I'd like to set a form's action based on the presence of an bean. The code
below fails during compile at the first </logic:present> tag, saying that it
is a mismatch.

---- start snip -----------------------------------
<logic:present name="abcForm">
    <html:form method="post" action="/saveABC">
</logic:present>
<logic:present name="xyzForm">
    <html:form method="post" action="/saveXYZ">
</logic:present>

...

</html:form>
---- stop snip ------------------------------------

My gut feeling is that I would have to nest the whole form block in each
logic block to make this work. ... Right or wrong?

I really don't want to nest the form like that because it would make too
much code duplication. For the time being I've set the form to default to
one option then switch it if needed in a JavaScript function. That works but
seems ugly. Is there a better option?

Thanks,
boz

Re: Form action based on bean presence

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Fri, 10 May 2002, Jennings, Christofer J. wrote:

> Date: Fri, 10 May 2002 09:18:59 -0700
> From: "Jennings, Christofer J." <CJ...@Semprautilities.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: 'Struts Users Mailing List' <st...@jakarta.apache.org>
> Subject: Form action based on bean presence
>
> I'd like to set a form's action based on the presence of an bean. The code
> below fails during compile at the first </logic:present> tag, saying that it
> is a mismatch.
>
> ---- start snip -----------------------------------
> <logic:present name="abcForm">
>     <html:form method="post" action="/saveABC">
> </logic:present>
> <logic:present name="xyzForm">
>     <html:form method="post" action="/saveXYZ">
> </logic:present>
>
> ...
>
> </html:form>
> ---- stop snip ------------------------------------
>
> My gut feeling is that I would have to nest the whole form block in each
> logic block to make this work. ... Right or wrong?
>

Yep ... your approach above violates the tag nesting constraints of markup
language like HTML and XML.

> I really don't want to nest the form like that because it would make too
> much code duplication. For the time being I've set the form to default to
> one option then switch it if needed in a JavaScript function. That works but
> seems ugly. Is there a better option?
>

Two other approaches:

* Use JavaScript to change the destination on the client side

* Submit the form to a common Action and let *it* decide what to do.

> Thanks,
> boz
>

Craig



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>