• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Struts - tiles

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to use tiles in my jsp's , but I am getting the following error when I try to access the jsp.
javax.servlet.jsp.JspException: Error - tag.getAsString : component context is not defined. Check tag syntax
at org.apache.struts.taglib.tiles.GetAttributeTag.doEndTag(GetAttributeTag.java:198)
at jsp_servlet._jsp.__cpitemplate._jspService(__cpitemplate.java:158)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:446)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
Does anybody know what this error means?? Any help will be really appreciated.
Thanks.
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sanny
It would be easier to determine the problem area if you can post the code.
Thanks
Ravi
 
Sany Bel
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Here is my struts-config file
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<!--
This is the Struts configuration file for the example application,
using the proposed new syntax.
NOTE: You would only flesh out the details in the "form-bean"
declarations if you had a generator tool that used them to create
the corresponding Java classes for you. Otherwise, you would
need only the "form-bean" element itself, with the corresponding
"name" and "type" attributes.
-->

<struts-config>

<!-- ========== Action Mapping Definitions ============================== -->
<action-mappings>
<action path="/viewInstruments"
type="xxx.ViewInstrumentsAction">
<forward name="viewInstruments" path="cpi.template"/>
</action>
</action-mappings>
<!-- ========== Message Resources Definitions =========================== -->
<message-resources parameter="ApplicationResources" null="false"/>
<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config"
value="/WEB-INF/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />
</plug-in>
</struts-config>
The following is my
 
Sany Bel
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry I had hit enter by mistake in my previous mail.
Here is my struts-defs.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd">
<!-- Tiles definitions -->
<tiles-definitions>
<!-- ======================================================= -->
<!-- Master layout -->
<!-- ======================================================= -->
<!-- Master layout and default tiles used by all pages -->
<definition name="cpi.template" path="/jsp/CPITemplate.jsp">
<put name="title" value="CPI Pricing" />
<put name="header" value="/jsp/Header.jsp" />
<put name="navigation" value="/jsp/Navigation.jsp" />
<put name="footer" value="/jsp/Footer.jsp" />
<put name="body" value="/jsp/DefaultBody.jsp" />
</definition>

</tiles-definitions>
Here is my jsp that uses tiles
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%-- Layout Tiles
This layout create a html page with <header> and <body> tags. It render
a header, left menu, body and footer tile.
@param title String use in page title
@param header Header tile (jsp url or definition name)
@param menu Menu
@param body Body
@param footer Footer
--%>
<HTML>
<HEAD>
<link rel=stylesheet href="<%=request.getContextPath()%>/css/stylesheet.css" type="text/css">
<title><tiles:getAsString name="title"/></title>

</HEAD>
<%--
<body bgcolor="#ffffff" text="#000000" link="#023264" alink="#023264" vlink="#023264">
<table border="0" width="100%" cellspacing="5">
<tr>
<td colspan="2"><tiles:insert attribute="header" /></td>
</tr>
<tr>
<td width="140" valign="top">
<tiles:insert attribute="navigation"/>
</td>
<td valign="top" align="left">
<tiles:insert attribute="body" />
</td>
</tr>
<tr>
<td colspan="2">
<tiles:insert attribute="footer" />
</td>
</tr>
</table>
</body>
--%>
</html>
It's failing right at title. I've commented out all the other stuff. I am not sure what is wrong. Can you tell me if I am missing anything.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the tile name should START with a '.'

<!-- Master layout and default tiles used by all pages -->
<definition name=".cpitemplate" path="/jsp/CPITemplate.jsp">
<put name="title" value="${title}" />
<put name="header" value="/jsp/Header.jsp" />
<put name="navigation" value="/jsp/Navigation.jsp" />
<put name="footer" value="/jsp/Footer.jsp" />
<put name="body" value="${content}" />
</definition>
<!-- CPI Pricing page -->
<definition name=".cpiPricing" extends=".cpitemplate">
<put name="title" value="CPI Pricing"/>
<put name="body" value="jsp/cpiPricing.jsp"/>
</definition>
Have Struts forward to the path .cpiPricing
 
Sany Bel
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I remember reading that. But I have an example application that runs fine without the ".". It's one of the example application that you get when you download struts 1.1. Also, when I try to restart the server (weblogic 8.1) I am ocassionally getting the following error:
java.lang.NoClassDefFoundError: org/apache/commons/collections/FastHashMap$KeySe
t
at org.apache.commons.collections.FastHashMap.keySet(Unknown Source)
at org.apache.struts.action.ActionServlet.destroyDataSources(ActionServl
et.java:769)
at org.apache.struts.action.ActionServlet.destroy(ActionServlet.java:431
)
at weblogic.servlet.internal.ServletStubImpl$ServletDestroyAction.run(Se
rvletStubImpl.java:1029)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
dSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
118)
at weblogic.servlet.internal.ServletStubImpl.destroyServlet(ServletStubI
mpl.java:583)
at weblogic.servlet.internal.ServletStubImpl.destroyServlet(ServletStubI
mpl.java:610)
at weblogic.servlet.internal.ServletStubImpl.destroyServlet(ServletStubI
mpl.java:595)
at weblogic.servlet.internal.WebAppServletContext.destroyServlets(WebApp
ServletContext.java:5803)
at weblogic.servlet.internal.WebAppServletContext.destroy(WebAppServletC
ontext.java:5683)
at weblogic.servlet.internal.ServletContextManager.removeContext(Servlet
ContextManager.java:188)
at weblogic.servlet.internal.HttpServer.unloadWebApp(HttpServer.java:740
)
at weblogic.servlet.internal.WebAppModule.destroyContexts(WebAppModule.j
ava:767)
at weblogic.servlet.internal.WebAppModule.rollback(WebAppModule.java:745
)
at weblogic.j2ee.J2EEApplicationContainer.rollbackModule(J2EEApplication
Container.java:3057)
at weblogic.j2ee.J2EEApplicationContainer.rectifyClassLoaders(J2EEApplic
Looks like tiles is not gonna work for me
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To quote the Struts site:

lib/commons-*.jar - These JAR files contain packages from the Jakarta Commons project that are utilized within Struts itself. When you assemble a Struts-based application, you will need to copy these files to the WEB-INF/lib directory.
lib/struts.jar - This JAR file contains all of the Java classes included in Struts. It should be copied into the WEB-INF/lib directory of your web application. WARNING - If you are going to be hosting multiple Struts based applications on the same servlet container, you will be tempted to place the struts.jar file into the shared repository supported by your container. Be advised that this will like cause you to encounter ClassNotFoundException problems unless all of your application classes are stored in the shared repository.

 
Sany Bel
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had two war files in the applications directory. I deleted one of them and tried to restart the server a couple of times. Looks like the ClassNotFound error is gone. But, I am still getting the tag error.
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is your tiles-defs.xml named struts-defs.xml???
 
Sany Bel
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry but it is named tiles-defs.xml
 
Sany Bel
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmm!!, I finally got this to work. But, I had to go through the action to view thw jsp. Can't we directly go to the jsp? like can't we use jsp name in the url rather than using action name? I had to do the following in my action class:
ComponentContext context = ComponentContext.getContext( request );
if( context == null )
{ // Not found, create a context
ComponentContext tileContext = new ComponentContext( );
ComponentContext.setContext( tileContext, request);
}
return (mapping.findForward("viewInstruments"));
}
Is this how it should work?
Also, I am stillg getting the ClassNotFound error. Can't we use war files to deploy the application?
Please help
 
Joel Salatin has signs on his property that say "Trespassers will be Impressed!" Impressive tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic