Errors when the compiler is trying to build a custom JSP tag based on an Java Bean - jsp-tags

I am trying to use a custom tag in a jsp page but I get compilation errors so far.
Here is the custom jsp tag code along with the jsp page that is trying to use it.
address.tag
<%--
Document : address
Created on : Feb 21, 2012, 1:47:19 PM
Author : skiabox
--%>
<%#tag description="Address Input Field" pageEncoding="UTF-8"%>
<jsp:useBean id="addressBean" scope="session" class="com.ensode.netbeansbook.AddressBean" />
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%-- The list of normal or fragment attributes can be specified here: --%>
<%#attribute name="addressType" required="true"%>
<%-- any content can be specified here e.g.: --%>
<table border="0">
<tr>
<td>Line 1: </td>
<td>
<input type="text" size="20" name="${addressType}_line1" id="${addressType}_line1" value="${addressBean.line1}" />
</td>
</tr>
<tr>
<td>Line 2: </td>
<td>
<input type="text" size="20" name="${addressType}_line2" id="${addressType}_line2" value="${addressBean.line2}" />
</td>
</tr>
<tr>
<td>City: </td>
<td>
<input type="text" size="20" name="${addressType}_city" id="${addressType}_city" value="${addressBean.city}" />
</td>
</tr>
<tr>
<td>State: </td>
<td>
<select name="${addressType}_state" id="${addressType}_state">
<option value=""></option>
<option value="AL"
<c:if test="${addressBean.state == 'AL'}">selected</c:if> >
Alabama
</option>
<option value="AK"
<c:if test="${addressBean.state == 'AK'}">selected</c:if> >
Alaska
</option>
<option value="AZ"
<c:if test="${addressBean.state == 'AZ'}">selected</c:if> >
Arizona
</option>
<option value="AR"
<c:if test="${addressBean.state == 'AR'}">selected</c:if> >
Arkansas
</option>
<option value="CA"
<c:if test="${addressBean.state == 'CA'}">selected</c:if> >
California
</option>
</select>
</td>
</tr>
<tr>
<td>Zip: </td>
<td>
<input type="text" name="${addressType}_zip" id="${addressType}_zip" value="${addressBean.zip}" />
</td>
</tr>
</table>
index6.jsp
<%--
Document : index6
Created on : Feb 21, 2012, 3:25:43 PM
Author : skiabox
--%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%#taglib prefix="ct" tagdir="/WEB-INF/tags/" %>
<%#page import="com.ensode.netbeansbook.AddressBean" %>
<%
AddressBean addressBean = new AddressBean();
addressBean.setAddressType("home");
addressBean.setLine1("123 Tennis Ct");
addressBean.setCity("Phoenix");
addressBean.setState("AZ");
addressBean.setZip("85001");
session.setAttribute("addressBean", addressBean);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form>
<ct:address addressType="home"/>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="width: 65px;"></td>
<td>
<input type="submit" value="Submit" />
</td>
</tr>
</table>
</form>
</body>
</html>
AddressBean.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.ensode.netbeansbook;
/**
*
* #author skiabox
*/
public class AddressBean {
private String addressType;
private String line1;
private String line2;
private String city;
private String state;
private String zip;
public String getAddressType() {
return addressType;
}
public void setAddressType(String addressType) {
this.addressType = addressType;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getLine1() {
return line1;
}
public void setLine1(String line1) {
this.line1 = line1;
}
public String getLine2() {
return line2;
}
public void setLine2(String line2) {
this.line2 = line2;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
}
And here is the error log that Netbeans give me when it tries to compile the custom tag :
org.apache.jasper.JasperException: PWC6033: Error in Javac compilation
for JSP
PWC6197: An error occurred at line: 48 in the jsp file:
/WEB-INF/tags/address.tag PWC6199: Generated servlet error:
string:///address_tag.java:215: cannot access
javax.servlet.jsp.jstl.core.ConditionalTagSupport class file for
javax.servlet.jsp.jstl.core.ConditionalTagSupport not found
PWC6197: An error occurred at line: 48 in the jsp file:
/WEB-INF/tags/address.tag PWC6199: Generated servlet error:
string:///address_tag.java:216: cannot find symbol symbol : method
setPageContext(javax.servlet.jsp.PageContext) location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6197: An error occurred at line: 48 in the jsp file:
/WEB-INF/tags/address.tag PWC6199: Generated servlet error:
string:///address_tag.java:217: cannot find symbol symbol : method
setParent() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6197: An error occurred at line: 48 in the jsp file:
/WEB-INF/tags/address.tag PWC6199: Generated servlet error:
string:///address_tag.java:219: cannot find symbol symbol : method
doStartTag() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6199: Generated servlet error: string:///address_tag.java:223:
cannot find symbol symbol : method doAfterBody() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6199: Generated servlet error: string:///address_tag.java:228:
cannot find symbol symbol : method doEndTag() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6199: Generated servlet error: string:///address_tag.java:229:
reuse(javax.servlet.jsp.tagext.Tag) in
org.apache.jasper.runtime.TagHandlerPool cannot be applied to
(org.apache.taglibs.standard.tag.rt.core.IfTag)
PWC6199: Generated servlet error: string:///address_tag.java:232:
reuse(javax.servlet.jsp.tagext.Tag) in
org.apache.jasper.runtime.TagHandlerPool cannot be applied to
(org.apache.taglibs.standard.tag.rt.core.IfTag)
PWC6197: An error occurred at line: 52 in the jsp file:
/WEB-INF/tags/address.tag PWC6199: Generated servlet error:
string:///address_tag.java:241: cannot find symbol symbol : method
setPageContext(javax.servlet.jsp.PageContext) location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6197: An error occurred at line: 52 in the jsp file:
/WEB-INF/tags/address.tag PWC6199: Generated servlet error:
string:///address_tag.java:242: cannot find symbol symbol : method
setParent() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6197: An error occurred at line: 52 in the jsp file:
/WEB-INF/tags/address.tag PWC6199: Generated servlet error:
string:///address_tag.java:244: cannot find symbol symbol : method
doStartTag() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6199: Generated servlet error: string:///address_tag.java:248:
cannot find symbol symbol : method doAfterBody() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6199: Generated servlet error: string:///address_tag.java:253:
cannot find symbol symbol : method doEndTag() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6199: Generated servlet error: string:///address_tag.java:254:
reuse(javax.servlet.jsp.tagext.Tag) in
org.apache.jasper.runtime.TagHandlerPool cannot be applied to
(org.apache.taglibs.standard.tag.rt.core.IfTag)
PWC6199: Generated servlet error: string:///address_tag.java:257:
reuse(javax.servlet.jsp.tagext.Tag) in
org.apache.jasper.runtime.TagHandlerPool cannot be applied to
(org.apache.taglibs.standard.tag.rt.core.IfTag)
PWC6197: An error occurred at line: 56 in the jsp file:
/WEB-INF/tags/address.tag PWC6199: Generated servlet error:
string:///address_tag.java:266: cannot find symbol symbol : method
setPageContext(javax.servlet.jsp.PageContext) location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6197: An error occurred at line: 56 in the jsp file:
/WEB-INF/tags/address.tag PWC6199: Generated servlet error:
string:///address_tag.java:267: cannot find symbol symbol : method
setParent() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6197: An error occurred at line: 56 in the jsp file:
/WEB-INF/tags/address.tag PWC6199: Generated servlet error:
string:///address_tag.java:269: cannot find symbol symbol : method
doStartTag() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6199: Generated servlet error: string:///address_tag.java:273:
cannot find symbol symbol : method doAfterBody() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6199: Generated servlet error: string:///address_tag.java:278:
cannot find symbol symbol : method doEndTag() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6199: Generated servlet error: string:///address_tag.java:279:
reuse(javax.servlet.jsp.tagext.Tag) in
org.apache.jasper.runtime.TagHandlerPool cannot be applied to
(org.apache.taglibs.standard.tag.rt.core.IfTag)
PWC6199: Generated servlet error: string:///address_tag.java:282:
reuse(javax.servlet.jsp.tagext.Tag) in
org.apache.jasper.runtime.TagHandlerPool cannot be applied to
(org.apache.taglibs.standard.tag.rt.core.IfTag)
PWC6197: An error occurred at line: 60 in the jsp file:
/WEB-INF/tags/address.tag PWC6199: Generated servlet error:
string:///address_tag.java:291: cannot find symbol symbol : method
setPageContext(javax.servlet.jsp.PageContext) location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6197: An error occurred at line: 60 in the jsp file:
/WEB-INF/tags/address.tag PWC6199: Generated servlet error:
string:///address_tag.java:292: cannot find symbol symbol : method
setParent() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6197: An error occurred at line: 60 in the jsp file:
/WEB-INF/tags/address.tag PWC6199: Generated servlet error:
string:///address_tag.java:294: cannot find symbol symbol : method
doStartTag() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6199: Generated servlet error: string:///address_tag.java:298:
cannot find symbol symbol : method doAfterBody() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6199: Generated servlet error: string:///address_tag.java:303:
cannot find symbol symbol : method doEndTag() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6199: Generated servlet error: string:///address_tag.java:304:
reuse(javax.servlet.jsp.tagext.Tag) in
org.apache.jasper.runtime.TagHandlerPool cannot be applied to
(org.apache.taglibs.standard.tag.rt.core.IfTag)
PWC6199: Generated servlet error: string:///address_tag.java:307:
reuse(javax.servlet.jsp.tagext.Tag) in
org.apache.jasper.runtime.TagHandlerPool cannot be applied to
(org.apache.taglibs.standard.tag.rt.core.IfTag)
PWC6197: An error occurred at line: 64 in the jsp file:
/WEB-INF/tags/address.tag PWC6199: Generated servlet error:
string:///address_tag.java:316: cannot find symbol symbol : method
setPageContext(javax.servlet.jsp.PageContext) location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6197: An error occurred at line: 64 in the jsp file:
/WEB-INF/tags/address.tag PWC6199: Generated servlet error:
string:///address_tag.java:317: cannot find symbol symbol : method
setParent() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6197: An error occurred at line: 64 in the jsp file:
/WEB-INF/tags/address.tag PWC6199: Generated servlet error:
string:///address_tag.java:319: cannot find symbol symbol : method
doStartTag() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6199: Generated servlet error: string:///address_tag.java:323:
cannot find symbol symbol : method doAfterBody() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6199: Generated servlet error: string:///address_tag.java:328:
cannot find symbol symbol : method doEndTag() location: class
org.apache.taglibs.standard.tag.rt.core.IfTag
PWC6199: Generated servlet error: string:///address_tag.java:329:
reuse(javax.servlet.jsp.tagext.Tag) in
org.apache.jasper.runtime.TagHandlerPool cannot be applied to
(org.apache.taglibs.standard.tag.rt.core.IfTag)
PWC6199: Generated servlet error: string:///address_tag.java:332:
reuse(javax.servlet.jsp.tagext.Tag) in
org.apache.jasper.runtime.TagHandlerPool cannot be applied to
(org.apache.taglibs.standard.tag.rt.core.IfTag)
/Users/skiabox/NetBeansProjects/simplewebapp2/nbproject/build-impl.xml:612:
Java returned: 1 BUILD FAILED (total time: 2 seconds)
As you can see the first error occurs when the code is trying to access addressBean.state
Any ideas on how to fix that or what am I doing wrong?
Thank you.

I know it is very late (over 3 years) to answer this question. I have also had this problem. Apparently the solution is "Clean and Build Project" or press SHIFT+F11 and run again the project.

Related

Equivalent of JSP scriptlet method call in JSF

I need to convert a JSP file to an equivalent JSF file. The JSP is as follows:
Step 1: Class Import:
<%# page import="org.keycloak.constants.ServiceUrlConstants" %>
<%# page import="org.keycloak.common.util.KeycloakUriBuilder" %>
<%# page session="false" %>
<html>
Step 2: Define a variable:
<%
String logoutUri = KeycloakUriBuilder.fromUri("/auth").path(ServiceUrlConstants.TOKEN_SERVICE_LOGOUT_PATH).queryParam("redirect_uri", "/customer-portal").build("demo").toString(); %>
Step 3: Then refers to this variable:
logout
The imported library is an external library into the project. In JSF, I know how to do Step 3. But I don't know how to import the classes in Step 1 and how to define a variable as shown in Step 2 in JSF.
Is there an equivalent way of performing Step 1-3 in JSF? Thank you.
You can't call Methods directly in JSF or create variables, therefore you don't need imports.
The only way is to use EL-Expressions.
Since calling static Methods is not possible with EL, you'll have to create yourself a Bean, that makes the call of KeycloakUriBuilder.fromUri...
With a Named Bean you call its Methods:
Example:
import java.io.Serializable;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
//This Bean is available by default under the Name 'myBean', you can change it in the #Named Annotation if desired
#Named
#RequestScoped
public class MyBean implements Serializable {
public String myMethod(String inupt){
return "Hello " + input;
}
}
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core" >
<head></head>
<body>
<h:outputText value ="#{myBean.myMethod('world')}"/>
</body>
</html>
Will give you this HTML:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>Hello world
</body>
</html>
The preferred way to show Something on the page is to use getters and setters, if you have a field with getter and Setter
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
You can just use
#{myBean.name}
JSF will call the getter if it needs the value (for output) or call the Setter if there is a value to set (from input-fields)
The <%# page session="false" %> is also neither needed nor possible.
In JSF the Bean has a Scope, this example with RequestScoped should be a good match for <%# page session="false" %> - a Request Scoped Bean lives only for one Request, after that the Bean is disposed. There are many other scopes, e.g. #SessionScoped (from javax.enterprise.context) for a Bean that lives as long as the Session is active.
As mentioned by another User, those Scopes exists in the CDI-Variant (Package javax.enterprise.context) and a JSF-variant (package javax.faces.bean). You should use the CDI-Variant, since the JSF-Variant might be deprecated soon (see here).
Explanation of the Scopes see here.

Managed bean not found when upgrading to Mojarra 2.2.8-07 or newer

I use Spring Boot, JSF, PrimeFaces.
Right now, I can't update my application to new JSF 2.2.12.
Everything works properly for example with JSF 2.2.8-06 and PrimeFaces 5.2 but starting from JSF 2.2.8-07 and up to 2.2.12 version I can't reach my ManagedBean from XHTML page.
What was changed from JSF 2.2.8-07+ version and how to fix it ?
My bean:
#ManagedBean
#ViewScoped
public class HelloBean implements Serializable {
private static final long serialVersionUID = 8569928214435846079L;
public String getHello() {
return "Hello from PrimeFaces and Spring Boot!";
}
}
index.xhtml:
<f:view xmlns="http://www.w3c.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:ng="http://xmlns.jcp.org/jsf/passthrough"
xmlns:prime="http://primefaces.org/ui">
<h:head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>Title</title>
<style>
body {font-size:12px; }
</style>
</h:head>
<h:body>
<h:form>
<prime:panel header="What do you see here?" >
<div style="height:50px">
This is a simple PrimeFaces 5 project running on Spring Boot 1.1.4.
</div>
</prime:panel>
<prime:panel header="JSF 2.2 Bean Access">
#{helloBean.hello}
</prime:panel>
</h:form>
</h:body>
</f:view>
WebInitializer:
#Configuration
public class WebInitializer extends SpringBootServletInitializer implements ServletContextAware {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
#Bean
public DispatcherServlet dispatcherServlet() {
DispatcherServlet dispatcherServlet = new DispatcherServlet();
dispatcherServlet.setThrowExceptionIfNoHandlerFound(true);
return dispatcherServlet;
}
#Bean
public ServletRegistrationBean servletRegistrationBean() {
FacesServlet servlet = new FacesServlet();
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(servlet, "*.xhtml");
servletRegistrationBean.setLoadOnStartup(1);
return servletRegistrationBean;
}
#Bean
public ServletListenerRegistrationBean<ConfigureListener> jsfConfigureListener() {
return new ServletListenerRegistrationBean<ConfigureListener>(new ConfigureListener());
}
#Override
public void setServletContext(ServletContext servletContext) {
servletContext.setInitParameter("com.sun.faces.forceLoadConfiguration", Boolean.TRUE.toString());
}
}
With JSF 2.2.8-06 everything works properly except following errors in the console:
2015-09-02 12:32:34 [localhost-startStop-1] ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 18 at position 32
2015-09-02 12:32:34 [localhost-startStop-1] ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 0 at position 33
2015-09-02 12:32:34 [localhost-startStop-1] ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 0 at position 34
2015-09-02 12:32:34 [localhost-startStop-1] ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 0 at position 35
2015-09-02 12:32:34 [localhost-startStop-1] ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 30 at position 36
2015-09-02 12:32:34 [localhost-startStop-1] ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 15 at position 98
2015-09-02 12:32:34 [localhost-startStop-1] ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 0 at position 101
2015-09-02 12:32:34 [localhost-startStop-1] ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 97 at position 102
2015-09-02 12:32:34 [localhost-startStop-1] ERROR j.e.resource.webcontainer.jsf.config - Unknow type constant pool 15 at position 104
UPDATED
I got it working:
I have added resources/META-INF/faces-config.xml file:
<?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/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
<lifecycle>
<phase-listener>org.springframework.web.jsf.DelegatingPhaseListenerMulticaster</phase-listener>
</lifecycle>
</faces-config>
and also changed annotations in my HelloBean, not it looks like:
#Named
#ViewScoped
public class HelloBean implements Serializable {
private static final long serialVersionUID = 8569928214435846079L;
public String getHello() {
return "Hello from PrimeFaces and Spring Boot!";
}
}
Is it a proper way to go ? Is it a good idea to use #Named instead of #ManagedBean ?

new to Liferay , i am unable to navigate through Pages using renderURL

I am new to Liferay , i am unable to navigate through Pages using renderURL , please tell me where i am doing a mistake
I am struck here , i am not able to navigate to the Second Page during on click of an hyper link as shown below
This is my First Page , where i am showing the First Page ( view.jsp ) , But from view.jsp , i am unable to show view2.jsp
public class TestPortlet extends GenericPortlet {
public void doView(RenderRequest renderRequest,
RenderResponse renderResponse) throws IOException, PortletException {
renderResponse.setContentType("text/html");
PortletRequestDispatcher rd = getPortletConfig().getPortletContext()
.getRequestDispatcher("/html/test/view.jsp");
if (rd != null) {
rd.include(renderRequest, renderResponse);
}
}
}
This is my view.jsp
<%# taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
This is the <b>Sai Test Portlet</b> portlet in View mode.
<portlet:renderURL var="clickRenderURL">
<portlet:param name="jspPage" value="/html/test/view2.jsp" />
</portlet:renderURL>
Click here
This is my view2.jsp
<%# taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
This is the <b>View 2 </b> portlet in View mode.
There are no errros in console mode , and i am uisng Liferay 6.1 version .
Can you check the same using
"liferay-portlet:renderURL" tag.
Instead of using "portlet:renderURL" tag.
Rest all looks fine to me.

How to pass a value (selected from selectOneMenu)from page JSF to another

I want to fill an selectOneMenu with fields from my DataBase
and then use the chosen value in another request SQL.
For know I have my selectOneMenu filled from my data but I dont Know how to retrieve the chosen value and show it into another page. The error is:
org.apache.jasper.JasperException: An exception occurred processing JSP page /Result.jsp
Stacktrace:
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:553)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:442)
Also I want to write a clean code , I want to create class connection and use it to connect one time in the first page and deconnect at the last page(when I finish).
Bean:
public class BeanTools {
private List<SelectItem> mesElements;
private String maValeur;
public PreparedStatement st;
Connectionx con = new Connectionx(); **//IF I do that on N page I will have N connection!!**
Connection cx = (Connection) con.Connx();
public BeanTools() {
}
public String getMaValeur() {
return maValeur;
}
public void setMaValeur(String maValeur) {
this.maValeur = maValeur;
}
public void setMesElements(List<SelectItem> mesElements) {
this.mesElements = mesElements;
}
public Iterable<String> remplireItem() throws ClassNotFoundException, SQLException
{
String sql;
sql ="select issuestatus.pname from issuestatus;";
System.out.println("sql");
st=(PreparedStatement) cx.prepareStatement(sql);
ResultSet rs1 = st.executeQuery();System.out.println("execute");
String nbb;
ArrayList<String> list = new ArrayList<String>();
while(rs1.next())
{
nbb = rs1.getString("pname");
System.out.println(nbb);
list.add(nbb);
System.out.println("list"+list.toString());
}
return list;
}
public List<SelectItem> getMesElements() throws SQLException, ClassNotFoundException {
if (mesElements == null) {
mesElements = new ArrayList<SelectItem>();
for (String val : remplireItem()) {
mesElements.add(new SelectItem(val));
}
}
return mesElements;
}
}
First JSF page:
<h:form id="form">
Issue status 2 :<h:selectOneMenu style="width:200px" value="#{BeanTools.maValeur}" >
<f:selectItems value="#{BeanTools.mesElements}"/>
</h:selectOneMenu>
<h:commandButton action="submit" value="submit"/>
</h:form>
Second JSF page:
<body>
<h:outputText value="#{BeanTools.maValeur}" />
</body>
The Faces config:
<managed-bean>
<managed-bean-name>BeanTools</managed-bean-name>
<managed-bean-class>KPIs.BeanTools</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/welcomeJSF.jsp</from-view-id>
<navigation-case>
<from-outcome>submit</from-outcome>
<to-view-id>/Result.jsp</to-view-id>
</navigation-case>
</navigation-rule>
Class Connection:
public class Connectionx {
public Connection cx=null;
public Statement st;
public Connectionx() {}
public Connection Connx()
{
System.out.println("enregister le driver");
try {
Class.forName("com.mysql.jdbc.Driver");
}
catch( Exception ex )
{
System.err.println("Erreur lors du chargement du driver"+ex.getMessage() );
}
try {
/** Connection */
cx = (Connection) DriverManager.getConnection ( "jdbc:mysql://localhost/jiradb","","" );
}
catch( SQLException ex )
{
System. err. println( "Error ") }
return cx;
}
The whole stacktrace:
org.apache.jasper.JasperException: An exception occurred processing JSP page /Result.jsp at line 19
16: <body>
17: <h1>Hello World!</h1>
18:
19: <h:outputText value="#{BeanTools.maValeur}" />
20:
21: </body>
22: </html>
Stacktrace:
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:553)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:442)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:546)
at com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:363)
at com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:154)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: javax.servlet.ServletException: javax.servlet.jsp.JspException: java.lang.IllegalStateException: Component javax.faces.component.UIViewRoot#144c984 not expected type. Expected: javax.faces.component.UIOutput. Perhaps you're missing a tag?
at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:907)
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
at org.apache.jsp.Result_jsp._jspService(Result_jsp.java:84)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
... 38 more
Caused by: java.lang.IllegalStateException: Component javax.faces.component.UIViewRoot#144c984 not expected type. Expected: javax.faces.component.UIOutput. Perhaps you're missing a tag?
at com.sun.faces.taglib.html_basic.OutputTextTag.setProperties(OutputTextTag.java:126)
at javax.faces.webapp.UIComponentClassicTagBase.findComponent(UIComponentClassicTagBase.java:690)
at javax.faces.webapp.UIComponentClassicTagBase.doStartTag(UIComponentClassicTagBase.java:1311)
at com.sun.faces.taglib.html_basic.OutputTextTag.doStartTag(OutputTextTag.java:163)
at org.apache.jsp.Result_jsp._jspx_meth_h_005foutputText_005f0(Result_jsp.java:103)
at org.apache.jsp.Result_jsp._jspService(Result_jsp.java:73)
... 41 more
Finally, there's the root cause of the exception:
Caused by: java.lang.IllegalStateException: Component javax.faces.component.UIViewRoot#144c984 not expected type. Expected: javax.faces.component.UIOutput. Perhaps you're missing a tag?
You forgot the <f:view> in Result.jsp. All JSF components has to go inside a <f:view>. Edit your Result.jsp so that it look like the following basic template:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%#taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE html>
<f:view>
<html lang="en">
<head>
<title>JSP page</title>
</head>
<body>
<h:outputText value="JSF components here." />
</body>
</html>
</f:view>

