0

After reading multiple post about it, invoking my bean method at page load is just not working.

Here is a sample of my facelet :

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

    <h:head>
        <title>foo</title>
    </h:head>

    <h:body>
        <ui:composition template="resources/template/mainTemplate.xhtml">
            <f:metadata>
                <f:viewAction action="#{myBean.createObject}" />
            </f:metadata>   
            <ui:define name="header">
                <!-- Bunch of outputTexts -->
            </ui:define>
            <ui:define name="body">
                <!-- Bunch of outputTexts -->
            </ui:define>
            <ui:define name="footer">
                <!-- Bunch of outputTexts -->
            </ui:define>
        </ui:composition>
    </h:body>
</html>

My template (mainTemplate.xhtml) :

<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html">

    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <h:outputStylesheet name="/css/default.css"/>
        <h:outputStylesheet name="/css/cssLayout.css"/>
        <title>#{msg['application.name']}</title>
    </h:head>

    <h:body>
        <div id="top">
            <ui:insert name="top">Top</ui:insert>
        </div>
        <div id="content" class="center_content">
            <ui:insert name="content">Content</ui:insert>
        </div>
        <div id="bottom">
            <ui:insert name="bottom">Bottom</ui:insert>
        </div>
    </h:body>
</html>

As well as my managed bean :

@Named(value = "orderDetailsBean")
@SessionScoped
public class OrderDetailsBean implements Serializable {

    @Inject
    Services services;
    private Order order;

    public OrderDetailsBean() {
        this.order = new Order();
    }

    public Order getOrder() {
        return order;
    }

    public void setOrder(Order order) {
        this.order = order;
    }

    public void createOrder() {
        // this method is not triggered at page load
    }
}

I'm using :

  • JSF 2.2
  • GlassFish 4.1.1
Max
  • 197
  • 4
  • 15
  • @JasperdeVries I know, I did read that post but the answer provided doesn't seem to work in my case. – Max Nov 18 '16 at 11:19
  • 1
    [JSF 2 facelets in template and page](http://stackoverflow.com/questions/7574115/jsf-2-facelets-fmetadata-in-template-and-page) – Jasper de Vries Nov 18 '16 at 11:23
  • Next time if you read multiple posts, keep track of which ones and why it did not work and post that in the question... As stated in [ask] – Kukeltje Nov 18 '16 at 11:45
  • In the future questions, please post a [mcve] based on instructions in http://stackoverflow.com/tags/jsf/info. You've there a template which you didn't show anywhere and thus adds a big red herring to the question because your problem is for us not reproducible without that template. Everything works just fine for us in a minimal project with everything set to bare defaults and using most recent versions. You should do the same and boil down your problematic code further to a real MCVE. – BalusC Nov 18 '16 at 11:59
  • @BalusC Sorry, I'm not too familiar with JSF so I wasn't sure what was relevent in the context of my question. I edited the post to give it a little bit more specification, I hope it helps ! – Max Nov 18 '16 at 12:25
  • it is always relevant in (almost) any context to post a [mcve]. Or rather, create one in the process of getting to the 'root cause' of your problem – Kukeltje Nov 18 '16 at 14:28

0 Answers0