Hi, here is the question:
I have 2 textfields in my JSP:

<s:textfield name=" ...." />
<s:textfield name=" ...." />

Now I went to browser and did: View Source Code, and noticed that around the above tags, there were auto-generated tags that put the above fields into 2 rows in a table. It was like:

<tr><td>
<input type="text"  ....>
</td></tr>
<tr><td>
<input type="text"  ....>
</td></tr>

Now I wanted those 2 fields to be at the same row, so I originally wrote:

<table>
<tr>
 <td>  
   <s:textfield name=" ...." />
  </td>
  <td>  
   <s:textfield name=" ...." />
  </td>
 </tr>
</table>

But when I viewed the page at the browser the GUI was messed up and those 2 fields were put one under the other (like in 2 different rows because of the extra generated tr, td tags), But I wanted those fields to be at the same row next to each other (2 different columns).

I am sure that I am doing something wrong, because I have just started learning Struts 2, so is there a way for what I want to be done?
Am I making any sense?

Thanks

I think I have found the solution.
By default the tags in Struts 2 have a theme that renders the tags inside a table.

This can be changed by adding a file:
struts.properties with the line:

struts.ui.theme=css_xhtml

The above changes the way the tags would be rendered. The default is this: xhtml. If you use this: simple the tags would be displayed the way you write them in the code.

With the one I am using it generates <div> tags around the components in order to be easier to add .css style later

have you got solution ? because i also messed up with same problem and dont know how to fix it. if you got solution please reply.

Yes:

This can be changed by adding a file:
struts.properties with the line:

> struts.ui.theme=css_xhtml

The above changes the way the tags would be rendered. The default is this: xhtml. If you use this: simple the tags would be displayed the way you write them in the code.

With the one I am using it generates <div> tags around the components in order to be easier to add .css style later

Also I think that you can set the theme at each tag that you write. But that is not very helpful. It is better to have it in one prop file.

have you got solution ? because i also messed up with same problem and dont know how to fix it. if you got solution please reply.

It is not necessary to have a css file, but if you use this value:
css_xhtml
and you right click the page to View the Source code you will see div tags automatically added with some default class names. You can add your own class names in the tags but if you omit them the defaults will be added.
Then if you want you can create a .css file with the default class names, and you won't have to worry about adding the class or the id attribute to your tags anymore. And all your application will have the same look and feel.

Also I don't remember where to put the properties file. It's been a while. But you should be able to search the internet on how to deploy and run a Struts 2 applications or by simply searching the struts.properties

<s:textfield name=" ...." theme="simple" />
<s:textfield name=" ...." theme="simple"/>

should do the trick

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.