You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by HugoSilva <al...@gmail.com> on 2012/01/03 14:46:16 UTC

Altering TextField content from within AbstractDefaultAjaxBehavior

Hello guys,

I'm new to Wicket and working with it's version 1.4.9.
I'm developing some portlets using wicket for LifeRay and sometimes using
it's infrastructure to make inter portlets communication.
I have a product list portlet (which only lists the products - I will call
it portlet A) and a product creation/altering portlet which I will call
portlet B from now on.
When the user wants to alter a produtct, he clicks in the product in the
portlet A and the product ID is sent to the portlet B via JavaScript using
LifeRay's infrastructure.

In the portlet B, I have a wicket page (extends WebPage) that in its
constructor adds an AbstractDefaultAjaxBehavior just like the following:


		final AbstractDefaultAjaxBehavior editMessageReceiver = new
AbstractDefaultAjaxBehavior() {

			@Override
			public void renderHead(IHeaderResponse response) {
				super.renderHead(response);
				
                                //LifeRay's stuff
				String strJS = "Liferay.on( "+
					   "'alteracao_imovel', "+
					   "function(event, data) { "+
					     "var imovelId = data; "+
					     "if (imovelId) {"+
					       "jQuery.ajax( { "+
				           "url: '" + getCallbackUrl() +"', "+ // call back url
				           "data: { imovelId: imovelId }} "+ //product id					         
				           "); " +
					     "} "+
					   "} "+
					 ");";	
				
				response.renderJavascript(strJS, null);
			}

			@Override
			protected void respond(AjaxRequestTarget target) {
				//recover the product id
				String imovelId =
RequestCycle.get().getRequest().getParameter("imovelId"); 
				
				// retrieve the product from the database
				produto = recuperaProdutoDetalhadoPorId(Long.valueOf(imovelId)); 
				
				//TextField in which the product name suppose to go
				TextField apres =
(TextField)target.getPage().get("formManterImovel:apresentacao");
				apres.setModelObject(produto.getNome());
				apres.modelChanged();
				target.addComponent(apres);
			}
		};
		add(editMessageReceiver);

Note that in the renderHead method, I add a LifeRays specifc JavaScript
which listens to a message channel. When a message is get from the channel,
the JavaScript calls the getCallBack() url passing the product id as a
parameter.

In the respond(AjaxRequestTarget target) method, I get the product id from
the request and retrieve the product from the database to put its name in a
TextField and show it again in the portlet B now with the products name. So
far, so good.

The problem is that the text field is not being repainted and ramains empty
(without the products name in it).

I observed that in the AjaxRequestTarget respond(final RequestCycle
requestCycle) method, the response object carries the following message:

<?xml version="1.0" encoding="UTF-8"?>
<ajax-response>
    <component id="txtApresentacaoId" >
    <[CDATA[<input name="apresentacao" type="text" style="width: 98%;
padding-left: 5px" title="Texto de apresentação do imóvel" 
        value="Apartamento em localização privilegiada e ótimo acabamento"
id="txtApresentacaoId"/>]]>
    </component>
</ajax-response>

Which have the product desired name in it. But, at the end of the request,
the TextField is not being rendered!

In this same portlet (portlet B) I have a combobox that changes lots of
TextFields value through AjaxFormComponentUpdatingBehavior when the user
changes its value. All of them are rendered again in the portlet as
expected!

So I dont think its a LifeRay problem at all.

Do you guys have an idea of what is happening?

thanks a lot

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Altering-TextField-content-from-within-AbstractDefaultAjaxBehavior-tp4256806p4256806.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: Altering TextField content from within AbstractDefaultAjaxBehavior

Posted by HugoSilva <al...@gmail.com>.
I solved the issue

Instead of a direct call to jQuery.ajax(), I called wicketAjaxGet()
function.
I think that wicket has to do some stuff beforehand and when you call
wicketAjaxGet() it is "forced" to do it.

Thanks a lot

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Altering-TextField-content-from-within-AbstractDefaultAjaxBehavior-tp4256806p4258080.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: Altering TextField content from within AbstractDefaultAjaxBehavior

Posted by HugoSilva <al...@gmail.com>.
Thank you Martin,

I have just done what you said. It doesnt show anything in the debug window.
It remains blank!
By the other hand, when a change the combo box value it shows the ajax
command!

