My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
useScriptFeature  
Use Scripting features
Updated Apr 3, 2012 by bartolom...@gmail.com

Introduction

From release 2.6 swiwml2 has included scripting features (JSR223)

Example

<?xml version="1.0" encoding="UTF-8" ?>

<dialog 
xmlns="http://www.swixml.org/2007/Swixml" 
xmlns:script="http://www.swixml.org/2007/Swixml/script"
	resizable="true" 
	title="Example Script usage" 
	undecorated="false" 
	alwaysOnTop="true"
	defaultCloseOperation="JFrame.HIDE_ON_CLOSE" 
	modal="false"
	>

<!-- 
JAVA SCRIPT THAT DEFINE 'CLOSE' ACTION 

client ==> Rendered object 
application ==> Application' rendering object
-->
<script>

function close(e) {

	client.setVisible(false);
	
	application.exit();
}

</script>
<panel layout="borderLayout">

<vbox constraints="BorderLayout.CENTER">

<!-- CLASSIC ACTION BINDING -->
<Button name="tb" id="toggleButton" text="action" action="onCLick"  />

<box.vstrut height="10"></box.vstrut>

</vbox>

<hbox constraints="BorderLayout.SOUTH">
<!-- SCRIPT ACTION BINDING -->
<button text="close" script:action="close"/>
</hbox>
</panel>


</dialog>

Comment by monojoh...@yahoo.com, Nov 4, 2011

Any idea why I would get this error ?

// org.jdom.input.JDOMParseException: Error on line 21: The prefix "script" for attribute "script:action" associated with an element type "button" is not bound. //

Comment by project member bartolom...@gmail.com, Nov 4, 2011

Are you using 2.6-SNAPSHOT from repository https://oss.sonatype.org/content/repositories/snapshots ?

Please report bug in Issues section http://code.google.com/p/swixml2/issues/list

Comment by monojoh...@yahoo.com, Nov 11, 2011

Ah - that'll be why - I was using the released 2.5 dist - I should have read the notes better. I'll check out 2.6 another time (I have to work out how to retrieve those snapshots). Thanks for getting back on this.

Comment by rkapa2...@gmail.com, Feb 21, 2012

Is there a way that one can use java script function in eval expression?

For example in the above example I want to set button text through java script function like this. ......... .........

<script>
function getButtonLabel() {
return "action"
}
</script>
...... ...... <Button name="tb" id="toggleButton" text="${script:getButtonLabel()}" action="onCLick" /> ..... .....

Comment by project member bartolom...@gmail.com, Feb 21, 2012

Hi

Idea, behind the script introduction,is to achieve what you are asking for

At the moment i've implemented, throught script, just actions' evaluation ...

I've planned to introduce generic attribute evaluation, but until now i hadn't time to work on it

I've opened the  Issue 79 .. stay tune on it

Thx for feedbak Bartolo

Comment by rkapa2...@gmail.com, Feb 21, 2012

Hi,

Thanks u very much for that, it would be real cool. And also while doing it please consider the following also. Adding a "src" attribute to the "script" element. For example in the above code: <code> ...... ...... ...... <script language="JavaScript" src="smaple.js"></script> ...... ...... ...... <Button name="tb" id="toggleButton" text="${script:getButtonLabel()}" action="onClick()"> ...... ...... ...... Here is the sample.js file //sample.js function getButtonLabel() { return "action" } </code>

That way we can cleanly separate the markup and logic and test them in isolation.

Powered by Google Project Hosting