views:

59

answers:

2

We're converting an older Struts 1.x app from HTML4 to XHTML1.1. To force compliance from the Struts tags, we're adding

<html:xhtml /> 

to the top of our JSPs.

After doing this, JSPs using

<html:form method="post" action="/foo.do" styleId="bar">

threw the following error:

Cannot specify "styleId" when in XHTML mode as the HTML "id" attribute is already used to store the bean name

I read that The solution is to remove the styleId and use the name of your form bean, as that will be inserted as the id in your HTML. We can take out the styleId, but when 2 forms on the same page submit to the same action, they end up with the same id and the XHTML is no longer valid!

Do we have any other options while still using Struts tags?

A: 

If all you need to do is differentiate between the two forms, then just add a parameter to the action...

<html:form method="post" action="/foo.do?id=bar">
...
</html:form>
...
...
<html:form method="post" action="/foo.do?id=foo">
...
</html:form>

Then in your action, you just have to get the parameter from the request. Its been a while since I have used struts, but I had multiple forms going to the same action, and this is how I solved it.

Codemwnci
A: 

1) For your xhtml compliance, rather do this:

<html:html xhtml="true">

</html:html>

The styleId="bar" is rendered to html as id="bar" and that's why you're getting an exception (because Structs generates the following in html)

<html:form method="post" action="/foo.do" styleId="bar">

to

<form id="foo" action"/foo.do" id="bar">

(Bear in mind that id="foo" depends on your declaration of <action name="foo" />). StyleId is used for element attribute purposes, e.g. styleClass="this" will render class="this"

A solution would be to add an id to the action, as in:

<html:form method="post" action="/foo.do?id=blah" styleId="bar">
The Elite Gentleman