简体   繁体   English

元数据标记在jsf中不起作用

[英]metadata tag not working in jsf

I am trying to set a variable with viewparam but I can't seem to get the code to compile in eclipse. 我试图用viewparam设置一个变量,但我似乎无法获得在eclipse中编译的代码。 It seems like it's not finding the tags. 好像它没有找到标签。

I have the mojarra 2.2 used and I am inlcuding jsf-api-2.2.4 and impl also. 我使用了mojarra 2.2,我也参与了jsf-api-2.2.4和impl。

<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" version="2.0">
    <jsp:directive.page language="java"
        contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" />
    <jsp:text>
        <![CDATA[ <?xml version="1.0" encoding="UTF-8" ?> ]]>
    </jsp:text>
    <jsp:text>
        <![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ]]>
    </jsp:text>
<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:c="http://java.sun.com/jsp/jstl/core">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Insert title here</title>
</head>
<body>
<f:view>

test
<f:metadata>
        <f:viewParam name="id" value="#{bowlingEvent.ID}" />
    </f:metadata>

<h:form>
<h:inputText id="id" />
<h:commandButton id="button" value="Spara event" action="update">

</h:commandButton>
</h:form>

</f:view>
</body>
</html>
</jsp:root>

org.apache.jasper.JasperException: /update.jsp (line: 25, column: 13) No tag "metadata" 
defined in tag library associated with uri "http://java.sun.com/jsf/core"
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)

Your major mistake is that JSP is a deprecated view technology and is clearly a wrong tool for new projects. 您的主要错误是JSP是一种弃用的视图技术,显然是新项目的错误工具。 It has been succeeded by facelets, which is the default view technology for JSF 2.0+ projects. 它已经被facelets取代,这是JSF 2.0+项目的默认视图技术。

Some tags, namely the ones used by you like <f:metadata> and <f:viewParam> are not available in JSPs (see sections 10.4.1.3 and 2.5.5 of JSF 2.2 specification (JSR-344) respectively). 某些标记,即您使用的标记,如<f:metadata><f:viewParam> ,在JSP中不可用(分别参见JSF 2.2规范(JSR-344)的 10.4.1.3和2.5.5节)。

The solution is straightforward: switch to facelets as the view technology. 解决方案很简单:切换到facelets作为视图技术。

It is also requested to switch to using the new namespaces that have been proposed since JSF 2.2, namely http://java.sun.com should now become http://xmlns.jcp.org (see Preface, page 8 of JSF 2.2 specification (JSR-344) ), though both namespaces will work. 还要求切换到使用自JSF 2.2以来提出的新命名空间,即http://java.sun.com现在应成为http://xmlns.jcp.org (参见JSF 2.2第8页的前言) 规范(JSR-344) ),虽然两个命名空间都可以。 Also see BalusC's comment to this answer and BalusC's answer to a similar question . 另请参阅BalusC对此答案的评论以及BalusC对类似问题的回答

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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