Struts 2 + disable autocomplete form

We need to use the equivalent of the autocomplete attribute in our jsp and ftl. We are currently using struts tags (struts2-core version 2.1.6), and I do not see any attributes in the struts 2 domain that would help us turn off auto-completion of form fields. Any idea on how we can implement this function?

+3
source share
3 answers

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

+6
source

Struts2 tags support dynamic attributes, which allow you to specify arbitrary attributes in JSP tags. I am not sure when this support was added, so you may need to upgrade from version 2.1.6 if it does not support it.

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

 <dynamic-attributes>true</dynamic-attributes> 
+4
source

In my struts2 application, I use javascript to disable autocomplete

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

Call this code when the page loads. Since you should know that struts tags are converted to plain HTML tags when the page loads (you can check this by looking at the page source), so after loading the page the struts2 <s:form> will be a simple HTML <form> so you can set autocomplete attribute

+1
source

Source: https://habr.com/ru/post/1502168/


All Articles