It means that the command is not being executed, right?
Is there something that I can do to "force" its execution?

Thanks

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Altering-TextField-content-from-within-AbstractDefaultAjaxBehavior-tp4256806p4257762.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: Altering TextField content from within AbstractDefaultAjaxBehavior

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

Take a look at Wicket Ajax Debug window. Maybe there is some
JavaScript error during the replacement of the DOM node for this
textfield.
Otherwise all looks OK to me.

On Tue, Jan 3, 2012 at 3:46 PM, HugoSilva <al...@gmail.com> wrote:
> Hello guys,
>
> I'm new to Wicket and working with it's version 1.4.9.
> I'm developing some portlets using wicket for LifeRay and sometimes using
> it's infrastructure to make inter portlets communication.
> I have a product list portlet (which only lists the products - I will call
> it portlet A) and a product creation/altering portlet which I will call
> portlet B from now on.
> When the user wants to alter a produtct, he clicks in the product in the
> portlet A and the product ID is sent to the portlet B via JavaScript using
> LifeRay's infrastructure.
>
> In the portlet B, I have a wicket page (extends WebPage) that in its
> constructor adds an AbstractDefaultAjaxBehavior just like the following:
>
>
>                final AbstractDefaultAjaxBehavior editMessageReceiver = new
> AbstractDefaultAjaxBehavior() {
>
>                        @Override
>                        public void renderHead(IHeaderResponse response) {
>                                super.renderHead(response);
>
>                                //LifeRay's stuff
>                                String strJS = "Liferay.on( "+
>                                           "'alteracao_imovel', "+
>                                           "function(event, data) { "+
>                                             "var imovelId = data; "+
>                                             "if (imovelId) {"+
>                                               "jQuery.ajax( { "+
>                                           "url: '" + getCallbackUrl() +"', "+ // call back url
>                                           "data: { imovelId: imovelId }} "+ //product id
>                                           "); " +
>                                             "} "+
>                                           "} "+
>                                         ");";
>
>                                response.renderJavascript(strJS, null);
>                        }
>
>                        @Override
>                        protected void respond(AjaxRequestTarget target) {
>                                //recover the product id
>                                String imovelId =
> RequestCycle.get().getRequest().getParameter("imovelId");
>
>                                // retrieve the product from the database
>                                produto = recuperaProdutoDetalhadoPorId(Long.valueOf(imovelId));
>
>                                //TextField in which the product name suppose to go
>                                TextField apres =
> (TextField)target.getPage().get("formManterImovel:apresentacao");
>                                apres.setModelObject(produto.getNome());
>                                apres.modelChanged();
>                                target.addComponent(apres);
>                        }
>                };
>                add(editMessageReceiver);
>
> Note that in the renderHead method, I add a LifeRays specifc JavaScript
> which listens to a message channel. When a message is get from the channel,
> the JavaScript calls the getCallBack() url passing the product id as a
> parameter.
>
> In the respond(AjaxRequestTarget target) method, I get the product id from
> the request and retrieve the product from the database to put its name in a
> TextField and show it again in the portlet B now with the products name. So
> far, so good.
>
> The problem is that the text field is not being repainted and ramains empty
> (without the products name in it).
>
> I observed that in the AjaxRequestTarget respond(final RequestCycle
> requestCycle) method, the response object carries the following message:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ajax-response>
>    <component id="txtApresentacaoId" >
>    <[CDATA[<input name="apresentacao" type="text" style="width: 98%;
> padding-left: 5px" title="Texto de apresentação do imóvel"
>        value="Apartamento em localização privilegiada e ótimo acabamento"
> id="txtApresentacaoId"/>]]>
>    </component>
> </ajax-response>
>
> Which have the product desired name in it. But, at the end of the request,
> the TextField is not being rendered!
>
> In this same portlet (portlet B) I have a combobox that changes lots of
> TextFields value through AjaxFormComponentUpdatingBehavior when the user
> changes its value. All of them are rendered again in the portlet as
> expected!
>
> So I dont think its a LifeRay problem at all.
>
> Do you guys have an idea of what is happening?
>
> thanks a lot
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Altering-TextField-content-from-within-AbstractDefaultAjaxBehavior-tp4256806p4256806.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
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com