Question

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.

Was it helpful?

Solution

Add the property theme="simple" like

OTHER TIPS

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.

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

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top