You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Iamuser <su...@gmail.com> on 2016/10/12 15:07:17 UTC

AjaxLink cannot see updated model values

Hi,

I have a form backed by a model.
In this form I have and editable textfield and a image.

When clicking on the image I just need to write the value inserted in the
textfield to the console.

However, it does never display the updated value in the textfield.

Here is the html:
<img src="images/test.gif" name="btnSave" /> <#>  

Here is the Java code:

AjaxLink<MyBean> testLink = new AjaxLink<MyBean>("testLink", getModel())
			{
				/**
				 * 
				 */
				private static final long serialVersionUID = 1L;

				@Override
				public void onClick(AjaxRequestTarget target) {
					System.out.println("test link 1" + getModelObject().getName());
				}
			};

Could you please tell me a solution?

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxLink-cannot-see-updated-model-values-tp4675743.html
Sent from the Users forum 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: AjaxLink cannot see updated model values

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

AjaxLink uses AjaxEventBehavior behind the scenes. This behavior doesn't
send any parameters with the request.
You need something like AjaxFormComponentUpdatingBehavior to send form
elements' value to the server or use dynamic extra parameters by overriding
#updateAjaxAttributes().

P.S. Please subscribe to the mailing lists. You ask questions often and all
this moderation just slows down the delivery. Also the code snippets are
not sent by Nabble.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Wed, Oct 12, 2016 at 5:07 PM, Iamuser <su...@gmail.com> wrote:

> Hi,
>
> I have a form backed by a model.
> In this form I have and editable textfield and a image.
>
> When clicking on the image I just need to write the value inserted in the
> textfield to the console.
>
> However, it does never display the updated value in the textfield.
>
> Here is the html:
> <img src="images/test.gif" name="btnSave" /> <#>
>
> Here is the Java code:
>
> AjaxLink<MyBean> testLink = new AjaxLink<MyBean>("testLink", getModel())
>                         {
>                                 /**
>                                  *
>                                  */
>                                 private static final long serialVersionUID
> = 1L;
>
>                                 @Override
>                                 public void onClick(AjaxRequestTarget
> target) {
>                                         System.out.println("test link 1" +
> getModelObject().getName());
>                                 }
>                         };
>
> Could you please tell me a solution?
>
> --
> View this message in context: http://apache-wicket.1842946.
> n4.nabble.com/AjaxLink-cannot-see-updated-model-values-tp4675743.html
> Sent from the Users forum 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: AjaxLink cannot see updated model values

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
make

TextField<String> txtName

a field. Call txtName.setOutputMarkupId(true) and add it to the ART on on
click

On Thu, Oct 13, 2016 at 3:38 PM, Iamuser <su...@gmail.com> wrote:

> Hello,
>
> Yes, adding the behavoiur AjaxFormComponentUpdatingBehavior on the text
> field, solved the issue.
>
> Thank you for solution.
>
> Now I'm facing following situation.
> When another link is clicked I need to clear the input fields (so my
> textfield).
>
> I have the following added, but the form just doesn't get cleared.
> The model is empty, but the page still remains with the text, even after
> page refresh.
> Could you please advise?
>
>
> AjaxLink<TestBean> clearLink = new AjaxLink<TestBean>("clearLink", model)
>                                 {
>                                         /**
>                                          *
>                                          */
>                                         private static final long
> serialVersionUID = 1L;
>
>                                         @Override
>                                         public void
> onClick(AjaxRequestTarget target) {
>                                                 model.setObject(new
> TestBean());
>                                                 TestForm.this.clearInput();
>                                         }
>
>                                 };
>
>                                         add(clearLink);
>
> PS: I hope I have subscribed to the mailing list. I have sent an email to
> users-allow-subscribe
>
>
> Thank you
>
>
> --
> View this message in context: http://apache-wicket.1842946.
> n4.nabble.com/AjaxLink-cannot-see-updated-model-values-
> tp4675743p4675761.html
> Sent from the Users forum 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
>
>


-- 
Regards - Ernesto Reinaldo Barreiro

