You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by jammyjohn <jc...@yahoo.com> on 2010/06/23 01:42:21 UTC

Submitting a component value on a ajax call of a different component

Hi,

I have a dropdown box and a text field as below

 //dropdownbox
		final DropDownChoice typeOption=new DropDownChoice("type", dataList){			
			 protected boolean wantOnSelectionChangedNotifications() {
	                return true;
            }
		};

form.add(typeOption.setRequired(true).setOutputMarkupId(true));

 
//textfield

TextField nameTf = new TextField("name");
form.add(nameTf .setOutputMarkupId(true));
	
name.add(new AjaxFormComponentUpdatingBehavior("onBlur") {	        	
				@Override
				protected void onUpdate(AjaxRequestTarget target) {
								
					name.modelChanged();
					
	        		 target.addComponent(name);
	        	
	        		target.addComponent(feedbackPanel);
				}			
	        
		});

 How to submit a selected value from the drop down box to  the ajax behavior
of text component because the fields need to be updated based the selected
value from the dropdown.

Please suggest.

Thanks for your time.
J

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Submitting-a-component-value-on-a-ajax-call-of-a-different-component-tp2264940p2264940.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: Submitting a component value on a ajax call of a different component

Posted by jammyjohn <jc...@yahoo.com>.
Why is getCallbackScript(boolean onlyTargetActivePage) is not called in the
below code. I realized that it is not a @Override method. Not sure what is
wrong here....

Instead of using typeOption.add(new AbstractDefaultAjaxBehavior(), I also
tried using typeOption.add(new
AjaxFormComponentUpdatingBehavior("onchange"). the onUpdate method is
called, but not the getCallbackScript method..

Could anybody please help me?

Thanks,
J
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Submitting-a-component-value-on-a-ajax-call-of-a-different-component-tp2264940p2271345.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: Submitting a component value on a ajax call of a different component

Posted by jammyjohn <jc...@yahoo.com>.
Thank you so much for your reply. I tried using getCallbackScript on my
dropdown box. But it is never been called and also the fetch value on the
wicket side returns null for the dropdown box.
Not sure where I am doing wrong. Please suggest.
 
My code is as below..
/****************DropdownChoice**********/
final DropDownChoice<String> typeOption=new DropDownChoice<String>("type",
list){			
			private static final long serialVersionUID = 1L;
			@Override
			protected CharSequence getDefaultChoice(Object selected) {
				return "<option value=\"\">--</option>";
			}
			 protected boolean wantOnSelectionChangedNotifications() {
	                return true;
            }
		};	
		
		
	/*********adding to the form and setting outputmarkupid to true
		form.add(typeOption.setRequired(true).setOutputMarkupId(true));	

/****adding AbstractDefaultAjaxBehavior to the above dropdownchoice ****/

typeOption.add(new AbstractDefaultAjaxBehavior() {			
			
			private static final long serialVersionUID = 1L;
			@Override
			protected void respond(AjaxRequestTarget target) {
				// TODO Auto-generated method stub
				System.out.println("this is not getting printed");
				
			}
			@Override
			protected CharSequence getCallbackScript(boolean onlyTargetActivePage)
		     {
				System.out.println("not getting printed");
		         return generateCallbackScript("wicketAjaxGet('" +
		getCallbackUrl(onlyTargetActivePage) +
	
"&mawbTypeDataOptionValue='+$Wicket.$("+mawbTypeDataOption.getMarkupId()+").value"
+
		             ");");
		     }


	});



 final TextField<String> nameTf = new TextField<String>("name");       
       
form.add(nameTf.setConvertEmptyInputStringToNull(false).setOutputMarkupId(true));

//**************trying to access ddc value from onBlur of the
textfield**********/	
 nameTf.add(new AjaxEventBehavior("onBlur") {
        	private static final long serialVersionUID = 1L;
			@Override
			protected void onEvent(AjaxRequestTarget target) {
				nameTf.setModelObject("");				
				
				Request request = RequestCycle.get().getRequest();
			     String ddcValue = request.getParameter ("mawbTypeDataOptionValue");
			     System.out.println("this always prints null "++ddcValue);				
				
				nameTf .modelChanged();
        		
        		       target.addComponent(nameTf);
        		
        		      target.addComponent(feedbackPanel);
        		}
		
        });
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Submitting-a-component-value-on-a-ajax-call-of-a-different-component-tp2264940p2268754.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: Submitting a component value on a ajax call of a different component

Posted by Michael O'Cleirigh <mi...@rivulet.ca>.
Hello,

What you need to do is add a parameter to the url of the behaviour.  But 
the trick is that you don't attach a fixed string but rather an 
&otherFieldValue=' + 
document.getElementById(otherFieldComponentMarkupID).value which will 
use javascript to extract the current value of the referenced component 
when the ajax request is initiated.

Then inside the behaviour action you pull the request parameter value in 
and use it to update the model of the drop down box; then you can 
proceed normally.

Look at the AbstractDefaultAjaxBehaviour and this method:

     protected CharSequence getCallbackScript(boolean onlyTargetActivePage)
     {
         return generateCallbackScript("wicketAjaxGet('" + 
getCallbackUrl(onlyTargetActivePage) +
             "'");
     }

What you will want is something like this:

     protected CharSequence getCallbackScript(boolean onlyTargetActivePage)
     {
         return generateCallbackScript("wicketAjaxGet('" + 
getCallbackUrl(onlyTargetActivePage) + 
"&ddcValue='+$Wicket.$("+ddc.getMarkupId()+").value" +
             ");");
     }

Then in fetch the value in the wicket side:
@Override
protected void onEvent(final AjaxRequestTarget target) {
     Request request = RequestCycle.get().getRequest();

     String ddcValue = request.getParameter ("ddcValue");

     // convert the ddc value to into the proper model object

}

You also need to call ddc.setOutputMarkupID (true) since it will need to 
exist for javascript to find the element in the DOM.

Regards,

Mike

> Hi,
>
>   I am looking to submit the selected value from the dropdown to the server ,
> on the onblur of the textfield component. Is there a way to do it, though I
> have attached the AjaxFormComponentUpdatingBehavior to the textfield but not
> to the dropdown box.
>
> Appreciate your help in this regard.
>
> Thanks for your time.
> J.
>    


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


Re: Submitting a component value on a ajax call of a different component

Posted by jammyjohn <jc...@yahoo.com>.
Hi,

 I am looking to submit the selected value from the dropdown to the server ,
on the onblur of the textfield component. Is there a way to do it, though I
have attached the AjaxFormComponentUpdatingBehavior to the textfield but not
to the dropdown box.

Appreciate your help in this regard.

Thanks for your time.
J.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Submitting-a-component-value-on-a-ajax-call-of-a-different-component-tp2264940p2266036.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: Submitting a component value on a ajax call of a different component

Posted by vov <vo...@mail.ru>.
http://www.wicketstuff.org/wicket14/ajax/choice
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Submitting-a-component-value-on-a-ajax-call-of-a-different-component-tp2264940p2265189.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