Loading blocks based on a database record

I'm making a reactive web app.

Is it possible to load a block (the reusable screen element) based on a name in the database?

I now have a gigantic nested if/else statement in my screen and I would like to directly load the appropriate block instead.

Or perhaps someone has a suggestion on how to do this in another way?

Rank: #650

Hi Milosa,

Can you please tell me is you condition is based on the check whether you entity is empty or not (data present in your entity or not). If this is the case then use aggregate in preparation, put you web block inside if  either in "True" or "False" block and use condition as shown below


And if this is not the case then put your aggregate in preparation and in if directly compare the name with the values. 

GetCities.List.Current.City.CityName = "CityName"

Hope this will help you



Rank: #224

Hi Milosa

I don't think you can write more generic code than this, either you can do like you are doing currently or you can put all your inputs in a single block and handle them conditionally based on a type as an input parameter.

even in both cases whenever you will add a new type in your database manually conditional changes will always require.



Rank: #139

Hi Milosa,

surely, the way to control it getting out of hand, is controlling the multitude of webblocks that each represent a different type of data.  

The single spot where you have to choose which one to apply in which situation is not the issue (i don't think a massive if structure is the way to go, though), that spot will just be a reflection of how complex you are making the relation between your data and how you represent them.  

So, for starters, there's the mapping of each indivual piece of data to the type of data it holds, i gather that you are doing that inside your datamodel ??  How ?  By looking at the name of attributes, or by modelling them out into a child entity with a value and type, or with a mapping entity, or ???

And then there's the mapping of the type of data to the webblock to be used.  That doesn't even need to be a one on one, you might use a single webblock with parameters to cater for a couple of similar types.  That might already keep the overall messyness down.  But in all this complexity, why do you perceive the single decision structure to do this picking of a webblock as the bit that could 'get out of hand' ?

From your question, I'm kind of sensing that you are trying to make your code as generic as possible.  If not, then why not explicitly choose a block to represent a given piece of info at design time.  Let's say you have a customer with a invoicing address and a delivery address, why not just put the address block on the customer screen twice.  So basically, the step of matching the type of data to the way you want to represent it, is done in your screen design, as is exactly what is done in most applications, designing a ui is deciding how to represent your data.  Is there a reason why you can't do that ?