简体   繁体   English

样式化Struts2文本字段标签

[英]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? 我想做的是通过CSS为它提供自定义样式,但是问题是没有应用它,对此有什么解决方案? our designers will style our form using css but however, there styling could not be applied if we convereted their form in struts tags 我们的设计师将使用CSS为表单设置样式,但是,如果我们在struts标签中将其表单转换为样式,则无法应用样式

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 我认为您应该使用属性cssClass

eg <s:textfield cssClass = "formfield" name="userBean.username" label="User Name" /> 例如<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 . 正如在其他的答案说,你必须使用cssClass的instad classcssStyle而不是style

If you note that the behaviour of Struts2 components is different from standard HTML components, it is due to Struts2 Themes and Templates . 如果您注意到Struts2组件的行为与标准HTML组件不同,则归因于Struts2主题和模板

The default theme is XHTML; 默认主题是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. <s:textfield/>标记上设置label属性时,它将在<input="text"/>标记之前创建html <label/>元素。 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. 如果不希望这样,可以在<s:textfield/><s:form/>指定theme="simple" ,以将设置应用于所有包含的元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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