Re: AjaxLink cannot see updated model values

Posted by Iamuser <su...@gmail.com>.
I have added
txtName.setOutputMarkupId(true);
and
target.add(TestForm.this);

But it is still not working.

txtName.setOutputMarkupId(true);
AjaxLink<TestBean> clearLink = new AjaxLink<TestBean>("clearLink", model)
{
/**
*
*/
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
model.setObject(new TestBean());
TestForm.this.clearInput();
target.add(TestForm.this);
}

};

On Thu, Oct 13, 2016 at 4:52 PM, Martin Grigorov-4 [via Apache Wicket] <
ml-node+s1842946n4675763h87@n4.nabble.com> wrote:

> On Thu, Oct 13, 2016 at 3:38 PM, Iamuser <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=4675763&i=0>> wrote:
>
> > Hello,
> >
> > Yes, adding the behavoiur AjaxFormComponentUpdatingBehavior on the text
> > field, solved the issue.
> >
> > Thank you for solution.
> >
> > Now I'm facing following situation.
> > When another link is clicked I need to clear the input fields (so my
> > textfield).
> >
> > I have the following added, but the form just doesn't get cleared.
> > The model is empty, but the page still remains with the text, even after
> > page refresh.
> > Could you please advise?
> >
> >
> > AjaxLink<TestBean> clearLink = new AjaxLink<TestBean>("clearLink",
> model)
> >                                 {
> >                                         /**
> >                                          *
> >                                          */
> >                                         private static final long
> > serialVersionUID = 1L;
> >
> >                                         @Override
> >                                         public void
> > onClick(AjaxRequestTarget target) {
> >                                                 model.setObject(new
> > TestBean());
> >
> TestForm.this.clearInput();
> >
>
> target.add(TestForm.this);
>
>
> >                                         }
> >
> >                                 };
> >
> >                                         add(clearLink);
> >
> > PS: I hope I have subscribed to the mailing list. I have sent an email
> to
> > users-allow-subscribe
> >
>
> http://wicket.apache.org/help/email.html#user
> Follow the links.
> Once subscribed just send messages to [hidden email]
> <http:///user/SendEmail.jtp?type=node&node=4675763&i=1>. Do not use
> Nabble!
>
>
> >
> >
> > Thank you
> >
> >
> > --
> > View this message in context: http://apache-wicket.1842946.
> > n4.nabble.com/AjaxLink-cannot-see-updated-model-values-
> > tp4675743p4675761.html
> > Sent from the Users forum mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> <http:///user/SendEmail.jtp?type=node&node=4675763&i=2>
> > For additional commands, e-mail: [hidden email]
> <http:///user/SendEmail.jtp?type=node&node=4675763&i=3>
> >
> >
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://apache-wicket.1842946.n4.nabble.com/AjaxLink-cannot-
> see-updated-model-values-tp4675743p4675763.html
> To unsubscribe from AjaxLink cannot see updated model values, click here
> <http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4675743&code=c3VwZXJiaXNzaW1hQGdtYWlsLmNvbXw0Njc1NzQzfC01MzM2MjU4NzI=>
> .
> NAML
> <http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxLink-cannot-see-updated-model-values-tp4675743p4675764.html
Sent from the Users forum 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: AjaxLink cannot see updated model values

Posted by Martin Grigorov <mg...@apache.org>.
On Thu, Oct 13, 2016 at 3:38 PM, Iamuser <su...@gmail.com> wrote:

> Hello,
>
> Yes, adding the behavoiur AjaxFormComponentUpdatingBehavior on the text
> field, solved the issue.
>
> Thank you for solution.
>
> Now I'm facing following situation.
> When another link is clicked I need to clear the input fields (so my
> textfield).
>
> I have the following added, but the form just doesn't get cleared.
> The model is empty, but the page still remains with the text, even after
> page refresh.
> Could you please advise?
>
>
> AjaxLink<TestBean> clearLink = new AjaxLink<TestBean>("clearLink", model)
>                                 {
>                                         /**
>                                          *
>                                          */
>                                         private static final long
> serialVersionUID = 1L;
>
>                                         @Override
>                                         public void
> onClick(AjaxRequestTarget target) {
>                                                 model.setObject(new
> TestBean());
>                                                 TestForm.this.clearInput();
>

target.add(TestForm.this);


>                                         }
>
>                                 };
>
>                                         add(clearLink);
>
> PS: I hope I have subscribed to the mailing list. I have sent an email to
> users-allow-subscribe
>

