Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

jsf 2 - Primefaces Schedule is not displayed in Application

I got a problem with the Primefaces <p:schedule>.

It is not displayed in my Application which uses <ui:include> and <ui:composition> Tags. But if I place the Schedule in a Standalone Page without these Tag Combination, it works as expected.

My app.xhtml Page includes a Layout which is defined by the <p:Layout> Component. I define a Menu at the left side with a <f:ajax> Tag, so that a contentPanel get updated on each click in the menu.

One of these Pages which gets included, is the hldyplanning.xhtml - in this Page a <p:schedule> should be displayed. For testing I create a new site. The test.xhtml. I decide to implement the Primefaces ShowCase Example for testing it.

I hope that I'm doing something wrong and it is not a Bug or something like that.

Here's the app.xhtml:

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

    <f:view contentType="text/html">
        <h:head>
            <f:facet name="first">
                <meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
                <meta http-equiv="refresh" content="#{session.maxInactiveInterval};url=/LEAN" />
                <title>Lean - Menü</title> 
            </f:facet>
        </h:head>

        <h:body style="background: white;">

            <p:layout fullPage="true">

                <p:layoutUnit position="west" size="175" header="Menü" collapsible="true" style="background: wheat;">
                    <h:form id="frm_menu">
                        <f:ajax render=":contentPanel" execute="@this">
                            <p:menu model="#{appController.menu}" style="font-size: 12px; width: 96%" />                                
                        </f:ajax>
                    </h:form>
                </p:layoutUnit>

                <p:layoutUnit position="center" style="background: wheat;">
                    <h:panelGroup id="contentPanel">
                        <ui:include src="#{appController.content}.xhtml" />
                    </h:panelGroup>
                </p:layoutUnit>

            </p:layout>

            <p:growl autoUpdate="true" showDetail="true"/>

        </h:body>

    </f:view>
</html>

The appController.java

package lean.controller.view;


import java.util.Map;
import javax.annotation.PostConstruct;
import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletResponse;
import org.primefaces.model.DefaultMenuModel;
import org.primefaces.model.MenuModel;
import org.primefaces.component.menuitem.MenuItem;  
import org.primefaces.component.submenu.Submenu;  

@ManagedBean
@RequestScoped
public class AppController {

    private String content = "/app/includes/dashboard";

    private MenuModel menu;
    private Submenu submenu;
    private MenuItem item;

    final private String[] submenu_urlb = { "Urlaubsübersicht", "/app/includes/urlaubsubersicht", 
                                            "Urlaubsplanung", "/app/includes/hldyplanning", 
                                            "Abteilungsübersicht", "/app/includes/abt_ubersicht", 
                                            "Pers?nliche übersicht", "/app/includes/per_uberischt",
                                            "Urlaubsantr?ge", "/app/includes/urlaubsantrage"};

    FacesContext fc;
    ExpressionFactory exfactory;
    HttpServletResponse response;
    Map cookieMap;
    MethodExpression me;

    //<editor-fold defaultstate="collapsed" desc="GETTER UND SETTER">

    public MenuModel getMenu(){
        return menu;
    }

    public MethodExpression getMe() {
        return me;
    }

    public void setMe(MethodExpression me) {
        this.me = me;
    }

    public ExpressionFactory getExfactory() {
        return exfactory;
    }

