Remove id and/or autocomplete from viewstate in JSF

In this tutorial we will show you how to remove the id and/or autocomplete attribute from the viewstate. Although it is not a good idea to remove the autocomplete function in firefox. We can howver remove the id from the viewstate. This is sometimes required when you have multiple forms in your page with the same id.

Default Generated Output

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <h1>JSF Viewstate without and or autocomplete</h1>
	<form id="user-form" ...;>
		<input type="hidden" name="user-form" value="user-form" />
		<input type="hidden" name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:0" value="..." autocomplete="off" />
	</form>
</body>
</html>

Remove autocomplete and/or id attribute from ViewState

You must add these context parameters to your servlet descriptor (web.xml) of your project to remove the id and/or autocomplete attribute.

<!-- remove auto-complete attribute from view-state -->
<context-param>
    <param-name>com.sun.faces.autoCompleteOffOnViewState</param-name>
    <param-value>false</param-value>
</context-param>
<!-- remove id attribute from view-state -->
<context-param>
    <param-name>com.sun.faces.enableViewStateIdRendering</param-name>
    <param-value>false</param-value>
</context-param>

Generated Output Without id and autocomplete

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <h1>JSF Viewstate without and or autocomplete</h1>
	<form id="user-form" ...>
		<input type="hidden" name="user-form" value="user-form" />
		<input type="hidden" name="javax.faces.ViewState" value="..." />
	</form>
</body>
</html>

References

Download

You may also like...