JSPTag: Exception - This attribute does not support request time values

I am getting the "This attribute does not support request time values." while compiling my custom jsp tag implementation.
My TLD file
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>My Extension</shortname>
<info>Customization Extensions</info>
<tag>
<name>requireDisplay</name>
<tagclass>com.view.LinksTag</tagclass>
<teiclass>com.view.LinksTagExtraInfo</teiclass>
<bodycontent>JSP</bodycontent>
<info> My Tags Exercise
</info>
<attribute>
<name>viewID</name>
<required>true</required>
<rtexpvalue>true</rtexpvalue>
</attribute>
<attribute>
<name>viewType</name>
<required>true</required>
<rtexpvalue>true</rtexpvalue>
</attribute>
</tag>
</taglib>
My JSP Tag Implementation has the following method
/**
* doStartTag is called by the JSP container when the tag is encountered
*/
public int doStartTag() throws JspException {
try {
JspWriter out = pageContext.getOut();
out.println(getContent());
} catch (Exception ex) {
throw new ElmsUncheckedException(ex);
}
// Must return SKIP_PAGE because we are done with the content.
return SKIP_BODY;
}
/**
* getContent is called by the startTag to print the Request View button
* contents.
*/
private String getContent() {
String linkURL = ViewConstants.BASE_URL;
StringBuffer sbuffer = new StringBuffer();
sbuffer.append("<form name=\"postView\" action=\"" + linkURL + "\" target=\"_blank\" method=\"POST\">\n");
sbuffer.append("<input type=\"hidden\" name=\"ID\" value=\"" + viewID + "\" />\n");
sbuffer.append("<input type=\"hidden\" name=\"Type\" value=\"" + viewType + "\" />\n");
sbuffer.append("<tr>\n");
sbuffer.append("<td class=\"BodyBG\">\n");
sbuffer
.append("<button type=\"submit\" class=\"GridButton\" name=\"dispatch\" value=\"postView\">postView</button> \n");
sbuffer.append("</td><td width=\"1\"></td>\n");
sbuffer.append("</tr>\n");
sbuffer.append("</form>\n");
return sbuffer.toString();
}
public int doEndTag() throws JspException {
resetVariables();
return EVAL_PAGE;
}
my jsp has the following
<%# taglib uri="/WEB-INF/view.tld" prefix="cmd" %>
.....
<cmd:requireDisplay viewID="<%=vox.getViewID()%>" viewType="<%=vox.getViewType()%>"/>
But i am getting the following exception
[jspc] Error encountered while compiling 'jspURI'
view_details.jsp:136:22: The required attribute "viewID" is missing.
<cmd:requireDisplay viewID="<%=vox.getViewID()%>" viewType="<%=vox.getViewType()%>"/>
^----------------------^
view_details.jsp:136:22: The required attribute "viewType" is missing.
<cmd:requireDisplay viewID="<%=vox.getViewID()%>" viewType="<%=vox.getViewType()%>"/>
^----------------------^
view_details.jsp:136:42: This attribute does not support request time values.
<cmd:requireDisplay viewID="<%=vox.getViewID()%>" viewType="<%=vox.getViewType()%>"/>
^---------^
view_details.jsp:136:57: This attribute does not support request time values.
<cmd:requireDisplay viewID="<%=vox.getViewID()%>" viewType="<%=vox.getViewType()%>"/>
^----------^
Am i missing anything? As in the tld, even i tried to give TagExtraInfo too. But no luck.
Any help is much appreciated.
I figured out the issue.
It is a typo :(
<rtexpvalue>true</rtexpvalue>
entry suppose to be
<rtexprvalue>true</rtexprvalue>

Resources