views:

2439

answers:

3

I use struts-html to generate forms fields.

For example:

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

<html:text property="email" styleId="email" size="44"/>

generates:

<input type="text" name="email" size="44" value="" id="email">

As shown above the generated input tag is not closed. This causes my html to be not valid.

struts-html.tld includes:

<tlibversion>1.2</tlibversion>
<jspversion>1.1</jspversion>
<shortname>html</shortname>
<uri>http://struts.apache.org/tags-html&lt;/uri&gt;

Does anyone knows why is the generated input not closed? Is there a newer version? Where can it be downloaded?

I tried using:

<html:html xhtml="true">

which renders as:

<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">

However, my input tags keep rendering unclosed.


Solution:

Use the tag:

<html:xhtml/>

Note: If you use Tiles, as I do, use it directly inside your included jsp. It is not inherited from your base template file.

Note: Within xhtml mode you can not use sytleId inside a html:form tag. It is not a problem since the id property is automatically generated to store your bean's name.

A: 

input tags don't have to be closed in HTML, so I'm guessing Struts doesn't know you're trying to generate XHTML. Sadly, my Struts-fu is so ancient I have no idea how to go about fixing it. Maybe you should fall back to HTML instead of XHTML; XHTML really only comes into its own when you're using other namespaces, such as SVG or MathML.

Hank Gay
+5  A: 

Can you not just use <html:xhtml/>?

Using this tag in a page tells all other html taglib tags to render themselves as XHTML 1.0

Alternatively you could use <html:html xhtml="true">.

Phill Sacre
The `<html:xhtml/>` construct works just fine on the sites that I've developed. (And it has to, because the generated markup is being returned via AJAX calls, which will reject invalid XML)All the other examples, that you give, match mine too.Which version of struts are you using?
belugabob
A: 

There must be a backing Java code that does the actual generation. Grab the source of the library since it's already open sourced and check if the code consults some parameters when it appends the closing tag bracket '>'. If it doesn't do that at all you may modify the library, use the patched version and contribute the patch.

Boris Pavlović