http://wicket.apache.org/help/email.html#user
Follow the links.
Once subscribed just send messages to users@wicket.apache.org. Do not use
Nabble!


>
>
> Thank you
>
>
> --
> View this message in context: http://apache-wicket.1842946.
> n4.nabble.com/AjaxLink-cannot-see-updated-model-values-
> tp4675743p4675761.html
> Sent from the Users forum 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: AjaxLink cannot see updated model values

Posted by Iamuser <su...@gmail.com>.
Hello,

Yes, adding the behavoiur AjaxFormComponentUpdatingBehavior on the text
field, solved the issue.

Thank you for solution.

Now I'm facing following situation.
When another link is clicked I need to clear the input fields (so my
textfield).

I have the following added, but the form just doesn't get cleared. 
The model is empty, but the page still remains with the text, even after
page refresh.
Could you please advise?


AjaxLink<TestBean> clearLink = new AjaxLink<TestBean>("clearLink", model)
				{
					/**
					 * 
					 */
					private static final long serialVersionUID = 1L;

					@Override
					public void onClick(AjaxRequestTarget target) {
						model.setObject(new TestBean());
						TestForm.this.clearInput();
					}

				};
				
					add(clearLink);

PS: I hope I have subscribed to the mailing list. I have sent an email to 
users-allow-subscribe


Thank you


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxLink-cannot-see-updated-model-values-tp4675743p4675761.html
Sent from the Users forum 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: AjaxLink cannot see updated model values

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
Read Martin's comment: you are not submitting the form.

On Wed, Oct 12, 2016 at 5:33 PM, Iamuser <su...@gmail.com> wrote:

> Hello,
>
> Yes, it is dynamic.
>
> Here is the complete code (html and java):
>
> ==My test bean==
>
> public class TestBean implements Serializable{
>
>         /**
>          *
>          */
>         private static final long serialVersionUID = 1L;
>
>
>         private String name;
>         private String code;
>         private Integer id;
>         public String getName() {
>                 return name;
>         }
>         public void setName(String name) {
>                 this.name = name;
>         }
>         public String getCode() {
>                 return code;
>         }
>         public void setCode(String code) {
>                 this.code = code;
>         }
>         public Integer getId() {
>                 return id;
>         }
>         public void setId(Integer id) {
>                 this.id = id;
>         }
>
> }
>
> ==HTML page==
>
> <!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; >
> <html xmlns="http://www.w3.org/1999/xhtml"
> xmlns:wicket="http://wicket.apache.org/" lang="en" xml:lang="en">
> <body>
> <wicket:extend>
>         <form wicket:id="testForm">
>
>
>
>
>                                         Name:
>
>                                         <input wicket:id="txtName"
> size="80"/>
>
>
>
>
>
>                                          <img src="images/lupa.gif"
> name="btnSave" /> <#>
>
>
>
>
>         </form>
> </wicket:extend>
> </body>
> </html>
>
> ==JAVA code==
> public class TestPage extends Page {
>
>         private static final long serialVersionUID = 311508940740808005L;
>         private static final Logger logger = LogManager.getLogger(TestPage.
> class);
>         private ReturnObjectPage returnPage = null;
>
>         public TestPage(IModel<TestBean> model, final ReturnObjectPage
> returnPage)
> {
>                 super(model);
>                 this.returnPage = returnPage;
>
>                 add(new TestForm("testForm", model));
>
>         }
>
>         class TestForm extends Form<TestBean> {
>                 /**
>                  *
>                  */
>                 private static final long serialVersionUID = 1L;
>
>                 public TestForm(String id, IModel<TestBean> model) {
>                 super(id, model);
>
>                 TextField<String> txtName = new
> TextField<String>("txtName", new
> PropertyModel<String>(getDefaultModel(), "name"));
>                 add(txtName);
>
>                 AjaxLink<TestBean> testLink = new
> AjaxLink<TestBean>("testLink",
> getModel())
>                 {
>                         /**
>                          *
>                          */
>                         private static final long serialVersionUID = 1L;
>
>                         @Override
>                         public void onClick(AjaxRequestTarget target) {
>                                         System.out.println("ajax in");
>                                         System.out.println("test name= " +
> getModelObject().getName());
>                         }
>
>                 };
>
>                         add(testLink);
>                 }
>                 }
>
>
> }
>
> --
> View this message in context: http://apache-wicket.1842946.
> n4.nabble.com/AjaxLink-cannot-see-updated-model-values-
> tp4675743p4675746.html
> Sent from the Users forum 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
>
>


