Struts2 / css in textfield

喜欢而已 提交于 2019-12-04 06:49:54

问题


I am beginning with struts2 programming and I wondered how I could do the following thing. I have this struts code in a form :

<s:textfield name="aName"/>

And I had this html code before using struts2 :

<input id="aLogin" type="text" class="form-control" name="username" value="" placeholder="something" required autofocus>

How could I "merge" these two lines to do the same html code but using my struts2 code ?


回答1:


In Struts tags, class ans style becomes cssClass and cssStyle; in old versions of Struts, required was an attribute indicating when to put the * mark, now changed to requiredLabel to avoid overriding the HTML5 required attribute. Other HTML5 attributes like placeholder and autofocus can be set because Textfield tag Allows Dynamic Attributes.

Then in your case:

<s:textfield id = "aLogin" 
           name = "aName" 
       cssClass = "form-control" 
          value = ""
    placeholder = "something" 
       required
      autofocus />

For other info, refer to the official <s:textfield/> documentation




回答2:


name should be same as that of bean variable,therefore,

<s:textfield name="username"/>

this will work, only if you have setUsername method in your action class.



来源:https://stackoverflow.com/questions/27212433/struts2-css-in-textfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!