You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mufaddal Khumri <mk...@allegrocentral.com> on 2007/09/27 23:22:35 UTC

Validation and freemarker result ....

Hello,

===============
My web.xml:
===============
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web  
Application 2.3//EN"
   "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
   <display-name>Glop</display-name>

   <filter>
     <filter-name>struts2</filter-name>
     <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</ 
filter-class>
   </filter>

   <filter-mapping>
     <filter-name>struts2</filter-name>
     <url-pattern>*.action</url-pattern>
   </filter-mapping>
</web-app>

===============
My struts.xml:
===============
<!DOCTYPE struts PUBLIC
     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
     "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
	<!-- Configuration for the default package. -->
	<package name="default" extends="struts-default">
	  <action name="workOnOrder" class="com.experiment.MyOrderAction">
	    <result name="error" type="freemarker">/support/error.ftl</result>
	  </action>
   </package>
</struts>

===============
My Action class
===============
@Validation
public class MyOrderAction extends ActionSupport
{
	private String orderNumber;

	public String execute()
   	{
		// do some stuff here	
		return NONE;
   	}

	public void setOrderNumber(String orderNumber)
	{
   		this.orderNumber = orderNumber;
	}

	@RequiredStringValidator(message = "Order number is required.")
	public String getOrderNumber()
   	{
   		return this.orderNumber;
   	}
}

===============
Problem:
===============
http://mydomain/glop/workOnOrder.action?orderNumber=123456
Accessing the above url does what is intended.

On the other hand,
http://mydomain/glop/workOnOrder.action
Throws an error, but struts does not take the user to /support/ 
error.ftl page

Basically, I want to render the error.ftl page on validation failure.  
Is this possible?  What am I missing?

Thanks.

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


Re: Validation and freemarker result ....

Posted by Dave Newton <ne...@yahoo.com>.
--- Mufaddal Khumri <mk...@allegrocentral.com>
wrote:
> <action name="workOnOrder"
>         class="com.experiment.MyOrderAction">
>   <result name="error" type="freemarker">
>     /support/error.ftl
>   </result>
> </action>
> On the other hand,
> http://mydomain/glop/workOnOrder.action
> Throws an error, but struts does not take the user
> to /support/error.ftl page
> 
> Basically, I want to render the error.ftl page on
> validation failure. Is this possible?  What am I 
> missing?

Validation normally returns you to the "input" result
(via the default workflow interceptor). Off the top of
my head I don't know of an immediately trivial way to
change that without doing the validation manually;
somebody else probably does though.

d.


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