25753

How to avoid generating more HTML elements in Struts

Question:

When Struts(2)' UI tags are used, more HTML elements are generated automatically.For example, when defining <s:form ... > it includes form within a table(even though such table is not declared by us). So, if any CSS is used(lets say, a div tag is only used and located input elements according to the CSS), all elements are not viewed as expected because of auto generated elements and their postions. Even if the struts is allowed to generate such elements and we add CSS to them, then another weight must be bored to add css to design auto generated html elements because more elements are generated in various positions and sizes. Also as I feel, more html codes may effect the browser page loading time.

So is there a way to avoid generating such elements when struts UI tags are used<br /> OR ELSE<br /> is there a convenient way to work with CSS in Struts UI tags ? (I read a question in Stackoverflow and it had said for an answer that, to add css finally which the struts generated. But it is not that much easy when compare to normal jsp html designing level..)

Answer1:

In short Struts2 work on the concept of themes and it provides certain theme out of the box. Based on the theme selected it will generate some HTML code for the used tags when rendering the view.

<a href="http://struts.apache.org/2.3.1/docs/struts-2-themes.html" rel="nofollow">Themes</a> are really a very nice and beautiful concept of Struts2 and it even provides you the way to create a custom themes are per your requirement.

coming to your Question by default Struts2 use xhtml theme which means it will generate some HTML (which includes tables as name suggested) while rendering the HTML for the used tags.

you can control the HTML generation by specifying simple theme either in struts.properties file or in struts.xml file

<h2>Struts Properties file</h2> struts.ui.theme=simple <h2>Struts.xml file</h2> <constant name="struts.ui.theme" value="simple" />

Other theme being provided by S2 out of the box are

<ul><li>css_xhtml: generate div based HTML</li> <li>ajax: for ajax tags</li> </ul>

Note that simple theme will not generate any extra HTML but only tags equivalent HTML code and you have full control to customize ur view by providing your own CSS and any other properties.

Above settings in properties file as well in struts.xml will be applicable to entire application which means each and every tag will generate same HTML for whole appllication.beside that if you want to control per tag HTML generation each S2 tag as a property namely theme, provide value to this property like simple,css_xhtml etc to control per tag HTML generation.

There is one more way to control the theme per request basis by using the following code <s:set name="theme" value="'simple'" scope="page" /> or

<s:set name="theme" value="%{myTheme}" scope="page" />

Choice is all yours which way you want to go

Answer2:

Add theme="simple" to the Tag.

Sample Code:

<s:select id="..." list="..." theme="simple">

Recommend

  • How to use fmt.Sscan to parse integers into an array?
  • is it possible to have partial xaml like partial class?
  • What icons required for app to submit to MAC App Store?
  • Add an entry to the legend for a manually added line
  • Submitting two different forms with an external Submit button not working properly
  • Multiple Layouts Previews for Android in Eclipse
  • Render html in springfox-swagger-ui
  • Set text in TextView in custom dialog
  • How to move axis labels automatically in rgl R
  • Positioning children objects in scene (car wheels hierarchy)
  • Python find continuous interesctions of intervals
  • Skip Characters in Oracle TO_DATE function
  • Efficient & Pythonic way of finding all possible sublists of a list in given range and the minim
  • Best way to dynamically load an xml configuration file into a Flex4/Flash movie at runtime?
  • Do I need to seed any random number generator before using EVP_PKEY_keygen of OpenSSL?
  • uniform generation of points on 3D box
  • how to avoid repetitive constructor in children
  • How to get Eclipse Oxygen to run on Java 9
  • JQuery Internet Explorer and ajaxstop
  • How to delay loading a property with linq to sql external mapping?
  • Control modification in presentation layer
  • Cannot connect to cassandra from Spark
  • Does CUDA 5 support STL or THRUST inside the device code?
  • htaccess rewriting URLs with multiple forward slashes
  • Display Images one by one with next and previous functionality
  • Web-crawler for facebook in python
  • R: gsub and capture
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Comma separated Values
  • retrieve vertices with no linked edge in arangodb
  • A cron job substitute?
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • SQL merge duplicate rows and join values that are different
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • LevelDB C iterator
  • How can I remove ASP.NET Designer.cs files?
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • Can't mass-assign protected attributes when import data from csv file
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?