You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Kevin Cramer <kc...@siscom.net> on 2003/03/26 03:50:19 UTC
Tiles Controller in definitions
I'm trying to setup a controller for a Tiles definition. I follow the
examples I've seen but it appears that the controller class is not
called. I've seen posts here that indicate that you need to use
tiles:insert to enable the controller but I'm always using that
whenever I include the JSP. Perhaps my use of tile definitions is
causing problems? I'm also unsure whether I'm supposed to use the
perform() or execute() on the Controller interface. The error I get
is that the JSP of the tile with the controller complains that it
cannot find the object that I am doing the putAttribute with. The
error is on the tiles:importAttribute.
I have the following in my tiles-defs.xml:
<definition name="standardPage"
path="/WEB-INF/common/layouts/standardLayout.jsp">
<put name="title.key" value="title.notDefined" />
<put name="header" value=".standardPage.header" />
<put name="content" value="NO CONTENT DEFINED" />
<put name="left" value="/WEB-INF/common/other1.jsp" />
<put name="right" value="standardPage.testcontroller" />
</definition>
<definition name=".standardPage.header"
path="/WEB-INF/common/header.jsp">
<put name="headerbar" value="standardPage.header.bar"/>
</definition>
<definition name="standardPage.header.bar"
path="/WEB-INF/common/bar.jsp">
<put name="left" value="NO LEFT DEFINED" />
<put name="right" value="NO RIGHT DEFINED" />
</definition>
<definition name="standardPage.testcontroller"
path="/WEB-INF/common/testcontroller.jsp"
controllerClass="mytest.TestAction">
</definition>
Here is the testcontroller.jsp:
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-tiles" prefix="tiles" %>
<tiles:importAttribute name="TEST"/>
<bean:write name="TEST" property="value"/>
Here is the controller class:
public final class TestAction extends TilesAction implements Controller {
public static final String TEST_KEY = "TEST";
public ActionForward perform(
ComponentContext context,
ActionMapping arg1,
ActionForm arg2,
HttpServletRequest arg3,
HttpServletResponse arg4)
throws IOException, ServletException {
perform(context, arg3, arg4, getServlet().getServletContext());
return null;
}
public void perform(
ComponentContext context,
HttpServletRequest arg1,
HttpServletResponse arg2,
ServletContext arg3)
throws ServletException, IOException {
MyTestObject test = new MyTestObject("Test Value");
context.putAttribute(TEST_KEY, test);
}
public ActionForward execute(
ComponentContext context,
ActionMapping arg1,
ActionForm arg2,
HttpServletRequest arg3,
HttpServletResponse arg4)
throws Exception {
perform(context, arg3, arg4, getServlet().getServletContext());
return null;
}
}
Thanks,
Kevin
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Tiles Controller in definitions
Posted by Cedric Dumoulin <ce...@apache.org>.
Hi,
If you use a class as controller, you need to implement the Controller
interface, which define only one method:
public void perform(ComponentContext tileContext,
HttpServletRequest request, HttpServletResponse
response,
ServletContext servletContext)
throws ServletException, IOException;
So you have to implement this method. Another solution is to extend
the ControllerSupport class, which implement the Controller interface.
The TilesAction class is a convenience class to be used with a
controller URL.
Cedric
Kevin Cramer wrote:
>I'm trying to setup a controller for a Tiles definition. I follow the
>examples I've seen but it appears that the controller class is not
>called. I've seen posts here that indicate that you need to use
>tiles:insert to enable the controller but I'm always using that
>whenever I include the JSP. Perhaps my use of tile definitions is
>causing problems? I'm also unsure whether I'm supposed to use the
>perform() or execute() on the Controller interface. The error I get
>is that the JSP of the tile with the controller complains that it
>cannot find the object that I am doing the putAttribute with. The
>error is on the tiles:importAttribute.
>
>I have the following in my tiles-defs.xml:
>
><definition name="standardPage"
> path="/WEB-INF/common/layouts/standardLayout.jsp">
> <put name="title.key" value="title.notDefined" />
> <put name="header" value=".standardPage.header" />
> <put name="content" value="NO CONTENT DEFINED" />
> <put name="left" value="/WEB-INF/common/other1.jsp" />
> <put name="right" value="standardPage.testcontroller" />
></definition>
>
><definition name=".standardPage.header"
> path="/WEB-INF/common/header.jsp">
> <put name="headerbar" value="standardPage.header.bar"/>
></definition>
>
><definition name="standardPage.header.bar"
> path="/WEB-INF/common/bar.jsp">
> <put name="left" value="NO LEFT DEFINED" />
> <put name="right" value="NO RIGHT DEFINED" />
></definition>
>
>
><definition name="standardPage.testcontroller"
> path="/WEB-INF/common/testcontroller.jsp"
> controllerClass="mytest.TestAction">
></definition>
>
>Here is the testcontroller.jsp:
>
><%@ taglib uri="/tags/struts-html" prefix="html" %>
><%@ taglib uri="/tags/struts-tiles" prefix="tiles" %>
>
><tiles:importAttribute name="TEST"/>
><bean:write name="TEST" property="value"/>
>
>
>Here is the controller class:
>
>public final class TestAction extends TilesAction implements Controller {
> public static final String TEST_KEY = "TEST";
>
> public ActionForward perform(
> ComponentContext context,
> ActionMapping arg1,
> ActionForm arg2,
> HttpServletRequest arg3,
> HttpServletResponse arg4)
> throws IOException, ServletException {
>
> perform(context, arg3, arg4, getServlet().getServletContext());
> return null;
> }
>
> public void perform(
> ComponentContext context,
> HttpServletRequest arg1,
> HttpServletResponse arg2,
> ServletContext arg3)
> throws ServletException, IOException {
>
> MyTestObject test = new MyTestObject("Test Value");
> context.putAttribute(TEST_KEY, test);
> }
>
> public ActionForward execute(
> ComponentContext context,
> ActionMapping arg1,
> ActionForm arg2,
> HttpServletRequest arg3,
> HttpServletResponse arg4)
> throws Exception {
>
> perform(context, arg3, arg4, getServlet().getServletContext());
> return null;
> }
>}
>
>
>Thanks,
>Kevin
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org