    public void setExfactory(ExpressionFactory exfactory) {
        this.exfactory = exfactory;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public FacesContext getFc() {
        return fc;
    }

    public void setFc(FacesContext fc) {
        this.fc = fc;
    }

    public HttpServletResponse getResponse() {
        return response;
    }

    public void setResponse(HttpServletResponse response) {
        this.response = response;
    }

    public Map getCookieMap() {
        return cookieMap;
    }

    public void setCookieMap(Map cookieMap) {
        this.cookieMap = cookieMap;
    }

    //</editor-fold>



    /**
     *
     */
    @PostConstruct
    public void init() {

        setFc(FacesContext.getCurrentInstance());
        setResponse((HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse());
        setCookieMap(FacesContext.getCurrentInstance().getExternalContext().getRequestCookieMap());
        setExfactory(FacesContext.getCurrentInstance().getApplication().getExpressionFactory());


        menu = new DefaultMenuModel();

        //erstes Submenu erzeugen

        submenu = new Submenu();
        submenu.setLabel("Urlaubsplanung");

        for(int i = 0; i <= (submenu_urlb.length-1); i=i+2){
            item = new MenuItem();  
            item.setValue(submenu_urlb[i]);
            setMe(getExfactory().createMethodExpression( fc.getELContext(), "#{appController.doNav(""+submenu_urlb[i+1]+"")}", void.class, new Class[0]));
            item.setActionExpression(me);
            item.setUpdate(":contentPanel");
            submenu.getChildren().add(item);
        }

        menu.addSubmenu(submenu);

        //zweites Submenu erzeugen
        submenu = new Submenu();
        submenu.setLabel("Account");

        item = new MenuItem();  
        item.setValue("Dashboard");
        setMe(getExfactory().createMethodExpression( fc.getELContext(), "#{appController.doNav("/app/includes/dashboard")}", void.class, new Class[0]));
        item.setActionExpression(me);
        item.setUpdate(":contentPanel");
        submenu.getChildren().add(item);


        item = new MenuItem();  
        item.setValue("Ausloggen");
        setMe(getExfactory().createMethodExpression( fc.getELContext(), "#{appController.menuitem_logout()}", void.class, new Class[0]));
        item.setActionExpression(me);
        item.setUpdate(":contentPanel");
        submenu.getChildren().add(item);

        menu.addSubmenu(submenu);

    }

    public String menuitem_logout(){

        FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
        return "backToStart";

    }

    public void doNav(String nav){

        setContent(nav);

    }
}

The hldyplanning.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">
<ui:composition 
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

    <h:form id="frm_urlbubersicht">

        <p:panelGrid style="width: 100%;">
            <f:facet name="header">
                <p:row>
                    <p:column colspan="2" style="height:50px;">
                        Urlaubsplanung
                    </p:column>
                </p:row>
            </f:facet>
            <p:row>
                <p:column style="width: 420px;" colspan="1">
                    <p:panel style="font-size: 12px; width: 420px; position: relative; border: 1px solid gray">

                        <f:facet name="header">
                            Urlaubsantrag Formular
                        </f:facet>

                    <p:panelGrid id="pnl_userinfo" style="font-size: 12px; width: 400px; border: 1px solid gray">

                        <f:facet name="header">  
                            <p:row>
                                <p:column colspan="2">Pers?nliche Informationen</p:column>
                            </p:row>
                        </f:facet>
                        <p:row>
                            <p:column style="width:120px">
                                <h:outputText value="Name:"/>
                            </p:column>
                            <p:column>
                                <h:outputText value="#{loginController.sessionData.user_name}" />
                            </p:column>
                        </p:row>
                        <p:row>
                            <p:column style="width:120px">
                                <h:outputText value="Team:" />
                            </p:column>
                            <p:column>
                                <h:outputText value="#{loginController.sessionData.teams_name}" />
                            </p:column>
                        </p:row>
                    </p:panelGrid>
                    <br/>
                    <p:panelGrid id="pnl_time" style="font-size: 12px; width: 400px; border: 1px solid gray">
                        <f:facet name="header">  
                            <p:row>
                                <p:column colspan="2">Zeitraum</p:column>
                            </p:row>
                        </f:facet>
                        <p:row>
                            <p:column style="width:120px">
                                <p:outputLabel for="cld_startdate" value="Startdatum:" />
                            </p:column>
                            <p:column>
                                <p:calendar value="#{hldyPlanningController.startdate}" id="cld_startdate" showOn="button" pattern="dd.MM.yyyy" required="true" requiredMessage=""/>
                            </p:column>
                        </p:row>
                        <p:row>
                            <p:column style="width:120px">
                                <p:outputLabel for="cld_enddate" value="Enddatum:" />
                            </p:column>
                            <p:column>
                                <p:calendar value="#{hldyPlanningController.enddate}" id="cld_enddate" showOn="button" pattern="dd.MM.yyyy" required="true" requiredMessage=""/>
                            </p:column>             
                        </p:row>
                    </p:panelGrid>
                    <br/>
                    <p:panelGrid id="pnl_misc" style="font-size: 12px; width: 400px; border: 1px solid gray">
                        <f:facet name="header"&gt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Problem Solved:

Search in your Application for Menuitems or Components which uses Ajax. If you don't need it, disable Ajax with ajax="false" and your <p:schedule> is displayed.

Source


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...