-- 
Regards - Ernesto Reinaldo Barreiro

Re: AjaxLink cannot see updated model values

Posted by Iamuser <su...@gmail.com>.
Hello,

Yes, it is dynamic.

Here is the complete code (html and java):

==My test bean==

public class TestBean implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	
	private String name;
	private String code;
	private Integer id;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}

}

==HTML page==

<!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; >
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:wicket="http://wicket.apache.org/" lang="en" xml:lang="en">
<body>
<wicket:extend>
	<form wicket:id="testForm">
		

			

					Name:
					
					<input wicket:id="txtName" size="80"/>
				
			
			

					
					 <img src="images/lupa.gif" name="btnSave" /> <#>  
				
			
		

	</form>
</wicket:extend>
</body>
</html>

==JAVA code==
public class TestPage extends Page {

	private static final long serialVersionUID = 311508940740808005L;
	private static final Logger logger = LogManager.getLogger(TestPage.class);
	private ReturnObjectPage returnPage = null;

	public TestPage(IModel<TestBean> model, final ReturnObjectPage returnPage)
{
		super(model);
		this.returnPage = returnPage;

		add(new TestForm("testForm", model));

	}

	class TestForm extends Form<TestBean> {
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		public TestForm(String id, IModel<TestBean> model) {
		super(id, model);
		
		TextField<String> txtName = new TextField<String>("txtName", new
PropertyModel<String>(getDefaultModel(), "name"));
		add(txtName);
		
		AjaxLink<TestBean> testLink = new AjaxLink<TestBean>("testLink",
getModel())
		{
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void onClick(AjaxRequestTarget target) {
					System.out.println("ajax in");
					System.out.println("test name= " + getModelObject().getName());
			}

		};
		
			add(testLink);
		}
		}
	

}

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxLink-cannot-see-updated-model-values-tp4675743p4675746.html
Sent from the Users forum 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: AjaxLink cannot see updated model values

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
if you model dynamic?

On Wed, Oct 12, 2016 at 5:07 PM, Iamuser <su...@gmail.com> wrote:

> Hi,
>
> I have a form backed by a model.
> In this form I have and editable textfield and a image.
>
> When clicking on the image I just need to write the value inserted in the
> textfield to the console.
>
> However, it does never display the updated value in the textfield.
>
> Here is the html:
> <img src="images/test.gif" name="btnSave" /> <#>
>
> Here is the Java code:
>
> AjaxLink<MyBean> testLink = new AjaxLink<MyBean>("testLink", getModel())
>                         {
>                                 /**
>                                  *
>                                  */
>                                 private static final long serialVersionUID
> = 1L;
>
>                                 @Override
>                                 public void onClick(AjaxRequestTarget
> target) {
>                                         System.out.println("test link 1" +
> getModelObject().getName());
>                                 }
>                         };
>
> Could you please tell me a solution?
>
> --
> View this message in context: http://apache-wicket.1842946.
> n4.nabble.com/AjaxLink-cannot-see-updated-model-values-tp4675743.html
> Sent from the Users forum 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
>
>


-- 
Regards - Ernesto Reinaldo Barreiro