Sunday, October 6, 2013

How to apply atheme to Struts2 Forms

Sometimes even if we try to align 2 components in UI of struts form, they will not get aligned.For eg: I needed to have two text boxes in one row.So in such a situation I can do below.

For eg: When you use a Struts 2 tag such as s:select in your web page, the Struts 2 framework generates HTML that styles the appearance and controls the layout of the select control. The style and layout is determined by which Struts 2 theme is set for the tag. Struts 2 comes with three built-in themes: simple, xhtml, and css_xhtml. If you don’t specify a theme, then Struts 2 will use the xhtml theme by default.

I can either change struts.xml as below.Then it will apply all pages.

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



xhtml layout
The xhtml theme renders out a two-column table. If a different layout is needed, do not write your own HTML. Create a new theme or utilize the simple theme.

If we get the issue of labels of text fields missing we can have like below.


              <td><label for="a" class="label" theme="simple">Firstname:</label></td>
              <td><s:textfield id="a" name="username" label="Username" size="20" theme="simple"/></td>

               <td><label for="b" class="label" theme="simple">LastName:</label></td>
              <td><s:textfield id="b" name="lastName" label="lastName" size="20" theme="simple"/></td>

<tr><s:submit method="execute" label="login" align="center" /></tr>

 It will show components in one row.

No comments:

Post a Comment