7

I've read a statement somewhere that generating UI automatically from DB layout (or business objects, or whatever other business layer) is a bad idea. I can also imagine a few good challenges that one would have to face in order to make something like this.

However I have not seen (nor could find) any examples of people attempting it. Thus I'm wondering - is it really that bad? It's definately not easy, but can it be done with any measure success? What are the major obstacles? It would be great to see some examples of successes and failures.

To clarify - with "generating UI automatically" I mean that the all forms with all their controls are generated completely automatically (at runtime or compile time), based perhaps on some hints in metadata on how the data should be represented. This is in contrast to designing forms by hand (as most people do).

Added: Found this somewhat related question

Added 2: OK, it seems that one way this can get pretty fair results is if enough presentation-related metadata is available. For this approach, how much would be "enough", and would it be any less work than designing the form manually? Does it also provide greater flexibility for future changes?

Community
  • 1
  • 1
Vilx-
  • 104,512
  • 87
  • 279
  • 422

9 Answers9

6

We had a project which would generate the database tables/stored proc as well as the UI from business classes. It was done in .NET and we used a lot of Custom Attributes on the classes and properties to make it behave how we wanted it to. It worked great though and if you manage to follow your design you can create customizations of your software really easily. We also did have a way of putting in "custom" user controls for some very exceptional cases.

All in all it worked out well for us. Unfortunately it is a sold banking product and there is no available source.

Mladen Mihajlovic
  • 6,095
  • 7
  • 40
  • 55
  • 1
    Tell me - how much info did you specify in the attributes? Was it down to very last pixel, or just "show this as textbox" and "show this as dropdown"? Also - would a screenshot of a typical form be much to ask? – Vilx- Apr 08 '09 at 09:15
  • Well to do this you need a kind of abstraction for the UI where the UI is defined into specific areas, types, style - that kind of thing. The attributes were not that detailed. We worked on a grid kind of display so they were more like, which type (although the type was inferred most of the time)... – Mladen Mihajlovic Apr 08 '09 at 09:39
  • but this was in case you wanted to change the type (ui type I mean) and also validations were defined here (mandatory, regex, numeric, currency, etc...), visibility, which group they belong to (we had subheadings (collapsible) like ms money) etc... – Mladen Mihajlovic Apr 08 '09 at 09:41
  • A screenshot is not really possible as I've left that company a while ago and I don't have any. But if you look at MS Money you would get an idea of what we did. – Mladen Mihajlovic Apr 08 '09 at 09:42
  • The main thing is that you need to have a well defined UI and the business classes need to fit into it. The usercontrols were for those really extreme cases (and we had to use an attribute to set a class to use the usercontrol) Lots of reflection was used :) – Mladen Mihajlovic Apr 08 '09 at 09:43
  • Heh, I believe you about the reflection. :) Though I really wonder what kind of performance effect that has. :P – Vilx- Apr 08 '09 at 09:46
  • Well if you cache it it's not too bad. – Mladen Mihajlovic Apr 08 '09 at 10:15
4

it's ok for something tiny where all you need is a utilitarian method to get the data in.

for anything resembling a real application though, it's a terrible idea. what makes for a good UI is the humanisation factor, the bits you tweak to ensure that this machine reacts well to a person's touch.

you just can't get that when your interface is generated mechanically.... well maybe with something approaching AI. :)

edit - to clarify: UI generated from code/db is fine as a starting point, it's just a rubbish end point.

nailitdown
  • 7,868
  • 11
  • 36
  • 37
  • 2
    That's the original opinion I had heard. And while intuitively it really seems so, I want some examples to approve or deny this. :) – Vilx- Apr 08 '09 at 10:21
  • 1
    I don't think this is true. It worked perfectly for us and our customers were perfectly happy with the usability. Do you have a real world scenario where this is not good, or is this just an opinion? – Mladen Mihajlovic Apr 08 '09 at 10:30
  • Just to clarify we did a lot more then just generate off the database. There was a lot of metadata (using cutom attributes) which were also used. – Mladen Mihajlovic Apr 08 '09 at 10:30
0

Can you look on your problem from application architecture perspective? I see you as another database terrorist – trying to solve all by writing stored procedures. Why having UI at all? Try do it in DB script. In effect of such approach – on what composite system you will end up? When system serves different businesses – try modularization, selectively discovered components, restrict sharing references. UI shall be replaceable, independent from business layer. When storing so much data in DB – there is hard dependency of UI – system becomes monolith. How you implement MVVM pattern in scenario when UI is generated? Designers like Blend are containing lots of features, which cannot be replaced by most futuristic UI generator – unless – your development platform is Notepad only.

  • Ermm... well, first of all, I'd like to bring your attention to the fact that this question is over 4 years old and the discussion is quite stale already. Anyways, my idea was that a lot of the work we do as CRUD application developers is quite repetitive, including the form design. Sure there's an oddity now and then, but for the most part it's the same stuff over and over again. My question was - would it be possible to automate some (most?) of it. In this case, the UI, which also always consists of the same elements, just different names in different forms. – Vilx- May 20 '13 at 06:40
  • 1
    Anyways, in the 4 years since I posted this question my own views have changed too. Today I would attempt to solve this by a library which covers most standard cases. That way the repetitive stuff is reduced to a minimum, while also allowing the flexibility required by the exceptional cases. – Vilx- May 20 '13 at 06:44
0


There is a hybrid approach where forms and all are described in a database to ensure consistency server side, which is then compiled to ensure efficiency client side on deploy.

A real-life example is the enterprise software MS Dynamics AX.

It has a 'Data' database and a 'Model' database.

The 'Model' stores forms, classes, jobs and every artefact the application needs to run.

Deploying the new software structure used to be to dump the model database and initiate a CIL compile (CIL for common intermediate language, something used by Microsoft in .net)

This way is suitable for enterprise-wide software and can handle large customizations. But keep in mind that this approach sets a framework that should be well understood by whoever gonna maintain and customize the application later.

Bilaal Rashid
  • 828
  • 2
  • 13
  • 21
ploox
  • 1
  • 1
0

I did this (in PHP / MySQL) to automatically generate sections of a CMS that I was building for a client. It worked OK my main problem was that the code that generates the forms became very opaque and difficult to understand therefore difficult to reuse and modify so I did not reuse it.

Note that the tables followed strict conventions such as naming, etc. which made it possible for the UI to expect particular columns and infer information about the naming of the columns and tables. There is a need for meta information to help the UI display the data.

Generally it can work however the thing is if your UI just mirrors the database then maybe there is lots of room to improve. A good UI should do much more than mirror a database, it should be built around human interaction patterns and preferences, not around the database structure.

So basically if you want to be cheap and do a quick-and-dirty interface which mirrors your DB then go for it. The main challenge would be to find good quality code that can do this or write it yourself.

Rolf
  • 5,550
  • 5
  • 41
  • 61
0

hey this is not difficult to achieve at all and its not a bad idea at all. it all depends on your project needs. a lot of software products (mind you not projects but products) depend upon this model - so they dont have to rewrite their code / ui logic for different client needs. clients can customize their ui the way they want to using a designer form in the admin system

i have used xml for preserving meta data for this sort of stuff. some of the attributes which i saved for every field were:

  1. friendlyname (label caption)
  2. haspredefinedvalues (yes for drop down list / multi check box list)
  3. multiselect (if yes then check box list, if no then drop down list)
  4. datatype
  5. maxlength
  6. required
  7. minvalue
  8. maxvalue
  9. regularexpression
  10. enabled (to show or not to show)
  11. sortkey (order on the web form)

regarding positioning - i did not care much and simply generate table tr td tags 1 below the other - however if you want to implement this as well, you can have 1 more attribute called CssClass where you can define ui specific properties (look and feel, positioning, etc) here

UPDATE: also note a lot of ecommerce products follow this kind of dynamic ui when you want to enter product information - as their clients can be selling everything under the sun from furniture to sex toys ;-) so instead of rewriting their code for every different industry they simply let their clients enter meta data for product attributes via an admin form :-)

i would also recommend you to look at Entity-attribute-value model - it has its own pros and cons but i feel it can be used quite well with your requirements.

Raj
  • 6,810
  • 6
  • 48
  • 56
0

In my Opinion there some things you should think about:

  1. Does the customer need a function to customize his UI?
  2. Are there a lot of different attributes or elements?
  3. Is the effort of creating such an "rendering engine" worth it?

Okay, i think that its pretty obvious why you should think about these. It really depends on your project if that kind of model makes sense... If you want to create some a lot of forms that can be customized at runtime then this model could be pretty uselful. Also, if you need to do a lot of smaller tools and you use this as some kind of "engine" then this effort could be worth it because you can save a lot of time. With that kind of "rendering engine" you could automatically add error reportings, check the values or add other things that are always build up with the same pattern. But if you have too many of this things, elements or attributes then the performance can go down rapidly. Another things that becomes interesting in bigger projects is, that changes that have to occur in each form just have to be made in the engine, not in each form. This could save A LOT of time if there is a bug in the finished application.

In our company we use a similar model for an interface generator between cash-software (right now i cant remember the right word for it...) and our application, just that it doesnt create an UI, but an output file for one of the applications. We use XML to define the structure and how the values need to be converted and so on..

SvenFinke
  • 1,254
  • 3
  • 15
  • 30
0

I would say that in most cases the data is not suitable for UI generation. That's why you almost always put a a layer of logic in between to interpret the DB information to the user. Another thing is that when you generate the UI from DB you will end up displaying the inner workings of the system, something that you normally don't want to do.

But it depends on where the DB came from. If it was created to exactly reflect what the users goals of the system is. If the users mental model of what the application should help them with is stored in the DB. Then it might just work. But then you have to start at the users end. If not I suggest you don't go that way.

haqwin
  • 377
  • 3
  • 12
  • Well, I was more thinking of displaying some business objects than the DB directly. Displaying tables to the user really isn't a very neat way of working... I think... Then again, people love Excel, don't they? – Vilx- Apr 08 '09 at 12:57
0

From my perspective, it was always a problem to change edit forms when a very simple change was needed in a table structure. I always had the feeling we have to spend too much time on rewriting the CRUD forms instead of developing the useful stuff, like processing / reporting / analyzing data, giving alerts for decisions etc...

For this reason, I made long time ago a code generator. So, it become easier to re-generate the forms with a simple restriction: to keep the CSS classes names. Simply like this! UI was always based on a very "standard" code, controlled by a custom CSS. Whenever I needed to change database structure, so update an edit form, I had to re-generate the code and redeploy.

One disadvantage I noticed was about the changes (customizations, improvements etc.) done on the previous generated code, which are lost when you re-generate it. But anyway, the advantage of having a lot of work done by the code-generator was great!

I initially did it for the 2000s Microsoft ASP (Active Server Pages) & Microsoft SQL Server... so, when that technology was replaced by .NET, my code-generator become obsoleted. I made something similar for PHP but I never finished it...

Anyway, from small experiments I found that generating code ON THE FLY can be way more helpful (and this approach does not exclude the SAVED generated code): no worries about changing database etc. So, the next step was to create something that I am very proud to show here, and I think it is one nice resolution for the issue raised in this thread. I would start with applicable use cases: https://data-seed.tech/usecases.php. I worked to add details on how to use, but if something is still missing please let me know here! You can change database structure, and with no line of code you can start edit data, and more like this, you have available an API for CRUD operations.

I am still a fan of the "code-generator" approach, and I think it is just a flavor of using XML/XSLT that I used for DATA-SEED. I plan to add code-generator functionalities.