-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi people,
I need to create a very complex window, with a lots of labels, textboxes and buttons filled with data from a database. Also each of these components must have a different style (background, foreground, font, border etc.) depending on the data when loading. So far so good! My problem is to change a single style property without deconstructing and reconstructing the style-string again. May be a textbox style is:
_textBox.setStyle("background-color:#123456;font-family:open sans light;font-size:123;color:#654321");
If I want to change the font-size for example, I could split the string at ";", check for "startsWith("font-family"), split again at ":" and so on. After all I have to construct the style string again and set the property. Well, I could store style-strings parallel in a hashmap, but when changing a single style has to take effect on multiple components, there is a lot of checking, looping, hashing etc. Also I'm afraid to blow up the performance and memory budget!
Is there a more efficient way to change a single style of a component? Direct access to the CSS-parser or a helper Class?
I don't understand why you have to do such a thing. The first thing is to define all different styles in a separate css file. Then apply in the sclass property of each component all required css-classes depending on your business rules.
/costas
Why don't you create a enum?
Define in the enum all the different possibilities.
you can even save the enum value in the DB, so when you load your data, you just need to get the style from the enum.
The thing what change is when you save the data, you need to check what enum value it will be.
Like this, lesser check in the viewmodels (most of time) but you have to adapt your model and service.
Chill.
Hello Manz,
Also you could define domain models in order to retrieve your data.
i.e
Table Name: Template (id, name, create_date, update_date)
Table Name: Template_Values (id, template_id, property_name, property_value, create_date, update_date)
Best Regards,
Darksu
Asked: 2015-08-11 14:43:51 +0800
Seen: 46 times
Last updated: Sep 21 '15
composite component help [closed]
EL in a forEach @command not working?
Different template for each grid row
Cardlayout animation is broken
Grid RowRender slow using 6.5.1 and sizable=true
setVisible(false), component will load or not
Decimalbox and doublebox value rounded on iPad
history management with page status