Replies: 4 comments 1 reply
-
Hi Michael, Happy New Year! Thanks for checking out Medusa! I don't often get people interacting with my open source projects, so it's kind of exciting to get some feedback. I've tried a little setup myself (with the new XSD implementation): https://github.com/medusa-ui/medusa/blob/feature/maps-arrays/medusa-sample-implementation/src/main/resources/pages/integration-tests/maps.html#L13-L16 And yup, it does not seem like there's a good way to work with Maps yet in the main branch, as you mentioned. In fact, other things might break in the same way: Arrays as variables come to mind. It would make sense to be able to do something like I'll use the feature/maps-arrays branch to do some work on this. Thanks for pointing it out to us! I think I got the basics of it working, but I'll need to check how this works in things like foreaches and click events. Side note: I did just merge in a big refactor I've been working on from this holiday week, so notation wise you'll see a big difference with the latest main branch. I've gotten rid of my own notations and switched to custom HTML tags. Hopefully, that's not too confusing! It's something @dirkdeyne and myself had been talking about for a while and I finally had time to implement it. -- And yes, I agree that creating an expression language has been more complex than I initially figured. As much as possible, I do try to rely on existing systems like SpEL. We do this in several places for the rendering of initial HTML, in fact. But there's always a second side to consider at all times for this project. Rendering the initial HTML is only the first step, after that we need to make sure the JS side can continue to interact with it as well. In a simplified example, what we generally do is something like:
I try to stay away from re-rendering HTML and instead just rely on the new value being passed in the notification. The WebSocket connection is already there, so all I would ideally need to do to keep communication minimal, is let the browser know the new value. On the JS side, we should be smart enough to figure out where that value is used and apply changes as necessary. I know which values to find in the DOM due to an attribute I've set on there. Something like: Actual value. So I can find all those places and replace the new value. With more complex objects (including arrays and maps), I want this to also work - it should just be a matter of traversing the object properly on JS side. So in short, I can only partially rely on SpEL or complex operations like Thymeleaf handles. As much of the logic as possible should really be pushed to the Java side. On the HTML side, I wouldn't want anything more complex in there than some object traversal, some condition expressions, or basic math, I think. |
Beta Was this translation helpful? Give feedback.
-
Hi Kevin, happy new year to you too - and thanks for your elaborate reply. The XML expressions look and feel a lot more natural, not to mention the well-formedness and validity checkability. Thank you for these changes. I've taken the liberty and looked into What do you have in mind, ultimately? How "rich" an expression language do you envision? (As a sidenote, it seems the iteration with Best, Michael |
Beta Was this translation helpful? Give feedback.
-
Thanks for the PR, I will try to find some time this week to have a further look at this functionality. There are quite a few things still to check out that new branch. I'm keeping a list of them here, just for reference: #102 -- I don't want it to become too involved beyond the basics of object traversal. From my perspective, HTML is only meant for structure. So, for some concrete examples, I don't want inline functions anywhere - just references to which Java functions to call on 'actions' (button click, on input, ...). I don't want too complex conditions in iterations or conditions - I'd rather people write a little POJO that has data pre-formatted in an easier way for the UI to handle. I don't really want security tags in the HTML either. If someone's not allowed some data, then that should be filtered out at the Java level. I think object traversal, however, is a common enough use case that I want to explore further. My pie-in-the-sky goals with Medusa are:
So I think that's too involved. I want to have a framework where I can write a page in HTML and say, 'this button corresponds with this action'. Effectively that's what So the goal here is not to provide a lot of functionality on the HTML side. Instead, the goal is just to provide less friction between HTML and Java interactivity. If I have to look at the HTML side for some piece of logic, that's probably too much already. That said, some use cases like conditionals and iterations are common enough that they are pretty much must-haves. For example: want to write a table? You'll need a List variable and then build your rows out of each element in the list. A further (even pie'er-in-the-sky'er) idea I had around simplicity is badly documented here: medusa-ui/phanes#1. I would love it if I got to the point where setting up a Medusa UI (with Hydra support) is as simple as start.spring.io, where you select some basic components and it delivers you a zip with those built-in as examples. All you'd have to do is tailor it to your own needs, but no need to learn the entire language just to build common stuff; at least functionality-wise.
We kind of have this already with https://medusa-ui.gitbook.io/docs/medusa/additional-functions#send-your-own-event-from-anywhere-in-the-backend-code. Likely more work to be done to make this more user friendly, though.
For me, this is the ultimate purpose of Medusa - to provide just enough functionality in medusa tags to have it be workable for your average business app and have it feel like a modern app. Then provide hydra tags to allow interactivity between UI microservices. For example: A menu where the items are dynamically populated by whatever service is online. Or a link to another microservice, which is only available when that microservice is online. Hope that kind of gives you an idea of where my head's at and what my goals are for the project(s). -- Finally, you mentioned iterations don't work for you. I have integration tests in the sample-impl that should at least check that it does in fact iterate, and does so in nested form as well: https://github.com/medusa-ui/medusa/blob/main/medusa-sample-implementation/src/main/resources/pages/integration-tests/nested-each.html So if you have a use case where it doesn't work, I'd love to see it - because that means I haven't covered something in those tests. That said, I do know of one issue at least with the most recent implementation, which is a foreach with no child node but only direct text entries. This has issues:
This should work fine:
I have that on my 'todo' list if that's the issue. |
Beta Was this translation helpful? Give feedback.
-
A first implementation of this has now been merged to the main branch. You can check out the things we've tested for here: https://github.com/medusa-ui/medusa/blob/main/medusa-sample-implementation/src/main/resources/pages/integration-tests/maps.html No doubt we'll stumble over some bugs here and there, but at least now I have a basic answer to your original question on how to use hashmaps or arrays in the medusa tags. :) |
Beta Was this translation helpful? Give feedback.
-
Hello -
how do I access the values stored in a
HashMap
using Medusa expressions?For example, with
$mymap
being aHashMap
:This won't work.
Simplified, even this won't work:
This also won't work, because the
$mymap
part of the expression will evaluate to atoString()
on theHashMap
, and the entire expression will be rendered as{...contents of the map...}['key']
. This is apparently handled in Medusa'sExpressionEval.interpretValue()
method.Now for some naïve musing. It seems that supporting
HashMap
access (and others, e.g., lists, arrays, ...) would make sense in the Medusa expression language. I'm wondering whether the "proprietary" expression language used by Medusa will prove helpful though, as covering all the possible cases will add considerable complexity. Could Medusa rely on plain SpEL?Best,
Michael
Beta Was this translation helpful? Give feedback.
All reactions