Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Change disabled attribute on client side

 
Tony David
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody

When a JSF component is initialized with the attribute disabled set to true, if we changed it on the client side with javascript code setting it to true, the value is not submitted.



If I changed the value of my component test, the text zone is enabled, but the value is not sent to the managed bean, so I suppose JSF checks its component tree before setting values, and this component was initially disabled that's why the value is not submitted.

What do you suggest to get the value on server side ?
I can get it in the request but I would like to know if we have a way to avoid that.

Thanks for your help
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18169
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only thing I can think of more likely to give you problems than using Javascript to alter the "disabled" attribute client-side is using Javascript to alter the "rendered" attribute client-side. In both cases, you can expect the JSF HTML renderer to produce seriously different HTML depending on which state these attributes were set to in the original template. In the case of "disabled", that probably includes extra form data that's not actually in - or even physically near - the disabled control itself.

The safest way to do this is to manage the disabled state via an EL reference to a server property. Which means at least a partial page refresh (AJAX) is needed to update the UI. An alternative is to code the control enabled and disable it under Javascript control. That way, you'll have the form metadata available when you re-enable it. This isn't totally safe, but short of getting the disable status from the server, it's about the best you can do.
 
Tony David
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for you help,
indeed, if the component is initialized with disabled set to true, it will not be in the JSF tree, so matching values will not be submitted.

As you suggest two ways to avoid that :

- Manage it with javascript by adding a JS script to disable the component just after the component declaration


- If we prefer to manage it completely with JSF, when we want to switch the disable state, we must trigger an Ajax event which will reassess the EL expression set on disabled attribute of the inputText.


If the component was set to disabled, so not present in the jsf tree, during the ajax request to enable it, it will be added, so the value may be submitted later
This solution will cost a request on the server..., just to change an element state

The perfect solution should be to manage the disable state with JSF and WITHOUT such an Ajax request but, I don't know why JSF specifies to not introduce disabled element in the JSF tree, because in my opinion
disabled during initialization phase does not mean disabled for all the component life.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic