如何在 struts2 标签中使用 css 样式? [英] How to use css styles in struts2 tags?

查看:49
本文介绍了如何在 struts2 标签中使用 css 样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 struts2 应用程序中使用 Metro CSS 主题.我正在使用带有 CSS 类的 html 标签,效果很好.但是在创建验证逻辑时,我发现它确实验证了表单但没有显示任何错误.

I am using metro CSS theme in my struts2 application. I was using html tags with CSS classes which was working fine. But while creating validation logic I found that It does validate the form but doesn't show any error.

<form action="register.action" method ="post" validate="true">
 <div class="input-control text span3">
    <input type="text" name="username" placeholder="Enter User Name" value="" />
    <span class="helper"></span>
 </s:div> 
</form>

然后我切换到 struts2 html 标签,它开始显示错误,但现在我没有附加样式.我使用 struts2 html 标签的 cssClass 属性为表单和 div 标签提供样式,这些标签效果很好,但是在将 <input type="text"> 标签更改为 <s:textfield> 所有附加到输入框的样式都消失了.

then I switched to struts2 html tags and it started showing errors but now I have no style attached. I used cssClass attribute of struts2 html tags to give style to form and div tags which worked well but after changing <input type="text"> tag to <s:textfield> all the style attached to input box is gone.

请建议我如何使用 struts 标签来保留 CSS 样式.

Please suggest me how to use struts tags preserving CSS styles.

推荐答案

如果您已经拥有所有具有自己样式和元素的 JSP-s,请使用 Struts2 simple 主题.此主题不会创建其他元素,也不会显示验证错误.但是你可以使用 fielderror 标签来显示验证错误 http://struts.apache.org/2.x/docs/fielderror.html.所以你的表格看起来像这样:

If you already have all JSP-s with your own styles and elements use Struts2 simple theme. This theme will not create additional elements nor show validation errors. But you can use fielderror tag for showing validation errors http://struts.apache.org/2.x/docs/fielderror.html. So you form will look something like that:

<form action="register.action" method ="post" validate="true">
  <div class="input-control text span3">
    <s:fielderror fieldName="username"/>
    <s:textfield name="username" placeholder="Enter User Name"/>
    <span class="helper"></span>
  </s:div>
</form>

您可以使用 struts.ui.theme 常量在 struts.xml 文件中为整个应用程序定义默认主题.

You can define default theme for the whole application inside your struts.xml file by using struts.ui.theme constant.

<constant name="struts.ui.theme" value="simple" />

这篇关于如何在 struts2 标签中使用 css 样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