JSF: when disable component, its value does not make into the request map parameter. Is there a workaround?

Go To StackoverFlow.com

6

I have a drop down list p:selectonemenu and a checkbox p:selectbooleancheckbox, when I select the checkbox, I want to set the selectonemenu to a specific value. And I dont want the user to change it, so I set selectonemenu disabled attribute to true. However, when it is disabled, its value does not appear inside the request parameter map, when I do facescontext.getcurrentinstance().getexternalcontext().getrequestparametermap(), and I need its value to this map. Is there a way to get around this?

I writing a font-end to a legacy Servlet system, where they use request map parameters to obtain form attribute value.

2012-04-05 01:47
by Thang Pham
It doesn't appear because when the component is disabled, the browser doesn't send the components value to the server. Look for "readonly" parameter - Adrian Mitev 2012-04-05 06:14
@AdrianMitev: Unfortunately, even though JSF component h:selectonemenu have readonly attribute, primefaces component p:selectonemenu does no - Thang Pham 2012-04-05 13:49


8

As Adrian Mitev pointed out in a comment, disabling the selectBooleanCheckbox component will mean it will not post its value on a form submit.

What you can do however is have a hidden input field where you can set the value to the same managed bean property as the checkbox.

<h:inputHidden id="checkDisabled" value="#{managedBean.someValue}" />

Using a javascript you can set the value of this hidden input when the checkbox is disabled.

2012-04-05 12:03
by maple_shaft
This does by the way not specifically apply to checkboxes, but to all HTML input elements and buttons in general. If disabled="true", then its name=value will not be sent as request parameter. This is as per HTML specification: "Disabled controls cannot be successful."BalusC 2012-04-05 14:10
@BalusC: The above problem also give me trouble, since JSF component dont have name attribute (I think you set the name but setting the id), and if I set the id attribute of the <h:inputHidden> component, to be the same as the selectonemenu, then I got this exception Component ID cmbxFgnFormNumber has already been found in the viewThang Pham 2012-04-05 14:17
The ID get generated as name. Check HTML source. As to the new problem, either give the disabled checkbox a different ID, or use plain <input type="hidden"> instead (this won't prepend the form ID) - BalusC 2012-04-05 14:18
@BalusC and maple: Thank you, I get it working correctly - Thang Pham 2012-04-05 15:51
Ads