?
Solved

struts tiles if i use tiles, none of my beans and html tags get rendered

Posted on 2006-05-14
9
Medium Priority
?
464 Views
Last Modified: 2013-11-19
I have a struts application. I recently thought of adding tiles to it since the application is still in the beginning stage. But if I add tiles, the body which contains <bean:message> and <html:text> etc tag does not show up. anything in regular html shows up.

I have added all the <tag uri> bean, html,tiles, login in my layout.jsp. but not in the body. if i add it in the body then the content of the body does not get rendered at all.

PLEASE HELP :-(

Thanks
0
Comment
Question by:muthiahmerchant
  • 5
  • 4
9 Comments
 
LVL 11

Expert Comment

by:fargo
ID: 16680589
u need to add the taglib directives in the tiles template like follows (uri reference may change as per your config.)

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/tiles.tld" prefix="tiles"%>
0
 
LVL 1

Author Comment

by:muthiahmerchant
ID: 16681630
I have added the following. but does the order matter.

Thanks
0
 
LVL 1

Author Comment

by:muthiahmerchant
ID: 16682560
Also tomcat log shows the following error

May 15, 2006 8:21:39 AM org.apache.commons.digester.Digester error
SEVERE: Parse Error at line 7 column 20: Document root element "tiles-definition
s", must match DOCTYPE root "struts-config".
org.xml.sax.SAXParseException: Document root element "tiles-definitions", must m
atch DOCTYPE root "struts-config".
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAX
ParseException(ErrorHandlerWrapper.java:236)
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Err
orHandlerWrapper.java:172)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(
XMLErrorReporter.java:382)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Accepted Solution

by:
fargo earned 1500 total points
ID: 16682610
Order of tag directive does not matter.

Your tiles definitiones config should start with..
<?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>
...
0
 
LVL 1

Author Comment

by:muthiahmerchant
ID: 16682897
I replaced my tiles definition with yours and now I don't see the error in tomcat logs anymore. but I am still unable to render <bean:xxx> and <html:xxx> type messages.

TILES-DEF.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>

  <!-- Main Layout -->
  <definition name="main.layout" path="/mainLayout.jsp">
        <put name="title"  value="Hello world"/>
        <put name="header" value="/header.jsp"/>
        <put name="body"   value="/footer.jsp"/>
        <put name="footer" value="/footer.jsp" />
  </definition>

  <!-- Search Page -->
  <definition name="search.page" extends="main.layout">
        <put name="title"  value="what the hell Page"/>
        <put name="body"   value="/search.jsp"/>
  </definition>

</tiles-definitions>

STRUTS-CONFIG.XML

<?xml version="1.0"?>

<!DOCTYPE struts-config PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
  "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<struts-config>

  <!-- Form Beans Configuration -->
  <form-beans>
    <form-bean name="searchForm"
               type="com.jamesholmes.minihr.SearchForm"/>
  </form-beans>

  <!-- Action Mappings Configuration -->
  <action-mappings>
    <action path="/viewSearch"
            type="org.apache.struts.actions.ForwardAction"
       parameter="search.page"/>
    <action path="/search"
            type="com.jamesholmes.minihr.SearchAction"
            name="searchForm"
           scope="request"
        validate="true"
           input="search.page"/>
  </action-mappings>

  <!-- Message Resources Configuration -->
  <message-resources
    parameter="com.jamesholmes.minihr.ApplicationResources"/>

  <!-- Tiles Configuration -->
  <plug-in className="org.apache.struts.tiles.TilesPlugin">
    <set-property property="definitions-config"
                     value="/WEB-INF/tiles-defs.xml"/>
  </plug-in>

</struts-config>

WEB.XML

<taglib>
    <taglib-uri>/WEB-INF/tld/struts-tiles.tld</taglib-uri>
    <taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
  </taglib>

mainLayout.jsp

<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tld/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/tld/struts-tiles.tld" prefix="tiles" %>

<html>
<head>
<title><tiles:getAsString name="title"/></title>
</head>
<body>

<tiles:insert attribute="header"/>

<tiles:insert attribute="body"/>

<tiles:insert attribute="footer"/>

</body>
</html>

search.jsp

<html:errors/>

<html:form action="/search">

<table>
<tr>
<td align="right"><bean:message key="label.search.name"/>:</td>
<td><html:text property="name"/></td>
</tr>
<tr>
<td></td>
<td>-- or --</td>
</tr>
<tr>
<td align="right"><bean:message key="label.search.ssNum"/>:</td>
<td><html:text property="ssNum"/> (xxx-xx-xxxx)</td>
</tr>
<tr>
<td></td>
<td><html:submit/></td>
</tr>
</table>

</html:form>

header.jsp and footer.jsp just have a <hr> at the momemnt
0
 
LVL 11

Expert Comment

by:fargo
ID: 16683157
don't u have taglib uri definitions in web.xml for struts-html, struts-logic and struts-bean ??
0
 
LVL 1

Author Comment

by:muthiahmerchant
ID: 16683180
I am sorry, I do, I thought only the tiles was important and hence copied that part alone

web.xml

<taglib>
    <taglib-uri>/WEB-INF/tld/struts-bean.tld</taglib-uri>
    <taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
  </taglib>
  <taglib>
    <taglib-uri>/WEB-INF/tld/struts-html.tld</taglib-uri>
    <taglib-location>/WEB-INF/tld/struts-html.tld</taglib-location>
  </taglib>
  <taglib>
    <taglib-uri>/WEB-INF/tld/struts-logic.tld</taglib-uri>
    <taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location>
  </taglib>
  <taglib>
    <taglib-uri>/WEB-INF/tld/struts-tiles.tld</taglib-uri>
    <taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
  </taglib>

Your help is greatly appreciated.

Thanks
0
 
LVL 1

Author Comment

by:muthiahmerchant
ID: 16686065
I solved it. I am not sure what exactly the problem was. some place i was using
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
and in some other files i was using
<%@ taglib uri="http://jakarta.apache......" prefix="html"%>

my tiles def was using dtd 1.1 and struts config was using dtd 1.2.

I cleaned it up a little bit, made it consistent and it worked.

Thanks
Muthiah
0
 
LVL 11

Expert Comment

by:fargo
ID: 16688233
good that it solved your problem. I am surely not happy with grade "B"...
With this i got guru level in jsp..thx
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question