0

I am trying to set a variable with viewparam but I can't seem to get the code to compile in 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.

<?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)
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user2130951
  • 2,601
  • 4
  • 31
  • 58

1 Answers1

2

Your major mistake is that JSP is a deprecated view technology and is clearly a wrong tool for new projects. It has been succeeded by facelets, which is the default view technology for JSF 2.0+ projects.

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).

The solution is straightforward: switch to facelets as the view technology.

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. Also see BalusC's comment to this answer and BalusC's answer to a similar question.

Community
  • 1
  • 1
skuntsel
  • 11,624
  • 11
  • 44
  • 67
  • @BalusC It is necessary to change the namespace to set up a JSF 2.2 view, isn't it? Or did I misinterpret the specification? – skuntsel Dec 10 '13 at 12:47
  • 1
    *"Developers are requested to use the values from the New URI column, **though both columns will work**."* Note that Mojarra 2.2.0/2.2.1 had a namespace bug wherein the new namespace didn't properly address all components. If upgrading Mojarra wasn't an option, using the old namespace would be the solution. See also among others http://stackoverflow.com/questions/18517384/fviewparam-doesnt-pass-required-parameter-when-new-xmlns-jcp-org-namespace-is/18517592#18517592 – BalusC Dec 10 '13 at 12:54
  • @BalusC Thank you for the information. I didn't read it thoroughly enough. – skuntsel Dec 10 '13 at 13:04