You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by ken carlino <ke...@gmail.com> on 2006/10/29 19:28:39 UTC

Problem in marking an InputText to 'readonly' and 'disabled'

Hi,

I have page using inputText in myfaces. It works okay. But when I try
to mark the username field to either 'readonly' or 'disabled' equals
to 'true'.

Like this:
   <h:inputText value="#{userForm.user.username}" id="username"
required="true" styleClass="text large" readonly="true">
       <v:commonsValidator type="required" arg="#{text['user.username']}"/>
   </h:inputText>

the input field of the page in browser is not-changeable (as
expected).  But when i try to do a submit my form, I get this
error message 'This username (null) or e-mail address (null) already
exists. Please try a different username.'


Can you please tell why the username becomes 'null' when I try to
submit? If i remove the 'readonly='true'' the submit works (i.e. the
username is not null).


Thank you for any help.

Re: Problem in marking an InputText to 'readonly' and 'disabled'

Posted by Martin Marinschek <ma...@gmail.com>.
Hi guys,

this is our Input-decode code. Looks good to me...

I do suggest you look into  the scope of your model first: do you save
the model between requests? If not, the read-only model-data will be
lost on the next request; so you should either put your model to
session-scope or use t:saveState to save the property between
requests.

Regards,

Martin

    public static void decodeUIInput(FacesContext facesContext,
                                     UIComponent component) {
        if (!(component instanceof EditableValueHolder)) {
            throw new IllegalArgumentException("Component "
                + component.getClientId(facesContext)
                + " is not an EditableValueHolder");
        }
        Map paramMap = facesContext.getExternalContext()
            .getRequestParameterMap();
        String clientId = component.getClientId(facesContext);

        if (isDisabledOrReadOnly(component))
            return;

        if (paramMap.containsKey(clientId)) {
            ((EditableValueHolder) component).setSubmittedValue(paramMap
                .get(clientId));
        }
        else {
            log.warn(
                "There should always be a submitted value for an input if it"
                    + " is rendered, its form is submitted, and it is
not disabled"
                    + " or read-only. Component : " +
                    RendererUtils.getPathToComponent(component));
        }
    }

On 10/30/06, Andrew Robinson <an...@gmail.com> wrote:
> What I don't understand is why the server is looking for POST'ed
> values from the client for read-only and disabled controls. If the
> browser submits values for these, the server should ignore them.
> Otherwise it could be a large security problem if users could, using
> script, re-enable a control so that the value is submitted back to the
> server.
>
> The fact that the error is printed out seems like a bug to me. I would
> think that UIInput controls should not print any errors or do any work
> (no local or sumitted value processing) if the control is read-only or
> disabled.
>
> What does the spec. have to say about these two attributes?
>
> -Andrew
>
> On 10/29/06, Craig McClanahan <cr...@apache.org> wrote:
> >
> >
> > On 10/29/06, Simon Kitching <si...@rhe.co.nz> wrote:
> > >
> > > I don't know whether the behaviour you see with the normal one
> > > (required=true causes error for components when readonly=true) also
> > > applies to Sun's JSF implementation but I wouldn't be at all surprised.
> > > Web browsers don't send data back unless the field is editable, and if
> > > the JSF implementation (of any brand) doesn't see data for a required
> > > field then it has to complain.
> >
> > Actually, that hasn't been my experience.  Fields that are *disabled* will
> > not be included in the POST, but if a field is not disabled, but is
> > readonly, it should still be included.  (That's what the HTML spec requires,
> > too.)
> >
> > Craig
> >
> >
>


-- 

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Re: Problem in marking an InputText to 'readonly' and 'disabled'

Posted by Andrew Robinson <an...@gmail.com>.
What I don't understand is why the server is looking for POST'ed
values from the client for read-only and disabled controls. If the
browser submits values for these, the server should ignore them.
Otherwise it could be a large security problem if users could, using
script, re-enable a control so that the value is submitted back to the
server.

The fact that the error is printed out seems like a bug to me. I would
think that UIInput controls should not print any errors or do any work
(no local or sumitted value processing) if the control is read-only or
disabled.

What does the spec. have to say about these two attributes?

-Andrew

On 10/29/06, Craig McClanahan <cr...@apache.org> wrote:
>
>
> On 10/29/06, Simon Kitching <si...@rhe.co.nz> wrote:
> >
> > I don't know whether the behaviour you see with the normal one
> > (required=true causes error for components when readonly=true) also
> > applies to Sun's JSF implementation but I wouldn't be at all surprised.
> > Web browsers don't send data back unless the field is editable, and if
> > the JSF implementation (of any brand) doesn't see data for a required
> > field then it has to complain.
>
> Actually, that hasn't been my experience.  Fields that are *disabled* will
> not be included in the POST, but if a field is not disabled, but is
> readonly, it should still be included.  (That's what the HTML spec requires,
> too.)
>
> Craig
>
>

