--
You received this message because you are subscribed to the Google Groups "mustache.java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mustachejava+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mustachejava/67ef4522-1010-4d56-be5b-becdb053b378%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
There isn't really support for 3 valued booleans in the language. Can you craft a very specific small example of what your template would look like and what the expected output would be for the 3 cases?
On Tue, Jun 25, 2019 at 3:36 PM, Kiran Hampal <kiran....@gmail.com> wrote:
Hello,--I've got a JAXB object with some optional Boolean object fields.In my mustache template I want to achieve the following behavior:Boolean is true -> print "made up true string here"Boolean is false -> print "made up false string here"Boolean is null/not set -> don't print anythingFor something like an integer I'd just do this:{{#jaxbobject.item}}made up {{jaxbobject.item}} string here{{/jaxbobject.item}}However in this case, both false and null values of the boolean will exhibit the same behaviour. :(What's the recommended way of achieving the desired behaviour mustache? Is there a way of customising mustache to introduce my own "not null/null" operator or do I need to store each string for each field in my context (the jaxb objects are quite big!).ThanksKiran
You received this message because you are subscribed to the Google Groups "mustache.java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mustac...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to mustachejava...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mustachejava/d2cc0c45-5938-4bcb-9fe5-c5f87fb051f1%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mustachejava/CAMUF1Smok-X1L8cC%2Bkg9J-tLVUsD8JwNnX%2BEubRAySDcBcp44Q%40mail.gmail.com.
Not saying this is a good idea, but you could abuse toString to distinguish Boolean.FALSE from null.only true: {{#booleanField}}YES{{/booleanField}}
only false: {{^booleanField}}{{#booleanField.toString}}YES{{/booleanField.toString}}{{/booleanField}}
only null: {{^booleanField.toString}}YES{{/booleanField.toString}}
true or false: {{#booleanField.toString}}YES{{/booleanField.toString}}
false or null: {{^booleanField}}YES{{/booleanField}}-Michael
On Wed, Jun 26, 2019 at 10:53 AM Sam Pullara <spul...@gmail.com> wrote:
Generally you should be using views on top of your objects rather than the data objects directly so that you could have a method that tells you whether or not something is set — in mustache, things are either truthy or falsey. There is no native way to put this kind of business logic into the template. You could potentially add this kind of thing to your ObjectHandler but you're going down a distinctly non-mustache path at that point. I talk a little bit about avoiding using data objects directly as inputs to a template for this reason:Sam
To view this discussion on the web visit https://groups.google.com/d/msgid/mustachejava/d2cc0c45-5938-4bcb-9fe5-c5f87fb051f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "mustache.java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mustac...@googlegroups.com.