How to disable autocomplete for Struts tags(HTML:text)

偶尔善良 提交于 2019-12-04 05:31:46

问题


For normal HTML input tag,disabling autocomplete is simple as given below:

<input type="email" name="email" autocomplete="off">

Whereas its does not work for Struts tags given below:

<html:text property="" styleId="Field" maxlength="4" size="4" tabindex="14" 
    onblur="check(this);" value="" />

How to disable autocomplete for Struts tags?


回答1:


Autocomplete attribute is not passed through to the rendered HTML by the tag.

You can do so by writing your own custom tag that extends the tag to accept the autocomplete attribute and pass it through to the rendered tag.

check these links ::

Struts 2 + Disable Form Autocomplete

http://www.coderanch.com/t/54020/Struts/form-input-tags-turning-autocomplete




回答2:


I've met the same issue. Editing the tld attibutes did not help me. I resolved it by adding the attribute via JavaScript code. Here is an example:

<bean:define id="autoComplete" scope="request" type="java.lang.String"
    value="<%=String.valueOf(ApplicationConfiguration.getAutoComplete()) %>" />

<script>
    var ttip;
    var ttip2;
    Ext.onReady(function() {
        var form = document.forms['formName'];
        var elem = form.elements["passortField"];
        elem.setAttribute( "autocomplete", "${autoComplete}" );

ApplicationConfiguration.getAutoComplete() - returns either on or off, depending on application configuration




回答3:


Another option is to write your Own TextTag class something like this:

public class TextTagNoAutoComplete extends BaseFieldTag {
    public TextTagNoAutoComplete() {
         super();
         this.type = "text";
         doReadonly = true;
    }
    protected void prepareOtherAttributes(StringBuffer handlers) {
         prepareAttribute(handlers, "autocomplete", "false");
    }
}

and point textnac to this class in your tld mapping! ..and Viola ! Not the best reusable code. Provided the fact that, Struts 1.x is in no way going to be revisited, this sortta monkey patching is more than enough in my point of view :)




回答4:


You can use redisplay="false" which is the equivalent in struts-html for autocomplete.




回答5:


We can use the attributes which are not supported in <htm-text> inside \"

<html:text property="userName" styleId="firstname\" placeholder=\"Email*\" 
           autocomplete=\"off" styleClass="ql-inpt"  readonly="true" />   


来源:https://stackoverflow.com/questions/20322853/how-to-disable-autocomplete-for-struts-tagshtmltext

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