Sorry, no red code for me.  ;-)

If the action= is the only change between your forms, you could just define
a bean with the action name and then use it in the form tag, e.g.:

 <logic:notPresent name="user" >
    <bean:define id="formAction" value="/eFilerAddNoUser" />
 </logic:notPresent>
 <logic:present name="user" >
    <bean:define id="formAction" value="/eFilerAdd" />
 </logic:present>

<html:form action="<bean:write name='formAction'/>" >
...

I think that will work.  Then, of course, if other things in your form need
to be different, you'll have other logic tags to control that.

Another strategy might be to set a bean (or attribute on your form bean) in
the Action class called before this page that contains the name of the
action to post to.  You could then access it here in a similar manner,
rather than having the logic code here.

BTW, I'm not clear on some of your logic below.  You have several places
where, in pseudo-code, you do something like:

if (user) then
   do something
   if (user) then
      do something else
   end if
end if

Why are you checking again when you're in code that will only be reached if
the user is present?  ;-)

Scott

> -----Original Message-----
> From: Dudley Butt@i-Commerce [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, April 25, 2001 3:18 AM
> To: '[EMAIL PROTECTED]'
> Subject: please help...is it possible to dynamically set the 
> form action
> a ttribute dynamically eg <html:form action="something that 
> can be built
> up dynamically">
> 
> 
> currently i'm doing the following:
> 
> I'm using the logic tag to display one of two forms with the 
> action of each
> for set differently, based on whether the user bean object is in the
> session. 
> Is this ok, or is there a better way? Look at the red code....
> 
> 
> <%@ page language="java" %>
> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
> 
> <html:html>
> <html:errors/>
> <head><html:base/>
> <logic:present name="eFilerForm" >
> <logic:equal name="eFilerForm" property="action" scope="request"
> value="Edit">
>               <title><bean:message key="eFilerEdit.title"/></title>
> </logic:equal>
> 
> <logic:equal name="eFilerForm" property="action" scope="request"
> value="Add">
>         <title><bean:message key="eFilerAdd.title"/></title>
> </logic:equal>
> </head>
> 
> <logic:equal name="eFilerForm" property="action" scope="request"
> value="Add">
>        <h3><bean:message key="eFilerAdd.heading"/></h3>
> </logic:equal>
> 
> <logic:equal name="eFilerForm" property="action" scope="request"
> value="Edit">
>        <h3><bean:message key="eFilerEdit.heading"/></h3>
> </logic:equal>
> </logic:present>
> 
> <body bgcolor="white">
> 
> <logic:notPresent name="user" >
>       <html:form action="/eFilerAddNoUser" >
> 
> <logic:notPresent name="user" >
>       <html:link page="/index.jsp"><bean:message
> key="eFilerMenu.menu"/></html:link>
> </logic:notPresent>   
> </br></br>
> 
> <table border="0" width="70%" cols="4">
>   <tr>
>     <th align="right">
>             <bean:message key="eFiler.firstName"/>
>     </th>
>     <td align="left">
>             <html:text property="firstName" size="16" maxlength="16"/>
>     </td>
>     <th align="right">
>             <bean:message key="eFiler.initials"/>
>     </th>
>     <td align="left">
>             <html:text property="initials" size="16" maxlength="16"/>
>     </td>
> 
>   </tr>
> </table>
>   
>       </html:form>
> </logic:notPresent>
> 
> 
> <logic:present name="user" >
>       <html:form action="/eFilerAdd" >
> 
> <logic:present name="user" >
>       <html:link page="/eFilerCancel.do?action=Cancel"><bean:message
> key="eFilerMenu.menu"/></html:link>
> </logic:present>      
> </br></br>
> 
> <table border="0" width="70%" cols="4">
>   <tr>
>     <th align="right">
>             <bean:message key="eFiler.firstName"/>
>     </th>
>     <td align="left">
>             <html:text property="firstName" size="16" maxlength="16"/>
>     </td>
>     <th align="right">
>             <bean:message key="eFiler.initials"/>
>     </th>
>     <td align="left">
>             <html:text property="initials" size="16" maxlength="16"/>
>     </td>
> 
>   </tr>
>  
> </table>
> </br>
> 
>       </html:form>
> </logic:present>
> 
> 
> </body>
> </html:html>
> 
> 
> 

Reply via email to