Re: Problem in marking an InputText to 'readonly' and 'disabled'

Posted by Craig McClanahan <cr...@apache.org>.
On 10/29/06, Simon Kitching <si...@rhe.co.nz> wrote:
>
>
> I don't know whether the behaviour you see with the normal one
> (required=true causes error for components when readonly=true) also
> applies to Sun's JSF implementation but I wouldn't be at all surprised.
> Web browsers don't send data back unless the field is editable, and if
> the JSF implementation (of any brand) doesn't see data for a required
> field then it has to complain.


Actually, that hasn't been my experience.  Fields that are *disabled* will
not be included in the POST, but if a field is not disabled, but is
readonly, it should still be included.  (That's what the HTML spec requires,
too.)

Craig

Re: Problem in marking an InputText to 'readonly' and 'disabled'

Posted by Simon Kitching <si...@rhe.co.nz>.
Hi Ken,

For info on myfaces/tomahawk tags go here:
    http://myfaces.apache.org/javadoc.html

Using the TLD(Tomahawk) link, you can info on the t:inputText component, 
which does have this attribute.

The attribute isn't on the standard h:inputText component, ie it's a 
tomahawk extension, available only if you use the t:inputText component 
instead of h:inputText (and include tomahawk in your classpath).

I don't know whether the behaviour you see with the normal one 
(required=true causes error for components when readonly=true) also 
applies to Sun's JSF implementation but I wouldn't be at all surprised.
Web browsers don't send data back unless the field is editable, and if 
the JSF implementation (of any brand) doesn't see data for a required 
field then it has to complain.

Maybe a JSF impl could work around this by putting the values of 
readonly fields into hidden input fields instead so they *are* present 
on postback but AFAIK MyFaces doesn't do that (and I'm not sure whether 
there are other problems that would be caused by that).

It seems to me that your options are:
(a) Remove the "required=true" attribute from the input field and 
instead implement the check in your action methods.
(b) use t:inputText and disabledOnClientSide=true

Regards,

Simon

ken carlino wrote:
> I am looking at this documentation,
> http://java.sun.com/javaee/javaserverfaces/1.1_01/docs/renderkitdocs/HTML_BASIC/javax.faces.Inputjavax.faces.Text.html 
>
>
> I don't see it has the '"disabledOnClientSide" attribute.
>
> Thanks.
>
> On 10/29/06, ken carlino <ke...@gmail.com> wrote:
>> Thanks.  Is this '"disabledOnClientSide" a JSF standard attribute (JSF
>> 1.0? 1.1?) ?
>> or it is a myfaces extension?
>>
>> I can't find any documentation about that.
>>
>>  Thanks for any help.
>>
>> On 10/29/06, Gerald Müllan <bi...@gmail.com> wrote:
>> > Hi,
>> >
>> > this is because the value is not posted back to server and it is
>> > ignored by the browser when submiting the form.
>> >
>> > But you can use t:inputText in combination with the attribute
>> > "disabledOnClientSide" which should be set to true.
>> >
>> > This makes sure that the value will be pushed to the form.
>> >
>> > regards,
>> >
>> > Gerald
>> >
>> > On 10/29/06, ken carlino <ke...@gmail.com> wrote:
>> > > Hi,
>> > >
>> > > I have page using inputText in myfaces. It works okay. But when I 
>> try
>> > > to mark the username field to either 'readonly' or 'disabled' equals
>> > > to 'true'.
>> > >
>> > > Like this:
>> > >    <h:inputText value="#{userForm.user.username}" id="username"
>> > > required="true" styleClass="text large" readonly="true">
>> > >        <v:commonsValidator type="required" 
>> arg="#{text['user.username']}"/>
>> > >    </h:inputText>
>> > >
>> > > the input field of the page in browser is not-changeable (as
>> > > expected).  But when i try to do a submit my form, I get this
>> > > error message 'This username (null) or e-mail address (null) already
>> > > exists. Please try a different username.'
>> > >
>> > >
>> > > Can you please tell why the username becomes 'null' when I try to
>> > > submit? If i remove the 'readonly='true'' the submit works (i.e. the
>> > > username is not null).


Re: Problem in marking an InputText to 'readonly' and 'disabled'

Posted by ken carlino <ke...@gmail.com>.
I am looking at this documentation,
http://java.sun.com/javaee/javaserverfaces/1.1_01/docs/renderkitdocs/HTML_BASIC/javax.faces.Inputjavax.faces.Text.html

I don't see it has the '"disabledOnClientSide" attribute.

Thanks.

