PDA

View Full Version : Attribute of type Expression


cdickson
02-04-2003, 10:33 AM
I have two attributes tags defined in a view:

<view>
<attributes name="SERVERNAME" value="http://localhost:8080" type="string" />
<attributes name="CONTROLLER_PATH" value="/myapp/controllers/" type="string" />
...
</view>

I want to define another attribute named LOGGER_URL that concats these abouve attributes with another string to get a value "http://localhost:8080/myapp/controllers/logger.jsp".

I am assuming to use the attribute of type 'expression'. what is the proper syntax for that?

Thanks
-Clint

Clint Dickson Software Engineer
p 415.875.7061 f 415.875.7001 cdickson@semaphorepartners.com

Semaphore Partners www.semaphorepartners.com

antun
02-04-2003, 10:48 AM
Hey Clint

You use the init attribute of the <attribute> tag:


<view id="smelly">
<attribute name="SERVERNAME" value="http://localhost:8080"
type="string" />
<attribute name="CONTROLLER_PATH" value="/myapp/controllers/"
type="string" />
<attribute name="LOGGER_URL"
init="this.SERVERNAME + this.CONTROLLER_PATH"
type="string" />
</view>


You don't need the expression attribute here.

-Antun

cdickson
02-04-2003, 10:53 AM
What if i needed to also concat a string "logger.jsp" in the attribute?
This expression would be:

this.SERVERNAME + this.CONTROLLER_PATH + "logger.jsp"

thanks!
-clint

antun
02-04-2003, 11:03 AM
Hey Clint

It would be:


<view id="smelly">
<attribute name="SERVERNAME" value="http://localhost:8080"
type="string" />
<attribute name="CONTROLLER_PATH" value="/myapp/controllers/"
type="string" />
<attribute name="LOGGER_URL"
init="this.SERVERNAME + this.CONTROLLER_PATH + 'login.jsp'"
type="string" />
</view>


The single quotes are required because the init attribute of an attribute tag takes an expression. (See the LZX ref: http://www.laszlosystems.com/developers/learn/documentation/lzxref/attribute.php#tag). To put a string in a JavaScript expression, you have to enclose it in quotes. If you didn't use the quotes, it would look for an element named 'login' and look for an attribute named 'jsp' within that.

This is true of any LZX attribute that takes an expression.

Take care,

Antun