|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
JQuery UI datepicker doesn't work in a struts 2 ajax pageDear all,
I'm using JQuery UI datepicker in my jsp page, here's the way I'm using: [code] <s:textfield name="parentAndChildren[%{#ind.index}].segmentList[%{#stat.index}].departureDate" size="7" cssClass="datepicker"/> <script type="text/javascript"> $(function() { $(".datepicker").datepicker({ changeMonth: true, changeYear: true, yearRange: '-5:+5', showOn: 'button', buttonImageOnly: true, buttonImage: 'images/calendar.gif' }); }); </script> [/code] It works fine if it's a new page. However, it doesn't work in an ajax page. Anyone can give me some hints? Thanks. Here's the info(from the same page) I found from firebug, it seems jquery doesn't do its work in the ajax part of the page. 1. ajax part(doesn't work) [code] <input id="segment_udpateSegmentList_parentAndChildren_0__segmentList_0__departureDate" class="datepicker" type="text" value="7/5/10" size="7" name="parentAndChildren[0].segmentList[0].departureDate"/> [/code] 2. static part(works) [code] <input id="segment_udpateSegmentList_parentAndChildren_1__segmentList_0__departureDate" class="datepicker hasDatepicker" type="text" value="12/10/09" size="7" name="parentAndChildren[1].segmentList[0].departureDate"/> [/code] |
|
|
Re: JQuery UI datepicker doesn't work in a struts 2 ajax pagedo you use the struts2 dojo tags for your ajax pages?
When yes try the parameter executeScripts="true" Best Regards Johannes Geppert
|
|
|
Re: JQuery UI datepicker doesn't work in a struts 2 ajax pageThanks Johannes, I'm using struts 2.0.11, this is my ajax submit tag:
<s:submit action="segment_udpateSegmentList" value="Update" theme="ajax" targets="%{'segment_edit_message'+#ind.index}" showLoadingText="false" indicator="%{'loadingImage'+#ind.index}" executeScripts="true" /> I just added executeScripts="true" to it but still doesn't work. Any other possibility may cause this problem?
|
|
|
Re: JQuery UI datepicker doesn't work in a struts 2 ajax pageWhen using jQuery via ajax you don¹t use jQuery¹s ready function, in you
case the $(function(){. You have two options. The simplest is to set a parameter (eg called ajaxRequest) in you action to true, when received via ajax and then change your javascript to have a s:if tag and if ajaxRequest is not true then include the $(function(){ line. For example you javascript block would look like: <script type="text/javascript"> > <s:if test=²%{!ajaxRequest}> > $(function() { > </s:if> > $(".datepicker").datepicker({ > changeMonth: true, > changeYear: true, > yearRange: '-5:+5', > showOn: 'button', buttonImageOnly: true, buttonImage: > 'images/calendar.gif' > }); > <s:if test=²%{!ajaxRequest}> > }); > </s:if> > </script> The option is to have either separate jsp pages or separate javascript blocks. > > > Dear all, > > I'm using JQuery UI datepicker in my jsp page, here's the way I'm using: > [code] > <s:textfield > name="parentAndChildren[%{#ind.index}].segmentList[%{#stat.index}].departureDa > te" > size="7" cssClass="datepicker"/> > > <script type="text/javascript"> > $(function() { > $(".datepicker").datepicker({ > changeMonth: true, > changeYear: true, > yearRange: '-5:+5', > showOn: 'button', buttonImageOnly: true, buttonImage: > 'images/calendar.gif' > }); > }); > </script> > [/code] > It works fine if it's a new page. However, it doesn't work in an ajax page. > Anyone can give me some hints? Thanks. > > Here's the info(from the same page) I found from firebug, it seems jquery > doesn't do its work in the ajax part of the page. > 1. ajax part(doesn't work) > [code] > <input > id="segment_udpateSegmentList_parentAndChildren_0__segmentList_0__departureDat > e" > class="datepicker" type="text" value="7/5/10" size="7" > name="parentAndChildren[0].segmentList[0].departureDate"/> > [/code] > > 2. static part(works) > [code] > <input > id="segment_udpateSegmentList_parentAndChildren_1__segmentList_0__departureDat > e" > class="datepicker hasDatepicker" type="text" value="12/10/09" size="7" > name="parentAndChildren[1].segmentList[0].departureDate"/> > > [/code] |
|
|
Re: JQuery UI datepicker doesn't work in a struts 2 ajax pageLong time ago I also have trouble to execute Scripts in AJAX Content.
http://old.nabble.com/-S2--No-JavaScript-in-TabbedPanel-to14772176.html#a14772176 So I switch to jQuery also for AJAX functions. Why do you mix Dojo and jQuery? You can use the build in Datepicker from dojo or switch to one of the two jQuery Plugins they exists for struts2. http://code.google.com/p/struts2-jquery/ or http://code.google.com/p/struts2-jquery-plugin/ Best Regards Johannes Geppert
|
|
|
Re: JQuery UI datepicker doesn't work in a struts 2 ajax pageThanks, I tried your method and it didn't work out.
I also tried to put all JQuery library and Javascript block in my ajax page(which is supposed to appear in the s:div). Still doesn't work. However, after adding executeScripts="true" in my <s:submit>, if I add "alert('test');" into my ajax page, I can see it works, which means Javascript works in my ajax page. Is it possible this is a JQuery issue?
|
|
|
Re: JQuery UI datepicker doesn't work in a struts 2 ajax pageThanks, Johannes, I tried the plugin of the second link but it didn't work out. It seems the plugin doesn't work for my struts 2.0.11.
The build in Datepicker from dojo doesn't work for me because I use <s:iterator>. segmentList[%{#stat.index}].departureDate can transfer value back(can't display value) while segmentList[#stat.index].departureDate can display value(can't transfer value back).
|
| Free embeddable forum powered by Nabble | Forum Help |