How to produce javax.faces.ViewState hidden field without 'id' and 'autocomplete' attributes
Asked Answered
D

5

8

This is what I have in the output HTML document (produced by JSF 2.0/Mojarra 2.0.3):

<input type="hidden" name="javax.faces.ViewState" 
id="javax.faces.ViewState" value="4267906931114993858:-6309146738430577631"
autocomplete="off" />

My document should be XHTML 1.1 compliant, where attribute autocomplete is not valid and id attribute is duplicated over all forms. How to instruct JSF to produce everything strictly compliant to XHTML?

Delve answered 1/3, 2011 at 8:8 Comment(2)
There is no such thing as XHTML 1.1 strict. XHTML 1.0 has Strict, Transitional and Frameset variants. XHTML 1.1 is just XHTML 1.1Arawn
@David thanks, I corrected my questionDelve
A
3

See.

 <context-param>
   <param-name>com.sun.faces.autoCompleteOffOnViewState</param-name>
   <param-value>false</param-value>
 </context-param>

 <context-param>
   <param-name>com.sun.faces.enableViewStateIdRendering</param-name>
   <param-value>false</param-value>
 </context-param>
Agathy answered 20/1, 2012 at 18:0 Comment(0)
P
2

The non unique use if the ID javax.faces.ViewState is a bug that appears Oracle will not fix. They have closed these tickets. No workaround.

Puke answered 12/4, 2011 at 12:29 Comment(1)
Last one is still open and targeted for 2.2: java.net/jira/browse/JAVASERVERFACES-1699Dove
K
1

How to instruct JSF to produce everything strictly compliant to XHTML?

That's not a matter of "instructing" the JSF implementation with a simple flag. It's something that has to be continuously checked and thus only possible when it's considered important by the project. XHTML strict imposes a lot of restrictions and is probably therefore generally not considered worth supporting - see this bug. Note also that any component library you use also has to support it.

You'll have a lot more luck with XHTML 1.0 Transitional - I can confirm that MyFaces does produce valid XHTML 1.0 Transitional (once you set the context param org.apache.myfaces.RENDER_VIEWSTATE_ID to false).

Konstantine answered 1/3, 2011 at 8:52 Comment(2)
Transitional isn't going to help — autocomplete is not in any XHTML 1.xArawn
@David: True. But even if you get rid of that, there are quite a lot of other things that all JSF implementations I know produce that are not XHTML Strict compliant.Konstantine
B
1

There is a solution to this problem, it was created in version 1.2_14 of JSF. I think the problem is related to the way that Firefox operates during the reset event (input type=reset) on hidden fields. There is a problem where the client viewState that is on a hidden field gets an inconsistent state. The solution for this problem was disabled the auto-complete in a strict way (and this is not XHTML compliant). The most interesting thing is that until 1.2_14 almost everybody lived with this potential error. So the JSF-RI implementation (Mojarra project) allowed a developer to disable this option using a parameter that you can edit in your web.xml, and this auto complete won't print anymore.

<context-param>
    <description>Put your description here :)</description>
    <param-name>com.sun.faces.autoCompleteOffOnViewState</param-name>
    <param-value>false</param-value>
</context-param>

It is really difficult to produce valid XHTML pages with component based frameworks like JSF, but at least a solution exists for this problem.

Betts answered 26/10, 2011 at 16:5 Comment(0)
N
0

It's not a good idea to disable autocomplete="off" for ViewState hidden input fields, because then Firefox doesn't refresh the ViewState-Id on page refresh. This causes unusable JSF forms and functionalities.

See this post for details.

Newby answered 13/2, 2015 at 12:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.