You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Larson, Kirk" <Ki...@pearson.com> on 2003/07/09 20:04:20 UTC

Accessing the ActionForm object from within JSP

I want to access a form within my JSP page using JSTL.  I have it working by
simply specifying the name of the form (cycleDateForm) in the JSTL EL.
However, this does not seem like the correct method of solving this problem.
The form name is derived from the Struts configuration file using the
appropriate action mapping.  Since the JSP page only specifies the action
name and does not directly specify the form name, it does not seem that it
should reference the form directly. However, I am not sure how to determine
the name of the form object?  Any suggestions?

Sample JSP page :
==============
<html:form action="/cycledates/edit" >
	<c:forEach items="${cycleDateForm.cycleDates}" var="cycleDate">
		<c:out value="${cycleDate.key}"/><br>
	</c:forEach>
</html:form>

Relevant portion of struts-config.xml :
==========================
<form-beans>
	<form-bean name="cycleDateForm"
type="com.pearson.tools.setup.CycleDatesForm" />
</form-beans>
<action-mappings>
	<action 
		path="/cycledates/edit" 
		parameter="" 
		type="com.pearson.tools.setup.CycleDatesDispatchAction" 
		name="cycleDateForm" 
		scope="request">
			<forward name="success" path="cycledates.edit.frame"
redirect="false" />
	</action>
</action-mappings>


**************************************************************************** 
This email may contain confidential material. 
If you were not an intended recipient, 
Please notify the sender and delete all copies. 
We may monitor email to and from our network. 
****************************************************************************

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Accessing the ActionForm object from within JSP

Posted by Yann C�bron <ya...@yahoo.de>.
> I want to access a form within my JSP page using JSTL.  I have it working
by
> simply specifying the name of the form (cycleDateForm) in the JSTL EL.
> However, this does not seem like the correct method of solving this
problem.
> The form name is derived from the Struts configuration file using the
> appropriate action mapping.  Since the JSP page only specifies the action
> name and does not directly specify the form name, it does not seem that it
> should reference the form directly. However, I am not sure how to
determine
> the name of the form object?  Any suggestions?
>
> Sample JSP page :
> ==============
> <html:form action="/cycledates/edit" >
> <c:forEach items="${cycleDateForm.cycleDates}" var="cycleDate">
                      ^^^^^^^^^^^^^
The name does not correspond to the ActionForm-<class>name, that's why it
doesn't work.

It should work using <c:forEach items="${CycleDatesForm.cycleDate}"
var="cycleDate">

An alternative is to use the <bean:struts>-tag to expose config-data, see
http://jakarta.apache.org/struts/userGuide/struts-bean.html#struts

HTH,
    Yann


> <c:out value="${cycleDate.key}"/><br>
> </c:forEach>
> </html:form>
>
> Relevant portion of struts-config.xml :
> ==========================
> <form-beans>
> <form-bean name="cycleDateForm"
> type="com.pearson.tools.setup.CycleDatesForm" />
> </form-beans>
> <action-mappings>
> <action
> path="/cycledates/edit"
> parameter=""
> type="com.pearson.tools.setup.CycleDatesDispatchAction"
> name="cycleDateForm"
> scope="request">
> <forward name="success" path="cycledates.edit.frame"
> redirect="false" />
> </action>
> </action-mappings>
>
>
>
****************************************************************************
> This email may contain confidential material.
> If you were not an intended recipient,
> Please notify the sender and delete all copies.
> We may monitor email to and from our network.
>
****************************************************************************




---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org