• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Multiple forms and duplicate javax.faces.ViewState ids

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have a page with multiple forms each such form has its own hidden ViewState field. This gives rise to warnings when using a validator such as HTML Tidy as each field has an identical id. Is there any way to eliminate this duplication of ids?
 
Saloon Keeper
Posts: 23729
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch!

The "id" atribute MUST be unique - it's a stricture that comes from XML. If you don't explicitly provide an ID, the JSF code generators will generate IDs for you, but since they're unpredictable and subject to change, it's better to supply your own IDs for cases where you want to always know what the ID of an item is.

Actually, in JSF, I believe that the rule is that the ID has to be unique within an ID container (such as a form). JSF concatenates the control IDs to their parent IDs, so that the actual HTML id is unique.

However, I don't think that Tidy understands ID containers, so it wants the IDs to be unique per-page, rather than per-container. So, if possible, try and do things that way if you can.
 
iain coghill
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am pretty sure that an ID attribute should always be unique within an entire document. Browsers are more forgiving as long as the ID is unique within a form as they will not conflict on submission, but it is still wrong and HTML Tidy is correct to flag it.

The problem is that JSF is injecting a hidden field with id="javax.faces.ViewState" for each form. For example:


results in

I don't know how to control the ID of those javax.faces.ViewState fields.
 
author and cow tipper
Posts: 5001
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed, it is extremely important to make sure those id fields are unique.

Even when subviews may not be incorporated into a common form, and the temptation might be to ignore common ids on composite pages, one never knows when a page layout might change in the future. Plus, many helper classes, such as IBM's pagecode class, depends on a unique id across the page/form.

Try your best to keep those ids unique!

-Cameron McKenzie
 
iain coghill
Greenhorn
Posts: 14
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cameron Wallace McKenzie wrote:Indeed, it is extremely important to make sure those id fields are unique.

Even when subviews may not be incorporated into a common form, and the temptation might be to ignore common ids on composite pages, one never knows when a page layout might change in the future. Plus, many helper classes, such as IBM's pagecode class, depends on a unique id across the page/form.

Try your best to keep those ids unique!

-Cameron McKenzie



Indeed, that is why I use the handy Firefox HTML Validator add-on to catch such transgressions. The problem is that this particular hidden field is generated by JSF once per form, and I don't know if or how I can control the id generated.
 
First, you drop a couch from the plane, THEN you surf it. Here, take this tiny ad with you:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic