@Florian: Regarding your question about a specific use-case, I am doing research into the requirements for supporting usage of the MVC 1.0 in a portlet environment -- that is actually the context of most of my questions lately.
One important difference between a servlet-based webapp and a portlet-based application is that the portlet lifecycle is based on a post-redirect-get type of design pattern.
In JAX-RS terms, portlet application form submissions always behave like this:
@Inject Models models;
@POST
@Controller
public String submitForm() {
models.put("abcd", "1234");
return "redirect:/mvc/foo";
}
@GET
@Controller
@View("view.jsp")
public String prepareView() {
System.err.println("abcd=" + models.get("abcd"));
}
Because of this, the instance of javax.mvc.Models has to be stored in something similar to @RedirectScoped so that it survives from the HTTP POST request into the subsequent HTTP GET request.
Back to the question about the use-case, I can foresee the possibility of the portlet developer wanting to remove a model attribute or clear the model attributes in the @GET controller method. Additionally, if a developer wanted to provide a CDI @Alternative for Models, then having more methods that control the underlying map would be a more helpful/flexible API.
Neil
On 1/26/19 1:51 PM, Florian Hirsch wrote:
> Thanks for your answer Christian. You're right:
>
> >Prior to the view render phase, all entries available in Models MUST be bound in such a way that they become available to the view being processed. The exact mechanism for this depends on the actual view engine implementation. In the case of the built-in view engines for JSPs and Facelets, entries in Models must be bound by calling HttpServletRequest.setAttribute(String, Object). Calling this method ensures access to the named models from EL expressions.
>
> This is explicit enough.
>
> Flo
>
> Am 26. Januar 2019 um 18:14:48, Christian Kaltepoth (
chri...@kaltepoth.de <mailto:
chri...@kaltepoth.de>) schrieb:
>
>> @Florian:
>>
>> If you @Observe AfterControllerEvent in a CDI bean, you could also inject Models into the same bean. So accessing the Models instance should be easy.
>>
>> Regarding clarification on how ViewEngines give access to models. IIRC this is more or less clearly specified. But maybe I'm wrong. Of course, we could make this more explicit if required.
>>
>> Christian
>>
>> Am Sa., 26. Jan. 2019 um 12:19 Uhr schrieb Florian Hirsch <
po...@florianhirsch.de <mailto:
po...@florianhirsch.de>>:
>>
>> Hi Neil,
>>
>> do you have any use-cases in mind? I first thought about removing model attributes in a generic AfterControllerEvent but I saw that you can't access models there. (OT: but would that make sense?)
>>
>> Regarding the missing map syntax: would it make sense to clarify in the spec at least how view Engines should give access to models?
>>
>> best
>> Flo
>>
>> Am 26. Januar 2019 um 06:31:10, Christian Kaltepoth (
chri...@kaltepoth.de <mailto:
chri...@kaltepoth.de>) schrieb:
>>
>>> Hey Neil,
>>>
>>> thanks for your feedback. I'm really happy to see that you are reviewing the latest draft of the spec. :-)
>>>
>>> Yes, we changed the Models interface in the PFD version of the spec. See the corresponding issue <
https://github.com/mvc-spec/mvc-spec/issues/40> and the pull request <
https://github.com/mvc-spec/mvc-spec/pull/171> for more information about the reasons for this change.
>>>
>>> Regarding your concerns:
>>>
>>> 1. Yes, currently you cannot clear the models instance or remove individual entries from it. But to be honest, I don't think this is something that a developer really needs. Usually you collect data in your controller (from the database or something like that) and store view models in the Models instance. But why should I clear it? Usually the controller method is quite simple. It gets data from somewhere and stores it in the model. BTW: If you really need to remove something from Models, you could still overwrite it with "null", which would have the same effect as removing it. However, I really doubt that somebody needs to do that in real world apps.
>>> 2. Actually I wasn't aware that our change breaks the ability to use JSP map syntax. But as you already wrote this isn't really a problem, because we don't expose the model as a "model" EL variable but instead make all the individual entries available in the EL context. So I don't think this is a real issue.
>>> > Linkedin:
www.linkedin.com/in/danieldiasjava <
http://www.linkedin.com/in/danieldiasjava> <
http://www.linkedin.com/in/danieldiasjava>
>>> > To unsubscribe from this group and stop receiving emails from it, send an email to
jsr371-users...@googlegroups.com <mailto:
jsr371-users%2Bunsu...@googlegroups.com> <mailto:
jsr371-users...@googlegroups.com <mailto:
jsr371-users%2Bunsu...@googlegroups.com>>.
>>> > To post to this group, send email to
jsr371...@googlegroups.com <mailto:
jsr371...@googlegroups.com> <mailto:
jsr371...@googlegroups.com <mailto:
jsr371...@googlegroups.com>>.
>>> > To unsubscribe from this group and stop receiving emails from it, send an email to
jsr371-users...@googlegroups.com <mailto:
jsr371-users%2Bunsu...@googlegroups.com> <mailto:
jsr371-users...@googlegroups.com <mailto:
jsr371-users%2Bunsu...@googlegroups.com>>.
>>> > To post to this group, send email to
jsr371...@googlegroups.com <mailto:
jsr371...@googlegroups.com> <mailto:
jsr371...@googlegroups.com <mailto:
jsr371...@googlegroups.com>>.
>>> To unsubscribe from this group and stop receiving emails from it, send an email to
jsr371-users...@googlegroups.com <mailto:
jsr371-users%2Bunsu...@googlegroups.com>.
>>> To view this discussion on the web visit
https://groups.google.com/d/msgid/jsr371-users/CAEXeC6yKLcDx-WR38mg0DTF4xy8x5NMdSoFTLbZ7uSaBsx6oqg%40mail.gmail.com <
https://groups.google.com/d/msgid/jsr371-users/CAEXeC6yKLcDx-WR38mg0DTF4xy8x5NMdSoFTLbZ7uSaBsx6oqg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>> To view this discussion on the web visit
https://groups.google.com/d/msgid/jsr371-users/CADO3Jtn1-t2%2B1fGdfqpU9Dr5u1r8vW5Q7JmLQnrx877NhN55eg%40mail.gmail.com <
https://groups.google.com/d/msgid/jsr371-users/CADO3Jtn1-t2%2B1fGdfqpU9Dr5u1r8vW5Q7JmLQnrx877NhN55eg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
>> To view this discussion on the web visit
https://groups.google.com/d/msgid/jsr371-users/CAEXeC6zJZYaCtRYeicnOLqvGka1oZFHO2e1%3D%3Dj-F%3D74S0dJnNA%40mail.gmail.com <
https://groups.google.com/d/msgid/jsr371-users/CAEXeC6zJZYaCtRYeicnOLqvGka1oZFHO2e1%3D%3Dj-F%3D74S0dJnNA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/jsr371-users/CADO3JtkCHSuecWyC_%3DSXe2tYC3m%3D__yZs1nOT0NgiyZasKLinw%40mail.gmail.com <
https://groups.google.com/d/msgid/jsr371-users/CADO3JtkCHSuecWyC_%3DSXe2tYC3m%3D__yZs1nOT0NgiyZasKLinw%40mail.gmail.com?utm_medium=email&utm_source=footer>.