Could I somehow make "screen templates"?

If I have multiple screens, possibly a dozen or more (one per “asset type”, implementing a CRUD UI), which are identical, except for the screen ID, and the controller class, is there a way I could reuse the XML somehow? I could have some “build task” that use XSLT or something to generate them, but that sounds like a lot of work. Is there some easier way that one of you could think of? The simplest way I can think of, is to turn the XML into Java builder code, but I don’t really like that idea, for a somewhat complex screen.

you could probably create a custom control for it and add that to each screen

Right-click the nifty xml file, select “Save as Template”

Thank you.

@wezrule Unless I’m missing something, programming my own custom control seems to be quite a lot of work, judging by the amount of code required for a prototype of editable text-area that I saw somewhere in the forum. That makes XSLT sound like the easier option…

@normen I can’t read you here. By “template”, I mean some kind of “reuse” that would not involve just duplicating the same code(XML) N times, you know, like inheritance with a few abstract methods. Using the IDE templating system seems just like a more nerdy version of copy-and-paste. Were you really just taking what I said literally, or was that meant as a joke?

The big reason against a copy-and-paste solution, is that if I have 12 copies, and I need to change something, then I need to change it 12 times, which is error prone. Of course, there might not be any practical solution which solves this issue, while at the same time not being way more work then is worth it. But that’s why I asked.

So you want what? A template that asks you what to enter for each string you set as “variable” in the template? That can be done too, theres a scripting system for the templates, check out the manual or look at some of the existing templates (Tools->Templates I think).

Or do you want to do something while the app is built? Theres ANT for that, edit the build.xml file. The XML code completion should give you hints if you’re not experienced in ANT, else its well documented.

…the NetBeans find and replace also supports RegEx and works across projects, folders and whatnot… if that helps shrug

One approach is to create a master XML file, add some code to the build script to do a copy of the file and then search and replace the specified tags to create the custom screen.

That is what I want: create an XML file with “replaceable parts”, and replace them before passing it to Nifty. I just noticed I can pass the XML as an InputStream, so I just load it myself directly, do an in-memory search-and-replace, and pass it to Nifty. That should work. :slight_smile: In fact, I don’t need any help from JME, except for the locating and loading of the XML template; I can just use standard XML APIs. :slight_smile: