Shubhankar
Shubhankar

Reputation: 87

How to change the label color of the textfield in Struts 2

I am stuck in changing the font color of

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

Here user.name=User comes from resource bundle. So in JSP HTML page, it displays User Name label and a textfield, but I want to change the font of User Name label.

Upvotes: 4

Views: 11242

Answers (4)

Divyanshu Kushwaha
Divyanshu Kushwaha

Reputation: 258

1.First define your textfield like this:

<s:textfield  id="tf1"  size="150%" />

2.Then create a label tag pointing to your created textfield like this:

<s:label  for="tf1" style="font-family:Arial;color: #af2d2d" value="my textfield"/>                             

Hope this helps!!

Upvotes: 0

sreenivasulu g
sreenivasulu g

Reputation: 7

Can you try below code

<s:label value="user.name" cssStyle="color: #ffffff;"/>
<s:textfield name="name" required="true"/>

if not work above code Struts support Theme and template feature for more information refer below link http://www.mkyong.com/struts2/working-with-struts-2-theme-template/ (Link have exmple for showing error message with color) and do changes according to your requirement

Upvotes: 0

Aleksandr M
Aleksandr M

Reputation: 24396

You can do this with CSS attribute selector. Give your <s:textfield> an id and reference this id in CSS like that:

<style type="text/css">
  label[for="nameFieldId"] {
    color: red;
  }
</style>

<s:textfield id="nameFieldId" name="name" key="user.name"/>

This will work because xhtml theme generates <label> for <s:textfield> tag with for attribute.

Upvotes: 2

sreenivasulu g
sreenivasulu g

Reputation: 7

Can you check <s:testfield> tag will support style attribute? If supports do like this

<s:testfield name=“name” key=“user.name” style="color:red;"/>

or else do like this

<span style="color:red;">
  <s:testfield name=“name” key=“user.name” style="color:red;"/>
</span>

in above line displays red color..if your want your custom color change red to your custom color

Upvotes: -1

Related Questions