On 10/29/06, ken carlino <ke...@gmail.com> wrote:
> Thanks.  Is this '"disabledOnClientSide" a JSF standard attribute (JSF
> 1.0? 1.1?) ?
> or it is a myfaces extension?
>
> I can't find any documentation about that.
>
>  Thanks for any help.
>
> On 10/29/06, Gerald Müllan <bi...@gmail.com> wrote:
> > Hi,
> >
> > this is because the value is not posted back to server and it is
> > ignored by the browser when submiting the form.
> >
> > But you can use t:inputText in combination with the attribute
> > "disabledOnClientSide" which should be set to true.
> >
> > This makes sure that the value will be pushed to the form.
> >
> > regards,
> >
> > Gerald
> >
> > On 10/29/06, ken carlino <ke...@gmail.com> wrote:
> > > Hi,
> > >
> > > I have page using inputText in myfaces. It works okay. But when I try
> > > to mark the username field to either 'readonly' or 'disabled' equals
> > > to 'true'.
> > >
> > > Like this:
> > >    <h:inputText value="#{userForm.user.username}" id="username"
> > > required="true" styleClass="text large" readonly="true">
> > >        <v:commonsValidator type="required" arg="#{text['user.username']}"/>
> > >    </h:inputText>
> > >
> > > the input field of the page in browser is not-changeable (as
> > > expected).  But when i try to do a submit my form, I get this
> > > error message 'This username (null) or e-mail address (null) already
> > > exists. Please try a different username.'
> > >
> > >
> > > Can you please tell why the username becomes 'null' when I try to
> > > submit? If i remove the 'readonly='true'' the submit works (i.e. the
> > > username is not null).
> > >
> > >
> > > Thank you for any help.
> > >
> >
> >
> > --
> > http://www.irian.at
> >
> > Your JSF powerhouse -
> > JSF Consulting, Development and
> > Courses in English and German
> >
> > Professional Support for Apache MyFaces
> >
>

Re: Problem in marking an InputText to 'readonly' and 'disabled'

Posted by ken carlino <ke...@gmail.com>.
Thanks.  Is this '"disabledOnClientSide" a JSF standard attribute (JSF
1.0? 1.1?) ?
or it is a myfaces extension?

I can't find any documentation about that.

 Thanks for any help.

On 10/29/06, Gerald Müllan <bi...@gmail.com> wrote:
> Hi,
>
> this is because the value is not posted back to server and it is
> ignored by the browser when submiting the form.
>
> But you can use t:inputText in combination with the attribute
> "disabledOnClientSide" which should be set to true.
>
> This makes sure that the value will be pushed to the form.
>
> regards,
>
> Gerald
>
> On 10/29/06, ken carlino <ke...@gmail.com> wrote:
> > Hi,
> >
> > I have page using inputText in myfaces. It works okay. But when I try
> > to mark the username field to either 'readonly' or 'disabled' equals
> > to 'true'.
> >
> > Like this:
> >    <h:inputText value="#{userForm.user.username}" id="username"
> > required="true" styleClass="text large" readonly="true">
> >        <v:commonsValidator type="required" arg="#{text['user.username']}"/>
> >    </h:inputText>
> >
> > the input field of the page in browser is not-changeable (as
> > expected).  But when i try to do a submit my form, I get this
> > error message 'This username (null) or e-mail address (null) already
> > exists. Please try a different username.'
> >
> >
> > Can you please tell why the username becomes 'null' when I try to
> > submit? If i remove the 'readonly='true'' the submit works (i.e. the
> > username is not null).
> >
> >
> > Thank you for any help.
> >
>
>
> --
> http://www.irian.at
>
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>

Re: Problem in marking an InputText to 'readonly' and 'disabled'

Posted by Gerald Müllan <bi...@gmail.com>.
Hi,

this is because the value is not posted back to server and it is
ignored by the browser when submiting the form.

But you can use t:inputText in combination with the attribute
"disabledOnClientSide" which should be set to true.

This makes sure that the value will be pushed to the form.

regards,

Gerald

On 10/29/06, ken carlino <ke...@gmail.com> wrote:
> Hi,
>
> I have page using inputText in myfaces. It works okay. But when I try
> to mark the username field to either 'readonly' or 'disabled' equals
> to 'true'.
>
> Like this:
>    <h:inputText value="#{userForm.user.username}" id="username"
> required="true" styleClass="text large" readonly="true">
>        <v:commonsValidator type="required" arg="#{text['user.username']}"/>
>    </h:inputText>
>
> the input field of the page in browser is not-changeable (as
> expected).  But when i try to do a submit my form, I get this
> error message 'This username (null) or e-mail address (null) already
> exists. Please try a different username.'
>
>
> Can you please tell why the username becomes 'null' when I try to
> submit? If i remove the 'readonly='true'' the submit works (i.e. the
> username is not null).
>
>
> Thank you for any help.
>


-- 
http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces