<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest topics for the forum "Sticky Actions"]]></title>
		<link>http://book.mentaframework.org/forums/show/21.page</link>
		<description><![CDATA[The newest discussed topics in the forum "Sticky Actions"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>Issues with using Sticky Actions and Action Chaining? </title>
				<description><![CDATA[ I hope this is the right place to ask a question. When chaining actions together, it seems the sticky-ness of the chained action is lost. Please see the example below:<br /> <br /> [b]loadActions in ApplicationManager:[/b]<br /> [code]<br />         ActionConfig ac1 = new ActionConfig("/FirstAction", FirstAction.class);<br />         ActionConfig ac2 = new ActionConfig("/SecondAction", SecondAction.class);<br /> <br />         ac1.addConsequence(FirstAction.CHOICE_1, new Chain(ac2));<br />         ac1.addConsequence(FirstAction.CHOICE_2, new Forward("/SecondAction.mtw"));<br />         ac1.addConsequence(ERROR, new Forward("/pages/select.jsp"));<br /> <br />         ac2.addConsequence(SUCCESS, new Forward("/pages/display.jsp"));<br /> <br />         addActionConfig(ac1);<br />         addActionConfig(ac2);<br /> [/code]<br /> [b]select.jsp[/b]<br /> [code]<br /> &lt;%@ taglib uri="/WEB-INF/lib/mentawai.jar" prefix="mtw" %&gt;<br /> &lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;<br />     Select: <br/><br />     &lt;form action="/FirstAction.mtw"&gt;<br />         &lt;input type="radio" name="choice" value="1"&gt;CHOICE_1<br/><br />         &lt;input type="radio" name="choice" value="2"&gt;CHOICE_2<br/><br />         &lt;input type="submit" value="Go"&gt;<br />     &lt;/form&gt;<br /> &lt;/body&gt;&lt;/html&gt;<br /> [/code]<br /> [b]FirstAction:[/b]<br /> [code]<br /> package com.sandbox;<br /> <br /> import org.mentawai.core.BaseAction;<br /> <br /> public class FirstAction extends BaseAction {<br /> <br />     public static final String CHOICE_1 = "CHOICE_1";<br />     public static final String CHOICE_2 = "CHOICE_2";<br /> <br />     public String execute() throws Exception {<br /> <br />         String choice = (String) input.getValue("choice");<br />         if (choice == null) {<br />             return ERROR;<br />         }<br />         output.setValue("result", "OK");<br />         input.setValue("result", "OK");<br /> <br />         switch (Integer.parseInt(choice)){<br />             case 1:<br />                 return CHOICE_1;<br />             case 2:<br />                 return CHOICE_2;<br />             default:<br />                 return ERROR;<br />         }<br />     }<br /> }<br /> [/code]<br /> [b]SecondAction:[/b]<br /> [code]<br /> package com.sandbox;<br /> <br /> import org.mentawai.core.BaseAction;<br /> <br /> public class SecondAction extends BaseAction {<br /> <br />     private int counter = 0;<br />     public String execute() throws Exception {<br /> <br />         if (counter == 0){<br />             adhere();<br />         }<br />         counter++;<br />         output.setValue("counter", counter);<br />         String resultFromOutput = (String) output.getValue("result");<br />         String resultFromInput = (String) input.getValue("result");<br /> <br />         if (resultFromInput == null) {<br />             output.setValue("inputMessage", "Result from input not set!");<br />         } else {<br />             output.setValue("inputMessage", resultFromInput);<br />         }<br /> <br />         if (resultFromOutput == null) {<br />             output.setValue("outputMessage", "Result from output not set!");<br />         } else {<br />             output.setValue("outputMessage", resultFromOutput);<br />         }<br /> <br />         return SUCCESS;<br />     }<br /> }<br /> [/code]<br /> [b]display.jsp[/b]<br /> [code]<br /> &lt;%@ taglib uri="/WEB-INF/lib/mentawai.jar" prefix="mtw" %&gt;<br /> &lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;<br /> <br /> Counter: &lt;mtw:out value="counter"/&gt;<br/><br /> Input Message: &lt;mtw:out value="inputMessage"/&gt;<br/><br /> Output Message: &lt;mtw:out value="outputMessage"/&gt;<br/><br /> <br /> <br/><a >Back to choice selection</a><br /> &lt;/body&gt;&lt;/html&gt;<br /> [/code]<br /> Depending on the selected choice in the form, action chaining does not seem to work as expected:<br /> <br /> With Choice 1: the consequence in the action configuration for the FirstAction is configured to chain to the SecondAction. However, in this case, even though the SecondAction is sticky since adhere is called when the counter is zero, the action state is not preserved across subsequent invocations. (The input and output filters work as expected).<br /> <br /> With Choice 2: the consequence in the action configuration for the FirstAction is configured to forward the request instead of chaining which would preserve the state of the SecondAction across subsequent invocations, but unfortunately, does not preserve the input/output filters.<br /> <br /> The expected result I’m looking for is for the counter to be incremented properly across multiple invocations and both Input Message and Output Message to be set as well.<br /> <br /> I’ve looked into the implementation of the getAction() method in ActionConfig which states:<br /> [code]<br />    /**<br />      * Returns an action instance to be used with this request.<br />      * Mentawai creates a new action instance for each request.<br />      * You can extend ActionConfig and override this class to integrate Mentawai <br />      * with other IoC containers, that may want to create the action themselves.<br />      * <br />      * @return The action instance to use for the request.<br />      */<br /> [/code]<br /> I see, as an example, the SingleInstanceActionConfig, but there doesn’t seem to be another subclass of ActionConfig that would work. Please let me know if there’s a workaround. Thanks for reading this far  :) <br /> <br /> Thanks for your time,<br /> Siraj Berhan]]></description>
				<guid isPermaLink="true">http://book.mentaframework.org/posts/preList/29/30.page</guid>
				<link>http://book.mentaframework.org/posts/preList/29/30.page</link>
				<pubDate><![CDATA[Tue, 18 Nov 2008 13:03:56]]> GMT</pubDate>
				<author><![CDATA[ sberhan]]></author>
			</item>
	</channel>
</rss>