Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Beginner : need xtend help
Beginner : need xtend help [message #697890] Mon, 18 July 2011 05:40 Go to next message
Eclipse UserFriend
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 05:42 Go to previous messageGo to next message
Eclipse UserFriend
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 05:48 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Beginner : need xtend help [message #697894 is a reply to message #697893] Mon, 18 July 2011 05:51 Go to previous messageGo to next message
Eclipse UserFriend
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 05:58 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Beginner : need xtend help [message #697899 is a reply to message #697898] Mon, 18 July 2011 05:59 Go to previous message
Eclipse UserFriend
Thanks much!
Previous Topic:Xtext from 2 ecore files
Next Topic:Using results from language interpreter in JavaValidator
Goto Forum:
  


Current Time: Fri Jul 11 22:53:45 EDT 2025

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

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

Back to the top