We help IT Professionals succeed at work.

jquery binding to jsp nested:text

mmoore
mmoore asked
on
I have the following JSP:
<nested:text readonly="true" styleClass="normalText" property="date" size="12" />
and the following JQUERY (this is just something I copied, ultimately all I want is a simple datepicker on a simple text field)
   $( document ).ready(function() {
        $.datepicker.setDefaults(
                $.extend($.datepicker.regional[''])
            );
            $('#datepicker_open').click(function(){
                $('#datepicker').datepicker(
                    'dialog',
                    '28.05.2013',
                    function(){
                        alert('Event onSelect');
                    },
                    { showButtonPanel: true }
                );
            });
    });

I tried to do this:
<nested:text readonly="true" styleClass="normalText" property="date" size="12" id="datepicker" />
but JSP processer rejects the "id" attribute.
Thanks,
Mike
Comment
Watch Question

Top Expert 2015
Commented:
Try using the styleId attribute instead e.g.
<nested:text readonly="true" styleClass="normalText" property="date" size="12" styleId="datepicker" />

Open in new window

Author

Commented:
Well, that works but I don't know why. I'm just learning jquery and I thought #datepicker would only bind to the id attribute. Apparently not. Thanks!

Author

Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for mmoore's comment #a40683392

for the following reason:

Solution worked. Would have been nice to have an explanation of why it works, but I guess I can figure that out on my own.

Author

Commented:
It worked!
Top Expert 2015

Commented:
Well, that works but I don't know why. I'm just learning jquery and I thought #datepicker would only bind to the id attribute. Apparently not. Thanks!

It is binding to the Id attribute. If you view the HTML source you will see the text field with the id attribute.

If you look at the API documentation for the text tag in the nested taglib you will see that it extends the <html:text> tag.
The <html:text> tag happens to have a styleId attribute which corresponds to the html id attribute.

I can't seem to find the documentation for the <html:text> tag, this would have shown you the definition of the styleId attribute.

Author

Commented:
Great! Thanks for making the extra effort. Regards,
Mike