You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Luca Graf <lu...@gmx.de> on 2009/01/15 20:28:22 UTC

Input components with disabled=true

Hello together,

I got an problem with input components like <h:selectBooleanCheckbox> when i use the attribute disabled=true. My scenario is that i have two checkboxes. The second is initially set to disabled=true. Now the user should only get access to the second if he changed the value of the first before. 

My approach was, if the user changed the value of checkbox1 then i set the attribute of checkbox2 via javascript to disabled=false.

Example:
<h:selectBooleanCheckbox id="checkbox1" onchange="var element=document.getElementById('checkbox2'); if(element.disabled) element.disabled = false; else element.disabled = true;">

<h:selectBooleanCheckbox id="checkbox2" disabled="false"/>

On the first it looks good, after the user has changed the value of the first checkbox, the second is now accessible via html.
But it looks that the value is doesn't send in the request to the server, like the normal behavior for an input element with disabled=true.

It is not enough to set disabled=false in HTML to get the value of checkbox2 to the server?


Thanks,
Luca


 


Re: Input components with disabled=true

Posted by Richard Yee <ri...@gmail.com>.
Luca,
The behavior you see is normal. If you are manipulating the view state  
with you own javascript, the changes will not be seen by the server.  
You should instead handle the event on the server and update the page  
via ppr(autosubmit, partialsubmit, and partialtrigger).

-Richard

Sent from my iPhone

On Jan 19, 2009, at 5:16 AM, LucaGraf@gmx.de wrote:

> Hi Simon,
>
> thanks for your hint to use readonly instead. I played now a little  
> with it and the values are sent back to the server (they are listed  
> in the requestParameterMap). But it looks like it is not possible to  
> use an input component that are declared as readonly together with  
> an valueChangeListener?
>
> Example:
>
> <h:inputText id="stringValue" value="#{property.stringValue}"  
> valueChangeListener="#{bean.propertyValueChanged}" readonly="true"/>
>
> The propertyValueChanged listener will never get invoked ... if this  
> the normal behavior or maybe i do something wrong?
>
> Before i submit the form, the field will set to input.readOnly =  
> false; via javascript.
>
> Thanks,
> Luca
>
> I use myfaces-1.1.6 with tomahawk-1.1.8 and facelets-1.1.14
>
>
> -------- Original-Nachricht --------
>> Datum: Fri, 16 Jan 2009 21:37:53 +0100
>> Von: Simon Kitching <sk...@apache.org>
>> An: MyFaces Discussion <us...@myfaces.apache.org>
>> Betreff: Re: Input components with disabled=true
>
>> On Thu, 2009-01-15 at 20:28 +0100, Luca Graf wrote:
>>> Hello together,
>>>
>>> I got an problem with input components like  
>>> <h:selectBooleanCheckbox>
>> when i use the attribute disabled=true. My scenario is that i have  
>> two
>> checkboxes. The second is initially set to disabled=true. Now the  
>> user should
>> only get access to the second if he changed the value of the first  
>> before.
>>>
>>> My approach was, if the user changed the value of checkbox1 then i  
>>> set
>> the attribute of checkbox2 via javascript to disabled=false.
>>>
>>> Example:
>>> <h:selectBooleanCheckbox id="checkbox1" onchange="var
>> element=document.getElementById('checkbox2'); if(element.disabled)  
>> element.disabled = false;
>> else element.disabled = true;">
>>>
>>> <h:selectBooleanCheckbox id="checkbox2" disabled="false"/>
>>>
>>> On the first it looks good, after the user has changed the value  
>>> of the
>> first checkbox, the second is now accessible via html.
>>> But it looks that the value is doesn't send in the request to the
>> server, like the normal behavior for an input element with  
>> disabled=true.
>>>
>>> It is not enough to set disabled=false in HTML to get the value of
>> checkbox2 to the server?
>>
>> Use "readonly" instead of "disabled". They appear the same to the  
>> user,
>> but browsers send the state of "readonly" HTML elements back to the  
>> server on
>> submit. Browsers ignore "disabled" HTML elements on submit, which is
>> causing the problem.
>>
>> Regards,
>> Simon
>
> -- 
> Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit al 
> len: http://www.gmx.net/de/go/multimessenger

Re: Input components with disabled=true

Posted by Lu...@gmx.de.
Hi Simon,

thanks for your hint to use readonly instead. I played now a little with it and the values are sent back to the server (they are listed in the requestParameterMap). But it looks like it is not possible to use an input component that are declared as readonly together with an valueChangeListener?

Example:

<h:inputText id="stringValue" value="#{property.stringValue}" valueChangeListener="#{bean.propertyValueChanged}" readonly="true"/>

The propertyValueChanged listener will never get invoked ... if this the normal behavior or maybe i do something wrong?

Before i submit the form, the field will set to input.readOnly = false; via javascript.

Thanks,
Luca

I use myfaces-1.1.6 with tomahawk-1.1.8 and facelets-1.1.14


-------- Original-Nachricht --------
> Datum: Fri, 16 Jan 2009 21:37:53 +0100
> Von: Simon Kitching <sk...@apache.org>
> An: MyFaces Discussion <us...@myfaces.apache.org>
> Betreff: Re: Input components with disabled=true

> On Thu, 2009-01-15 at 20:28 +0100, Luca Graf wrote:
> > Hello together,
> > 
> > I got an problem with input components like <h:selectBooleanCheckbox>
> when i use the attribute disabled=true. My scenario is that i have two
> checkboxes. The second is initially set to disabled=true. Now the user should
> only get access to the second if he changed the value of the first before. 
> > 
> > My approach was, if the user changed the value of checkbox1 then i set
> the attribute of checkbox2 via javascript to disabled=false.
> > 
> > Example:
> > <h:selectBooleanCheckbox id="checkbox1" onchange="var
> element=document.getElementById('checkbox2'); if(element.disabled) element.disabled = false;
> else element.disabled = true;">
> > 
> > <h:selectBooleanCheckbox id="checkbox2" disabled="false"/>
> > 
> > On the first it looks good, after the user has changed the value of the
> first checkbox, the second is now accessible via html.
> > But it looks that the value is doesn't send in the request to the
> server, like the normal behavior for an input element with disabled=true.
> > 
> > It is not enough to set disabled=false in HTML to get the value of
> checkbox2 to the server?
> 
> Use "readonly" instead of "disabled". They appear the same to the user,
> but browsers send the state of "readonly" HTML elements back to the server on
> submit. Browsers ignore "disabled" HTML elements on submit, which is
> causing the problem.
> 
> Regards,
> Simon

-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger

Re: Input components with disabled=true

Posted by Simon Kitching <sk...@apache.org>.
On Thu, 2009-01-15 at 20:28 +0100, Luca Graf wrote:
> Hello together,
> 
> I got an problem with input components like <h:selectBooleanCheckbox> when i use the attribute disabled=true. My scenario is that i have two checkboxes. The second is initially set to disabled=true. Now the user should only get access to the second if he changed the value of the first before. 
> 
> My approach was, if the user changed the value of checkbox1 then i set the attribute of checkbox2 via javascript to disabled=false.
> 
> Example:
> <h:selectBooleanCheckbox id="checkbox1" onchange="var element=document.getElementById('checkbox2'); if(element.disabled) element.disabled = false; else element.disabled = true;">
> 
> <h:selectBooleanCheckbox id="checkbox2" disabled="false"/>
> 
> On the first it looks good, after the user has changed the value of the first checkbox, the second is now accessible via html.
> But it looks that the value is doesn't send in the request to the server, like the normal behavior for an input element with disabled=true.
> 
> It is not enough to set disabled=false in HTML to get the value of checkbox2 to the server?

Use "readonly" instead of "disabled". They appear the same to the user, but browsers send the state of "readonly" HTML elements back to the server on submit. Browsers ignore "disabled" HTML elements on submit, which is causing the problem.

Regards,
Simon