views:

3454

answers:

5

Here's the .jsp code:

<table>
  <s:iterator value="allAgents">
   <tr>
    <td><s:property value="firstName" /></td>
    <td><s:property value="middleName" /></td>
    <td><s:property value="lastName" /></td>
    <td><s:checkbox name="ss"/></td>
   </tr>
  </s:iterator>
</table>

When rendered, the checkbox would occupy a whole row below the 'names', centered. Here's the generated html for what's supposed to be a single row:

<tr>
    <td>first</td>
    <td>middle</td>
    <td>last</td>
    <td>
<tr>
    <td valign="top" align="right"></td>
    <td valign="top" align="left"><input type="checkbox" name="ss"
     value="true" id="agent_ss" /> <input type="hidden"
     name="__checkbox_ss" value="true" /></td>
</tr>

</td>
</tr>

Is it me or struts? TIA.

+1  A: 

You need to look into the theme that is being used for your form tag rendering. Struts2 uses a template system (defined in struts.properties). It looks like you are using the xhtml template by default which is designed to output a two-column table. You can default to simple in the app or override it on the tag-level (or five other hierarchies in between).

Here's some more info: http://struts.apache.org/2.0.14/docs/themes-and-templates.html

edeviant
No, I suppose. Its rendering it perfectly in 4 columns as expected. The only problem is the tag <s:checkbox>.
Adeel Ansari
Yeah, it's only s:checkbox that misbehaves. I'm using <s:head theme="ajax"/>; the behavior is the same with all themes though.
alex
A: 

The problem is that with the default struts theme, s:checkbox is a table cell itself. (Struts 2 renders it as a table cell)

In your jsp you include it in <td> tags again (which is not needed)

Try removing the <td> tags around the checkbox tag.

kazanaki
A: 

Add the property theme="simple" like

A: 

Struts2 renders s:checkbox as a table cell itself.The reason is tht struts2 uses a template system for tag rendering. The default is (as defined in struts-default.properties)

Standard UI theme

struts.ui.theme=xhtml

struts.ui.templateDir=template

struts.ui.templateSuffix=ftl

You need to make this change -- struts.ui.theme:simple

It can be done by adding

constant name="struts.ui.theme" value="simple" /> tag

in the "struts.xml".This wil suffice.

A: 

When defining your checkbox, use "theme = simple" attribute as shown in the following:

The "simple" theme will put your checkbox in the same row as the other fields of your. Cheers.