简体   繁体   中英

JSF missing “javax/servlet/jsp/jstl/core/Config” on a xhtml file

I am working on panelgroup select menu that would only be visible if the first select Menu wasn't set as a "P" or as a "N". I found an example but before i can try it, I got an error stating

java.lang.NoClassDefFoundError: javax/servlet/jsp
/jstl/core/Config

Which is strange because I am sure i am using jsf 2.2 . the only jar file i have my project library is:

javax.faces-2.2.5.jar

Below is the section of new code i wrote based on a example I found.

<!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://xmlns.jcp.org/jsf/html"
   xmlns:f="http://java.sun.com/jsf/core" >


<h:body>
<h:form>    
<b>Blue tooth test: </b>  
     <h:selectOneMenu value="#{qcFormBean.dliStickerValue}">
     <f:selectItem itemValue="P" itemLabel="Pass" />
     <f:selectItem itemValue="N" itemLabel="N:A" />
     <f:selectItem itemValue="M" itemLabel="FAIL-Mechanical" />
     <f:selectItem itemValue="E" itemLabel="FAIL-Electrical" />
     <f:selectItem itemValue="C" itemLabel="FAIL-Cosmetic" />
     <f:selectItem itemValue="S" itemLabel="FAIL-Software" />
     <f:ajax event="change" execute="@this" render="perfbyDliSticker" />
</h:selectOneMenu>

<h:panelGroup id="perfbyDliSticker">
    <h:selectOneMenu value="#{qcFormBean.stickerFreq}"
                 rendered="#{!qcFormBean.dliStickerValue eq 'P' or !qcFormBean.dliStickerValue eq 'N'}">
<f:selectItem itemValue="O" itemLabel="Often" />
<f:selectItem itemValue="S" itemLabel="Seldom" />                
</h:selectOneMenu>


Is there something i am doing wrong or is the way i am trying to render this not JSF-ish or am i missing more files because I added these files before

jsf-api.jar jstl-1.2.jar jsf-impl.jar

but then i got a tomcat error in eclipse saying that the file is now a jsp file instead of a jsf file and needs to be added to the web.xml. So there must be some other way about this.

------Update------

Made changes to my code here is the update:

<h:selectOneMenu value="#{qcFormBean.dliStickerValue}">
<f:selectItem itemValue="P" itemLabel="Pass or Not applicable" />
<f:selectItem itemValue="M" itemLabel="FAIL-Mechanical" />
<f:selectItem itemValue="E" itemLabel="FAIL-Electrical" />
<f:selectItem itemValue="C" itemLabel="FAIL-Cosmetic" />
<f:selectItem itemValue="S" itemLabel="FAIL-Software" />
<f:ajax event="change" execute="@this" render="perfbyDliSticker" />
</h:selectOneMenu>

<h:panelGroup id="perfbyDliSticker">
<h:selectOneMenu value="#{qcFormBean.performedByRoleID}"
                 rendered="#{!qcFormBean.dliStickerValue eq  'P'}">
<f:selectItem itemValue="A" itemLabel="Always" />                
<f:selectItem itemValue="O" itemLabel="Often" />
<f:selectItem itemValue="S" itemLabel="Seldom" />                
</h:selectOneMenu>

--update 2_----- adding my web.xml to see if it helps.

 <?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns="http://java.sun.com/xml/ns/javaee"  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee                                               http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
     version="3.0">
  <servlet>
  <servlet-name>Faces Servlet</servlet-name>
  <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  </servlet>
  <servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
  <context-param>
  <param-name>javax.faces.PROJECT_STAGE</param-name>
  <param-value>Development</param-value>
  </context-param>
  <context-param>
  <description>State saving method: 'client' or 'server' (default). See JSF Specification section 2.5.2</description>
  <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
  <param-value>client</param-value>
  </context-param>
 <welcome-file-list>
<welcome-file>index.jsf</welcome-file>
<welcome-file>welcome.jsf</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>

The error tells that the class javax.servlet.jsp.jstl.core.Config is missing. This class is part of JSTL and is not provided by default on Tomcat.

You have to make sure the jstl-1.2.jar is present in your /WEB-INF/lib (together with the JSF api and impl jars).

See also:

a good structured xhtml could be something like this( <h:head>...</head> is important for jsf ajax):

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      >
<h:head>
    <meta charset="UTF-8" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <h:outputStylesheet name="stylesheet.css"/>
    <title>Test</title>    
</h:head>
<body>
<f:view> 
<h:outputText value="hello"></h:outputText>
.....
</f:view>
</body>
</html>

if you still have that error, try the following:

create a new Dynamic web Project in eclipse (Kepler EE):

1) menu item file -> new -> Dynamic web Project

2) then enter name for your Project

3) Target runtime (your tomcat server)

4) Modul Version 3.0

5) Configuration: Java Server Faces 2.2 Project

6) next-> next->, then select the checkbox "generate web.xml ..."

7) next -> JSF Implementation Library (Type: user Library): at the right side you see an icon for download(click it, and wait, you will get Mojarra 2.2 ...), select and install it, finish!

after that copy my above xhtml and test it in your Pages (don't forget to add your Faces Servlet pattern in the URL as in your web.xml)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM