views:

247

answers:

5

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?

+3  A: 

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
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-
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
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
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
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
Heh, I believe you about the reflection. :) Though I really wonder what kind of performance effect that has. :P
Vilx-
Well if you cache it it's not too bad.
Mladen Mihajlovic
A: 

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
+2  A: 

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
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-
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
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
A: 

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..

Gushiken
A: 

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
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-
Or do they, really? :)
haqwin