1

just a question....don't know if I did it right or if this will not work by specs. I've made a simple facelets master template, like this:

template.xhtml

    <html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <f:view>
        <ui:insert name="metadata" />

        <h:head>    

....  here the rest of template with other <ui:insert>

The client is simple and uses the template:

main.xhtml

<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                template="./WEB-INF/template/template.xhtml">

    <ui:define name="metadata">        
        <ui:include src="./WEB-INF/template/securityCheck.xhtml" />
    </ui:define>

... here goes the rest with other <ui:define> and <ui:include> ....

In the securityCheck.xhtml lies the simple f:viewAction as follow:

securityCheck.xhtml

<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                xmlns:f="http://xmlns.jcp.org/jsf/core">

    <f:metadata>
        <f:viewAction action="#{loginController.doLoginCheck()}" />
    </f:metadata>
</ui:composition>

Well, in this cas the f:viewAction is not ivoked, instead if I expand into metadata section the code directly, as follow:

main.xhtml

<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                template="./WEB-INF/template/template.xhtml">

    <ui:define name="metadata">        
        <f:metadata>
            <f:viewAction action="#{loginController.doLoginCheck()}" />
        </f:metadata>
    </ui:define>

... here goes the rest with other <ui:define> and <ui:include> ....

it works like a charm (as expected). Why is the inclusion of the metadata section into template client not working? And if there is a correct way to do this how can I add other f:viewAction calls after the included one? Something like this:

otherpage.xhtml

<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                template="./WEB-INF/template/template.xhtml">

    <ui:define name="metadata"> 
        <ui:include src="./WEB-INF/template/securityCheck.xhtml" />
        <f:metadata>
            <f:viewAction action="#{myBean.doSomething()}" />
        </f:metadata>
    </ui:define>

... here goes the rest with other <ui:define> and <ui:include> ....

If this is correct, are the calls made in this specific order?

I'm using JavaEE 7/JSF 2.2 with Glassfish 4.1 and Mojarra 2.2.12 impl.

Thank you.

crick77
  • 65
  • 8
  • Your technical problem is answered in the duplicate. However, your functional problem of authorization is solved the wrong way. Use a servlet filter instead. – BalusC Sep 29 '15 at 07:22
  • Thank you BalusC, I've read the other question/answer before but I didn't understand why I cannot include the fragment from an external file. For the security check I used a filter before this and now I'm experimentig this other tecnique that I find a little more "practical"...why it's not good? Thank you. – crick77 Sep 29 '15 at 08:01
  • You're tight coupling it to JSF instead of to HTTP/Servlet. Non-JSF requests will thus slip through. And, when you change the MVC framework, you have to reinvent everything again. – BalusC Sep 29 '15 at 08:04
  • So technically speaking it's not really wrong or there are some pitfalls? Or it's only less "flexible" in terms of reuse with other technologies? What worried me is if it will generate some security holes...that is. Instead, why the for f:viewAction is not working? Thank you so much. – crick77 Sep 29 '15 at 08:15
  • ...read multiple time the other answer and found it. My apologies @BalusC. Thank you for you're answer, always complete and clear. Think about writing a book... – crick77 Sep 29 '15 at 19:37

0 Answers0