简体   繁体   中英

Styling Struts2 textfield tags

I have this form.

<s:form action="register">

      <s:textfield class = "formfield" name="userBean.username" label="User Name" />
      <s:textfield class = "formfield"  name="userBean.password" label="Password" />
      <s:textfield class = "formfield"  name="profileBean.firstName"  label ="First Name"/>  
      <s:textfield class = "formfield"  name="profileBean.lastName"  label="Last Name"  />
      <s:textfield class = "formfield"  name="profileBean.Age"  label="Age"  />

      <s:submit/>
</s:form>   

What I wanted to do is provide it custom styling through css, but the problem is it is not being applied, what is the solution for this? our designers will style our form using css but however, there styling could not be applied if we convereted their form in struts tags

What we are aiming to do is to style it similar to how you style input tags

I think you are suppose to use the attribute cssClass

eg <s:textfield cssClass = "formfield" name="userBean.username" label="User Name" />

As said in the other answer, you must use cssClass instad of class , and cssStyle instead of style .

If you note that the behaviour of Struts2 components is different from standard HTML components, it is due to Struts2 Themes and Templates .

The default theme is XHTML;

For example,

when you set label attribute on your <s:textfield/> tag, it will create the html <label/> element before the <input="text"/> tag. If you don't want that, you can specify theme="simple" in your <s:textfield/> , or in your <s:form/> to apply the setting to all the contained elements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM