Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put <s: select...> and <s: textfield> in a single line - struts2?

Tags:

jsp

struts2

This is somehow embarrassing. I'm using Struts2 in a small project of mine. In the JSP, when I put something like this:

<s:select list="keywords" key="label.search" name="selectedKeyword"/>
<s:textfield name="searchparams" size="20" cssClass="label"/>

I get this (sorry, I'm a new user, so I can't add images): http://i.stack.imgur.com/ZA2Wg.png

--dropdown_--
[              ] < textfield

What I want is that the textfield is next to the dropdown, in the same line. Is there a way to do this without creating my own theme?

Thank you in advance!

like image 992
brimbela Avatar asked Dec 18 '10 15:12

brimbela


2 Answers

The Struts2 tags are themed using FreeMarker. You can either change from the default XHTML theme to the simple theme by specifying the following in your struts.properties:

struts.ui.theme=simple

Or you can override the theme for just those tags by adding the theme attribute as follows:

<s:select list="keywords" key="label.search" name="selectedKeyword" theme="simple"/>
<s:textfield name="searchparams" size="20" cssClass="label" theme="simple"/>

Here's some additional information about themes.

like image 91
Steven Benitez Avatar answered Sep 28 '22 09:09

Steven Benitez


Note for struts.properties not preferred:

"It's also possible to define constants in our web.xml file; this is useful when we don't need an XML-based configuration. Either is acceptable: which is used depends on your needs and preferences. We can also define constants in a file named struts.properties, also on the classpath, that this is not preferred." - Apache Struts2 pg 21.

To struts configuration in web.xml:

<filter>
    <filter-name>action</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    <init-param>
        <param-name>struts.ui.theme</param-name>
        <param-value>simple</param-value>
    </init-param>
</filter>

How to set parameter for a whole page:

Maybe not for everyone but personally if I don't want what ever is the default I will want to use another theme for the whole page, so this is convenient.

<s:set var="theme" value="'simple'" scope="page" />

How to set parameter in struts.xml:

Just under the root 'struts' tag you can define constants like so...

<constant name="struts.ui.theme" value="simple" />
like image 21
Quaternion Avatar answered Sep 28 '22 10:09

Quaternion