You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Thiago H. de Paula Figueiredo" <th...@gmail.com> on 2012/01/03 22:11:10 UTC

Re: Difference between renderSupport.addScript and JSON addInit(function, JSON Object)

On Wed, 28 Dec 2011 14:40:12 -0200, Javix <s....@gmail.com> wrote:

> In javascript, I just replaced arguments by jsonObject:
>
> function load(jsonObject){
> ...
> //acces to the variable in JSON
> errorText.text(jsonObject.m2)
> }
>
> Why in case of JSON it DOES NOT WORK ?

 From the addInit() JavaDoc, specifically the first parameter:

functionName  the name of the function (on the client-side  
Tapestry.Initializer object) to invoke.

addInit() just invokes functions that are part of the Tapestry.Initializer  
object. Try this instead:

Tapestry.Initializer.load = function(jsonObject){
  ...
  //acces to the variable in JSON
  errorText.text(jsonObject.m2)
}

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Difference between renderSupport.addScript and JSON addInit(function, JSON Object)

Posted by Javix <s....@gmail.com>.
One more question:
How to trigger the exectution of js function. For exmaple, before the code
was like that directly n the tml page:

<t:if test="error">
							<div class="info i-error">
								Some hard-coded meessage
							</div>
							
</t:if>
So I tried to apply your technics, but the js function is never loaded (I
have no errors displayed when submitting the form):
@IncludeJavaScriptLibrary(value = { "context:/static/javascript/password.js"
})
public class ForgottenPassword {
...
@Property
    private boolean error;

@BeginRender
    void addJsLibs() {
	if (error) {
	    JSONObject jsonObject = new JSONObject();
	    jsonObject.put("m1", messages.get("js.error.password.epmpty"));
	    jsonObject.put("m2",
messages.get("js.error.confirmed_password.empty"));
	    jsonObject.put("m3", messages.get("js.error.password.not_matched"));
	    jsonObject.put("m4", messages.get("js.error.email.empty"));
	    jsonObject.put("m5", messages.get("js.error.email.wrong"));    	    
	    
	    renderSupport.addInit("loadPass", jsonObject);
	}
    }
...
}
And in JS file password.js:

Tapestry.Initializer.load = function loadPass(jsonObject){
..
passError.html(jsonObject.m1);
...
}
loadPass(jsonObject);

Why?






--
View this message in context: http://tapestry.1045711.n5.nabble.com/Difference-between-renderSupport-addScript-and-JSON-addInit-function-JSON-Object-tp5105620p5125897.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Difference between renderSupport.addScript and JSON addInit(function, JSON Object)

Posted by Javix <s....@gmail.com>.
Finally I got it working by adding as you told:

Tapestry.Initializer.load = function load(jsonObject){
..
errorText.text(jsonObject.m1)

}

and ot in the very begining of the call:

jQuery(document).bind(Tapestry.ZONE_UPDATED_EVENT, function(e){	
	//load(m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12);
	load(jsonObject);
});
It works, THANK YOU!

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Difference-between-renderSupport-addScript-and-JSON-addInit-function-JSON-Object-tp5105620p5119608.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: Difference between renderSupport.addScript and JSON addInit(function, JSON Object)

Posted by Javix <s....@gmail.com>.
It didn't work:

Oups ... org.apache.tapestry5.runtime.ComponentEventException: A component
event handler method returned the value
MultiZoneUpdate[{page=org.apache.tapestry5.corelib.components.Zone@1799a64, 

May it's because in the javascript file the call to the load fucntion is
made lie that:

jQuery(document).bind(Tapestry.ZONE_UPDATED_EVENT, function(e){	
	//load(m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12);
	load(jsonObject);
});

...
Tapestry.Initializer.load = function load(jsonObject){
//function load(m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12){
errorText.text(jsonObject.m1)
...
}

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Difference-between-renderSupport-addScript-and-JSON-addInit-function-JSON-Object-tp5105620p5119428.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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