Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 853
yegor256 Avatar asked Mar 01 '11 08:03

yegor256


4 Answers

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>
like image 142
frekele Avatar answered Oct 17 '22 10:10

frekele


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.

like image 22
Ron Avatar answered Oct 17 '22 11:10

Ron


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).

like image 1
Michael Borgwardt Avatar answered Oct 17 '22 11:10

Michael Borgwardt


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.

like image 1
Saulo Andrade Almeida Avatar answered Oct 17 '22 11:10

Saulo Andrade Almeida