Search code examples
jsptemplatesstruts2themesstruts-1

UI is not loading properly (Struts 1 to Struts 2)


I'm migrating an application from Struts 1 to Struts 2, when I changed the form tag to s:form in the JSP file, the style and alignment loaded wrong, but when I leave the form tag, the page loaded properly.

I added the taglib and !DOCTYPE html PUBLIC

Do you have an idea why happens this?


Solution

  • Struts2 uses themes and templates for their tags.

    You can learn here to get know which HTML content is generated when using Struts UI tags.

    By default Struts2 uses xhtml theme for generating html content of form fields like textfield tag. This theme is using a layout with for input elements. This breaks your design because these elements is placed outside tag. If you want to use instead of for your input fields then you can choose css_xhtml theme. If you want to omit to generate or then you can use simple theme. For example

    <s:form theme="simple">
     <div>
       <s:textfield name="myfield" />
     </div>
    </s:form>