You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Grzel <gz...@yahoo.com> on 2008/02/07 16:57:47 UTC

Settings focus to window opened by javascript appended to AjaxLink

Hello,
I am using AjaxLink to open a new window using javascript.
The problem is that the focus is not set on the new window (it is opened but
stays behind, not visible to the user)

Code 
add(new AjaxLink("btn") {
	@Override
	public void onClick(AjaxRequestTarget target) {
	target.appendJavascript("generateReport('....params')");
}

The actual javascript 
function  generateReport(paramStr) {
	window.open('/portal/report?' + paramStr, 
'report','menubar=0,status=0,scrollbars =
1,resizable=1,width=640,height=480');
}

I tried changing javascript, using focus() method, nothing helped.
Seems like javascript is executed and then focus returned to 'calling page'
Any solution to this?
Thanks,


-- 
View this message in context: http://www.nabble.com/Settings-focus-to-window-opened-by-javascript-appended-to-AjaxLink-tp15336895p15336895.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Settings focus to window opened by javascript appended to AjaxLink

Posted by Christian Alejandro Marquez Grabia <ch...@gmail.com>.
You should try without the alert....it removes the focus when you click the
'Ok' button. Instead you should try something like: onfocus= "this.value =
'focused';"

Another method that can be used is select() instead of focus()

Rgds,
Christian

On 2/20/08, jeredm <je...@maplewoodsoftware.com> wrote:
>
>
> I am having a similar problem in IE, but it does not happen in Firefox.  I
> am
> popping up a modal dialog and want to set focus on the first text box in
> the
> modal when it is opened (id="focusMe").  Here is some code that has been
> trimmed for simplicity:
>
> HTML:
> <input id="focusMe" type="text" onfocus="alert('I have focus');"
> onblur="alert('I lost focus');" />
>
> JAVA:
>
> public void onClick(AjaxRequestTarget target){
>
>     modal.setContent(newPanel);
>     modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback(){
>         public void onClose(AjaxRequestTarget target){
>
>         }
>     });
>
>     modal.show(target);
>     target.appendJavascript("document.getElementById('focusMe').focus()");
> }
>
>
> I added an alert to the text box that tells me when it has focus and when
> it
> is lost.  I found that I see the focus message, but I do not see the
> cursor
> bar in the text box and nothing shows when I type.  Additionally, I do not
> see the blur message.  When I click in the text box after closing the
> focus
> alert there is no new alert.  This would indicate that IE thinks that the
> text box still has focus.  When I click out of the text box and then back
> into it the alerts and cursor both work as expected.  I ran this test in
> IE6
> and IE7 with the same results.
>
> Note that you will want to remove the onblur event for testing in Firefox
> as
> the alert itself will cause the text box to lose focus.
>
> --
> View this message in context:
> http://www.nabble.com/Settings-focus-to-window-opened-by-javascript-appended-to-AjaxLink-tp15336895p15602292.html
>
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Settings focus to window opened by javascript appended to AjaxLink

Posted by jeredm <je...@maplewoodsoftware.com>.
I am having a similar problem in IE, but it does not happen in Firefox.  I am
popping up a modal dialog and want to set focus on the first text box in the
modal when it is opened (id="focusMe").  Here is some code that has been
trimmed for simplicity:

HTML:
<input id="focusMe" type="text" onfocus="alert('I have focus');"
onblur="alert('I lost focus');" />

JAVA: 
public void onClick(AjaxRequestTarget target){
    modal.setContent(newPanel);
    modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback(){
        public void onClose(AjaxRequestTarget target){						

        }
    });		
		        
    modal.show(target);
    target.appendJavascript("document.getElementById('focusMe').focus()");
}


I added an alert to the text box that tells me when it has focus and when it
is lost.  I found that I see the focus message, but I do not see the cursor
bar in the text box and nothing shows when I type.  Additionally, I do not
see the blur message.  When I click in the text box after closing the focus
alert there is no new alert.  This would indicate that IE thinks that the
text box still has focus.  When I click out of the text box and then back
into it the alerts and cursor both work as expected.  I ran this test in IE6
and IE7 with the same results.

Note that you will want to remove the onblur event for testing in Firefox as
the alert itself will cause the text box to lose focus.
-- 
View this message in context: http://www.nabble.com/Settings-focus-to-window-opened-by-javascript-appended-to-AjaxLink-tp15336895p15602292.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Settings focus to window opened by javascript appended to AjaxLink

Posted by Igor Vaynberg <ig...@gmail.com>.
dont know, i think calling focus() on the window should work as long
as it is the last focus call that happens, not sure why it doesnt for
you

-igor


On Feb 8, 2008 6:50 AM, Grzel <gz...@yahoo.com> wrote:
>
> Thanks, I tried this already.
> It minimizes the window though.
> Is there any way to keep window displayed at the back, but allow popup
> (javascript generated) window to be displayed at front?
>
> I tried different javascript options with
> protected IAjaxCallDecorator getAjaxCallDecorator()
> {
>  return new AjaxCallDecorator()
>  {
>  private static final long serialVersionUID = 1L;
>
>  @Override
>  public CharSequence decorateScript(CharSequence script)
>  {
>   ...
>  }
> @Override
>  public CharSequence decorateOnSuccessScript(CharSequence script)
>  {
>   ...
>  }
>
>  @Override
>  public CharSequence decorateOnFailureScript(CharSequence script)
>  {
>  ..
> }
>
> };
>
> Nothing gave the results I was hoping for
> Thanks
>
>
>
>
> igor.vaynberg wrote:
> >
> > also try calling target.focuscomponent(null). by default target will
> > try to refocus the component that cause the ajax request.
> >
> > -igor
> >
> >
> > On Feb 7, 2008 7:57 AM, Grzel <gz...@yahoo.com> wrote:
> >>
> >> Hello,
> >> I am using AjaxLink to open a new window using javascript.
> >> The problem is that the focus is not set on the new window (it is opened
> >> but
> >> stays behind, not visible to the user)
> >>
> >> Code
> >> add(new AjaxLink("btn") {
> >>         @Override
> >>         public void onClick(AjaxRequestTarget target) {
> >>         target.appendJavascript("generateReport('....params')");
> >> }
> >>
> >> The actual javascript
> >> function  generateReport(paramStr) {
> >>         window.open('/portal/report?' + paramStr,
> >> 'report','menubar=0,status=0,scrollbars =
> >> 1,resizable=1,width=640,height=480');
> >> }
> >>
> >> I tried changing javascript, using focus() method, nothing helped.
> >> Seems like javascript is executed and then focus returned to 'calling
> >> page'
> >> Any solution to this?
> >> Thanks,
> >>
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Settings-focus-to-window-opened-by-javascript-appended-to-AjaxLink-tp15336895p15336895.html
> >> Sent from the Wicket - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Settings-focus-to-window-opened-by-javascript-appended-to-AjaxLink-tp15336895p15356494.html
>
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Settings focus to window opened by javascript appended to AjaxLink

Posted by Grzel <gz...@yahoo.com>.
Thanks, I tried this already.
It minimizes the window though.
Is there any way to keep window displayed at the back, but allow popup
(javascript generated) window to be displayed at front?

I tried different javascript options with
protected IAjaxCallDecorator getAjaxCallDecorator()
{
 return new AjaxCallDecorator()
 {
 private static final long serialVersionUID = 1L;
 
 @Override
 public CharSequence decorateScript(CharSequence script)
 {
  ...
 }
@Override
 public CharSequence decorateOnSuccessScript(CharSequence script)
 {
  ...
 }
 
 @Override
 public CharSequence decorateOnFailureScript(CharSequence script)
 {
 ..
}
 
};

Nothing gave the results I was hoping for
Thanks



igor.vaynberg wrote:
> 
> also try calling target.focuscomponent(null). by default target will
> try to refocus the component that cause the ajax request.
> 
> -igor
> 
> 
> On Feb 7, 2008 7:57 AM, Grzel <gz...@yahoo.com> wrote:
>>
>> Hello,
>> I am using AjaxLink to open a new window using javascript.
>> The problem is that the focus is not set on the new window (it is opened
>> but
>> stays behind, not visible to the user)
>>
>> Code
>> add(new AjaxLink("btn") {
>>         @Override
>>         public void onClick(AjaxRequestTarget target) {
>>         target.appendJavascript("generateReport('....params')");
>> }
>>
>> The actual javascript
>> function  generateReport(paramStr) {
>>         window.open('/portal/report?' + paramStr,
>> 'report','menubar=0,status=0,scrollbars =
>> 1,resizable=1,width=640,height=480');
>> }
>>
>> I tried changing javascript, using focus() method, nothing helped.
>> Seems like javascript is executed and then focus returned to 'calling
>> page'
>> Any solution to this?
>> Thanks,
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Settings-focus-to-window-opened-by-javascript-appended-to-AjaxLink-tp15336895p15336895.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Settings-focus-to-window-opened-by-javascript-appended-to-AjaxLink-tp15336895p15356494.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Settings focus to window opened by javascript appended to AjaxLink

Posted by Igor Vaynberg <ig...@gmail.com>.
also try calling target.focuscomponent(null). by default target will
try to refocus the component that cause the ajax request.

-igor


On Feb 7, 2008 7:57 AM, Grzel <gz...@yahoo.com> wrote:
>
> Hello,
> I am using AjaxLink to open a new window using javascript.
> The problem is that the focus is not set on the new window (it is opened but
> stays behind, not visible to the user)
>
> Code
> add(new AjaxLink("btn") {
>         @Override
>         public void onClick(AjaxRequestTarget target) {
>         target.appendJavascript("generateReport('....params')");
> }
>
> The actual javascript
> function  generateReport(paramStr) {
>         window.open('/portal/report?' + paramStr,
> 'report','menubar=0,status=0,scrollbars =
> 1,resizable=1,width=640,height=480');
> }
>
> I tried changing javascript, using focus() method, nothing helped.
> Seems like javascript is executed and then focus returned to 'calling page'
> Any solution to this?
> Thanks,
>
>
> --
> View this message in context: http://www.nabble.com/Settings-focus-to-window-opened-by-javascript-appended-to-AjaxLink-tp15336895p15336895.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org