开发者

CSS class names as bean content. To use or not to use?

Let's say we got 'Car' bean with car color and we want to display the color name with text in that color and some color specific image aside. Currently bean is responsible for converting color name to CSS class name and JSP should only assign that value to some div. It seems convenient, but mixes business and presentation layers.

What is the best practice for mapping String or Enum values to CSS classes? W开发者_如何学Pythonhere it should be done? (Assuming we got 1000 values and they might change.)

Thanks.


Returning class names from business layer looks like bad code indeed.

If I had to do something like it, i'd probably create a custom JSP tag. It gives you the power of handling Java objects and it is still tied closely to the presentation layer. You can define some enum-to-css-class-name mapping source to be loaded and your tag will do the job of using and doing the conversion job.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