当前位置: 动力学知识库 > 问答 > 编程问答 >

jsp - Struts 2 + Disable Form Autocomplete

问题描述:

We need to use the equivalent of 'autocomplete' attribute in our jsp's and ftl's. We are currently using struts tags (struts2-core version 2.1.6) and i don't see any attribute within the struts 2 domain which would help us disable the autocompletion of form fields.

Any idea on how we can implement this feature?

网友答案:

You could edit the struts2 tags... although I would just use jQuery to add autocomplete="false" to all the desired form elements. All struts2 UI tags have a class and id attribute. You could create a noComplete class, which the script will act on.

网友答案:

Struts2 tags support dynamic attributes, which allow you to specify arbitrary attributes to JSP tags. I'm not sure when this support was added, so you may need to upgrade from 2.1.6 if it doesn't support it.

You can tell by looking in the struts-tags.tld. The <tag/> entries should contain the following:

<dynamic-attributes>true</dynamic-attributes>
网友答案:

In my struts2 app I am using javascript to do disable autocompleter

    for (i=0; i<document.forms.length; i++) {
            document.forms[i].setAttribute("AutoComplete","off");
    }

Call this code on page load. As you should know struts tags are converted into simple HTML tags when the page is loaded (you can check this by looking at the source of the page), so after the page is loaded the struts2 <s:form> tag will be a simple HTML <form> tag to ahich you can set the Autoomplete attribute

分享给朋友:
您可能感兴趣的文章:
随机阅读: