Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Beginner : need xtend help
Beginner : need xtend help [message #697890] Mon, 18 July 2011 09:40 Go to next message
Arun  is currently offline Arun Friend
Messages: 26
Registered: July 2011
Junior Member
Hi,

I have a model which generates html tags like the below one

<form name="test" method=POST action="test.jps">
<input type=text name="name" length=30/>
</form>

The 'length' attribute is not a mandatory one. I have to add the length attribute only if it has been defined in dsl.

In xpand i have,

«FOREACH forms AS f»
<form name="«f.name»" "method="«f.methodType.name.toUpperCase()»" action="">
«FOREACH f.texts AS t»

<input type="text" name="«t.name»" maxlength="«t.maxlength»"/>
«ENDFOREACH»
</form>
«ENDFOREACH»

I have to add 'maxlength' attribute conditionally in my xpand template.

In Extensions.ext file , i have

boolean isMaxLengthExists(Model this) :
this.types.typeSelect(HTML).forms.texts.exists(e|e.maxlength) ;

//I'm getting error Boolean type expected! was Integer.

FYI, maxlength i s of type INT.

Thanks,
Arun






Re: Beginner : need xtend help [message #697891 is a reply to message #697890] Mon, 18 July 2011 09:42 Go to previous messageGo to next message
Arun  is currently offline Arun Friend
Messages: 26
Registered: July 2011
Junior Member
Sorry there is a typo its not maxlength, it is 'length'

boolean isLengthExists(Model this) :
this.types.typeSelect(HTML).forms.texts.exists(e|e.length) ;

length is of type INT
Re: Beginner : need xtend help [message #697893 is a reply to message #697891] Mon, 18 July 2011 09:48 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

this.types.typeSelect(HTML).forms.texts.exists(e|e.length!=0);

The problem is that there is a default value for features with integer value, so by default you cannot distinguish the case "length is not set" and "length is set to 0".

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Beginner : need xtend help [message #697894 is a reply to message #697893] Mon, 18 July 2011 09:51 Go to previous messageGo to next message
Arun  is currently offline Arun Friend
Messages: 26
Registered: July 2011
Junior Member
Thanks for the quick reply Alex!. But how to call this xpand template and conditionally generate the html tags.

Thanks,
Arun
Re: Beginner : need xtend help [message #697898 is a reply to message #697894] Mon, 18 July 2011 09:58 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

<input type="text" name="«t.name»"«IF conditionIsTrueFor(t)» length="«t.length»"«ENDIF»/>

Please have a look at the Xtend/Xpand documentation for these basic concepts.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Beginner : need xtend help [message #697899 is a reply to message #697898] Mon, 18 July 2011 09:59 Go to previous message
Arun  is currently offline Arun Friend
Messages: 26
Registered: July 2011
Junior Member
Thanks much!
Previous Topic:Xtext from 2 ecore files
Next Topic:Using results from language interpreter in JavaValidator
Goto Forum:
  


Current Time: Thu Apr 25 11:11:53 GMT 2024

Powered by FUDForum. Page generated in 0.03643 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top