Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 编程菜单不显示内容_Jsf_Jsf 2_Primefaces_Spring Boot - Fatal编程技术网

Jsf 编程菜单不显示内容

Jsf 编程菜单不显示内容,jsf,jsf-2,primefaces,spring-boot,Jsf,Jsf 2,Primefaces,Spring Boot,我正在使用SpringBoot和PrimeFaces5创建一个小应用程序 起初,我遵循一个教程,只在页面上显示一个编辑器和一个标题行,效果非常好。 然后我转到primefaces展示,并按照编程菜单的代码进行操作 我添加了两个菜单项和两个子菜单,如下所示: @Controller(value="navigation") @Scope(value = "session") public class NavigationComponent { private MenuModel model; @

我正在使用SpringBoot和PrimeFaces5创建一个小应用程序

起初,我遵循一个教程,只在页面上显示一个编辑器和一个标题行,效果非常好。 然后我转到primefaces展示,并按照编程菜单的代码进行操作

我添加了两个菜单项和两个子菜单,如下所示:

@Controller(value="navigation")
@Scope(value = "session")
public class NavigationComponent {

private MenuModel model;

@PostConstruct
public void init(){
    model = new DefaultMenuModel();
    //Home submenu
    DefaultSubMenu homeSubmenu = new DefaultSubMenu("Home");
    DefaultMenuItem item = new DefaultMenuItem("Home");
    item.setIcon("ui-icon-home");
    homeSubmenu.addElement(item);
    model.addElement(homeSubmenu);

    //Second submenu
    DefaultSubMenu secondSubmenu = new DefaultSubMenu("Second");
    item = new DefaultMenuItem("Show it");
    item.setUrl("www.google.com");
    item.setIcon("ui-icon-flag");
    secondSubmenu.addElement(item);
    model.addElement(secondSubmenu);
}

public MenuModel getModel() {
    return model;
}

public void setModel(MenuModel model){
    this.model = model;
}
}
并在index.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: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">

<h:head>
</h:head>
<h:body>
<h1>Hello World PrimeFaces</h1>
<h:form>
    <p:menu model="#{navigation.model}"/>
</h:form>
</h:body>
</html>
为了简单起见,我现在删除了这里的编辑器示例。编辑工作做得很好。但是导航栏没有显示任何内容。页面上只有一个空的银盒子

希望有人能帮助我


致以最良好的祝愿

实际上,我现在通过在配置中添加以下内容解决了这个问题

首先,我错过了以下内容:

@Bean
public ServletListenerRegistrationBean<ConfigureListener> jsfConfigureListener() {
    return new ServletListenerRegistrationBean<ConfigureListener>(
            new ConfigureListener());
}

@Bean
public ViewResolver getViewResolver(){
    InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    resolver.setPrefix("/WEB-INF/views/");
    resolver.setSuffix(".xhtml");
    return resolver;
}
其次,在src/main/resources/META-INF下,我必须添加文件faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javae/web-facesconfig_2_2.xsd"
          version="2.2">
<application>
    <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>
希望它能帮助别人


致以最诚挚的问候

是否正在执行init方法?您还可以尝试添加咆哮或消息组件以显示任何潜在错误;在那里,它出现在日志中。“咆哮”或“信息”组件是什么意思?