带有glassfish服务器的eclipse ID中的jsf2 / primefaces5

时间:2014-08-13 10:48:20

标签: eclipse jsf-2 primefaces glassfish

我尝试在Java EE项目中使用primefaces。我将这个库的jar添加到我的web-inf> lib并在web.xml中集成代码但是当我运行项目时所有的balise p:都没有显示O.o

此代码取自primefaces5

的展示
<!DOCTYPE html >
<html lang="fr"
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:head>
    <title>Primefaces</title>
</h:head>
<h:body>

    <h:form>
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
    <p:outputLabel for="basic" value="Basic:" />
    <p:selectManyCheckbox id="basic" value="#{checkboxView.selectedConsoles}">
        <f:selectItem itemLabel="Xbox One" itemValue="Xbox One" />
        <f:selectItem itemLabel="PS4" itemValue="PS+" />
        <f:selectItem itemLabel="Wii U" itemValue="Wii U" />
    </p:selectManyCheckbox>

    <h:outputText value="Grid:" />
    <p:selectManyCheckbox id="grid" value="#{checkboxView.selectedCities}" layout="grid" columns="3">
        <f:selectItems value="#{checkboxView.cities}" var="city" itemLabel="#{city}" itemValue="#{city}" />
    </p:selectManyCheckbox>
</h:panelGrid>

<p:commandButton value="Submit" update="display" oncomplete="PF('dlg').show()" icon="ui-icon-check" />

<p:dialog header="Values" modal="true" showEffect="clip" widgetVar="dlg" resizable="false">
    <p:outputPanel id="display">
        <p:dataList value="#{checkboxView.selectedConsoles}" var="console">
            #{console}
        </p:dataList>
        <p:dataList value="#{checkboxView.selectedCities}" var="city">
            #{city}
        </p:dataList>
    </p:outputPanel>
</p:dialog>
 </h:form>
</h:body>
 </html>

我的豆子

package Bean;
  import java.util.ArrayList;
  import java.util.List;
  import javax.annotation.PostConstruct;
  import javax.faces.bean.ManagedBean;

  @ManagedBean
  public class CheckboxView {

   private String[] selectedConsoles; 
   private String[] selectedCities;  
   private List<String> cities;

    @PostConstruct
    public void init() {
    cities = new ArrayList<String>();
    cities.add("San Francisco");
    cities.add("London");
    cities.add("Paris");
    cities.add("Istanbul");
    cities.add("Berlin");
    cities.add("Barcelona");
    cities.add("Rome");
    cities.add("Sao Paulo");
    cities.add("Amsterdam");
}

public String[] getSelectedConsoles() {
    return selectedConsoles;
}

public void setSelectedConsoles(String[] selectedConsoles) {
    this.selectedConsoles = selectedConsoles;
}

public String[] getSelectedCities() {
    return selectedCities;
}

   public void setSelectedCities(String[] selectedCities) {
    this.selectedCities = selectedCities;
 }

     public List<String> getCities() {


     return cities;

  }



  }



  the web.xml

 <context-param>  
 <param-name>primefaces.THEME</param-name>  
 <param-value>south-street</param-value>  
  </context-param>
  <filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
  </filter-mapping>

1 个答案:

答案 0 :(得分:0)

你能分享一下你的web.xml文件吗?

它必须具有JSF的servlet定义和映射。

下面的元素必须存在于您的web.xml中:

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
 </servlet-mapping>

请注意* .xhtml表示Faces Servlet将处理扩展名为.xhtml的所有JSF文件,您必须将其更改为您定义的扩展名。

希望这会对你有所帮助。