require:false for a template inheriting another

24 views
Skip to first unread message

Samuel Rossinovic

unread,
Oct 29, 2017, 6:34:18 PM10/29/17
to Geb User Mailing List

I have a confirmation dialog where I wish to allow for buttons labeled either ‘ok’ or ‘yes’.

class Foo extends Module {
    static content = {
        button { $("a", text: it) }

        yes(required: false) {button "Yes" }
        ok(required: false) {button "OK" }
        no { button "No" }
    }

    def confirm() { (yes ?: ok).click() }
}

Yet calling confirm() yields a RequiredPageContentNotPresent when the button is labeled ‘ok’. Only when I set require: false on button, does it play well.

Is that intended, that enabling optional content would require marking all inherited templates as require:false?
Thanks

Marcin Erdmann

unread,
Oct 30, 2017, 5:19:49 PM10/30/17
to Geb User Mailing List
I wouldn't say that the behaviour you're seeing is intended in a way that it was foreseen, but yes, this is how it works, you will need to mark all such templates with `required: false` no to get RequiredPageContentNotPresent exceptions.

Marcin

--
You received this message because you are subscribed to the Google Groups "Geb User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+unsubscribe@googlegroups.com.
To post to this group, send email to geb-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/aa7231f1-d6ca-4409-9ab9-474214b2a4a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Samuel Rossinovic

unread,
Oct 30, 2017, 11:12:57 PM10/30/17
to Geb User Mailing List
Would you consider a request to change that behavior valuable ?
Or possibly just documenting it in the book... 


On Tuesday, October 31, 2017 at 8:19:49 AM UTC+11, Marcin Erdmann wrote:
I wouldn't say that the behaviour you're seeing is intended in a way that it was foreseen, but yes, this is how it works, you will need to mark all such templates with `required: false` no to get RequiredPageContentNotPresent exceptions.

Marcin
On Sun, Oct 29, 2017 at 10:34 PM, Samuel Rossinovic <samuel.r...@gmail.com> wrote:

I have a confirmation dialog where I wish to allow for buttons labeled either ‘ok’ or ‘yes’.

class Foo extends Module {
    static content = {
        button { $("a", text: it) }

        yes(required: false) {button "Yes" }
        ok(required: false) {button "OK" }
        no { button "No" }
    }

    def confirm() { (yes ?: ok).click() }
}

Yet calling confirm() yields a RequiredPageContentNotPresent when the button is labeled ‘ok’. Only when I set require: false on button, does it play well.

Is that intended, that enabling optional content would require marking all inherited templates as require:false?
Thanks

--
You received this message because you are subscribed to the Google Groups "Geb User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+u...@googlegroups.com.

Marcin Erdmann

unread,
Nov 1, 2017, 5:39:37 PM11/1/17
to geb-...@googlegroups.com
I think that changing this behaviour would be counter productive. I understand that it’s frustrating that you have to explictly mark all content potentially returning empty navigators with required: false, even when it is accessed by another content definition that is already mark with it. And that it might seem to you counter intuitive. Please bear in mind that the goal of this mechanism is to fail fast - you get an exception as soon as content definition returns an empty navigator or a falsey value unless you explocitly say that this prticular definition does not always return something. The only way of implementing what you are suggesting I can think of is by catching RequiredContentNotPresent inside of a required: false content definition and returning an empty navigator. I think such a catch all behaviour would defeat the purpose of failing fast.

I’m more than happy to mention this behaviour in the manual. Github issues, pull requests and suggestions on wording and placement within the manual are welcome.

Samuel Rossinovic

unread,
Dec 6, 2017, 12:24:34 AM12/6/17
to Geb User Mailing List
Hi. In-case someone else stumbles onto such a case, here's a workaround that I think will work to resolve the a/m use-case:
class Foo extends Module {
   
static content = {

        button
{ label ->
           
if (label instanceof List) label.collect {$('a', text: it)}.find { it }
           
else $('a', text: label)
       
}
        submit
{ button (['Yes, 'Save']) }
    }
}


HTH
Reply all
Reply to author
Forward
0 new messages