Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Auto-complete(autocomplete="off") using STRUTS

i tried to disable auto complete(autocomplete="off") in struts framework,the process i followed is 1)In Strut-html.tld file i had few attributes of TextTag so added autocomplete attribute

<tagclass>org.apache.struts.taglib.html.TextTag</tagclass>
<attribute>
<name>autocomplete</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>   
</attribute>

2)i wrote a class for customtag by extending org.apache.struts.taglib.html.TextTag

import org.apache.struts.taglib.html.TextTag.*;

public class TextTag extends org.apache.struts.taglib.html.TextTag { 


private static final long serialVersionUID = 1L;
private String autocomplete = null;

public String getAutocomplete()
{ return autocomplete; }

public void setAutoComplete(String autocomplete)
{
this.autocomplete = autocomplete; 

} 

protected void prepareOtherAttributes(StringBuffer sb) { 


if (autocomplete != null) { 

sb.append(" autocomplete=\""+autocomplete+"\""); 
}
}
}

3) And in jsp page i added autocomplete="off" attribute

so when i run my application im getting the following error

/index.jsp(1): Error in using tag library uri='/tags/struts-html' prefix='html':
The Tagclass'org.apache.struts.taglib.html.FormTag' has no setter method corresponding  
to TLD declared attribute 'name', (JSP 1.1 spec, 5.4.1)  probably occurred due to an 
error in /index.jsp line 1:  
<%@ taglib uri="/tags/struts-html" prefix="html" %>

Some one please help me to solve this error and i tried with javascript as well but its not working.

function DisableAutocomplete()
{
var AC_Disable_login=document.forms[0].elements['loginID'];
AC_Disable_login.setAttribute ("autocomplete", "off");
}
like image 372
JayanthSuresh Avatar asked Oct 20 '22 07:10

JayanthSuresh


1 Answers

You do not need to rewrite Struts 1.x to add this functionality. All you need is to add the following lines:

<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
    $(function(){
        $(":text").attr("autocomplete", "off");
    });
</script>
like image 75
Paul Vargas Avatar answered Oct 23 '22 02:10

Paul Vargas