Jersey Freemarker MVC - model-view-controller

I try to configure jersey-mvc-freemarker on TomEE 1.7.2. But I can't ...
Configure Jersey
#ApplicationPath("resources")
public class JerseyConfig extends ResourceConfig{
public JerseyConfig() {
packages("my.pack.controllers")
.property(MvcFeature.TEMPLATE_BASE_PATH, "/WEB-INF/classes/my/pack")
.register(org.glassfish.jersey.server.mvc.freemarker.FreemarkerMvcFeature.class);
}
}
Controller
#Path("main")
public class MainController {
#Inject
private TestBean bean;
#GET
public Viewable getIt() {
return new Viewable("test");
}
}
web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>ui</display-name>
</web-app>
I put my test.ftl to my.pack
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
test
</body>
</html>
When I go to http://localhost:8080/resources/main I get message
No message body writer has been found for response class Viewable.
Thanks you
UPDATE:
I configured tracing in Jersey and got:
javax.servlet.ServletException: Error processing webservice request
org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:98)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.NullPointerException
org.apache.openejb.server.cxf.rs.CxfRsHttpListener.doInvoke(CxfRsHttpListener.java:227)
org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:94)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat (TomEE)/7.0.62 (1.7.2) logs.

Related

Target Unreachable, identifier 'XXX' resolved to null - jakarta.el.PropertyNotFoundException

I'm new to Java and tried to follow this tutorial. Since it's outdated, I've made some changes to use newer versions:
Netbeans 14
Glassfish 6
Java EE7
Jakarta Faces 3
Mojarra 3.0.1
The tutorial consists of a form where a user submits a message and gets the total count. However, when I submit, I get
Any clue of what I'm missing?
Here are the Glassfish logs
When app runs
WELD-000411: Observer method [BackedAnnotatedMethod] public
org.glassfish.jersey.ext.cdi1x.internal.ProcessAllAnnotatedTypes.processAnnotatedType(#Observes
ProcessAnnotatedType, BeanManager) receives events for all
annotated types. Consider restricting events using #WithAnnotations or
a generic type with bounds.|#] WELD-000411: Observer method
[BackedAnnotatedMethod] public
org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(#Observes
ProcessAnnotatedType) receives events for all annotated types.
Consider restricting events using #WithAnnotations or a generic type
with bounds.|#] WELD-000411: Observer method [BackedAnnotatedMethod]
org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(#Observes
ProcessAnnotatedType, BeanManager) receives events for all
annotated types. Consider restricting events using #WithAnnotations or
a generic type with bounds.|#] WELD-000146:
BeforeBeanDiscovery.addAnnotatedType(AnnotatedType) used for class
com.ibm.jbatch.container.cdi.BatchProducerBean is deprecated from CDI
1.1!|#] Initializing Soteria 2.0.1 for context '/mavenproject1'|#] Initializing Mojarra 3.0.1 for context '/mavenproject1'|#]
Monitoring jndi:/server/mavenproject1/WEB-INF/faces-config.xml for
modifications|#] Loading application [mavenproject1] at
[/mavenproject1]|#] mavenproject1 was successfully deployed in 4,055
milliseconds.|#]
When I click submit
/index.xhtml #15,103 value="#{messageView.message.message}": Target
Unreachable, identifier 'messageView' resolved to null
jakarta.el.PropertyNotFoundException: /index.xhtml #15,103
value="#{messageView.message.message}": Target Unreachable, identifier
'messageView' resolved to null at
com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:64)
at
com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:69)
at
jakarta.faces.component.UIInput.getConvertedValue(UIInput.java:1040)
at jakarta.faces.component.UIInput.validate(UIInput.java:955) at
jakarta.faces.component.UIInput.executeValidate(UIInput.java:1232) at
jakarta.faces.component.UIInput.processValidators(UIInput.java:721)
at jakarta.faces.component.UIForm.processValidators(UIForm.java:217)
at
jakarta.faces.component.UIComponentBase.processValidators(UIComponentBase.java:901)
at
jakarta.faces.component.UIComponentBase.processValidators(UIComponentBase.java:901)
at
jakarta.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1254)
at
com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:49)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:72) at
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:159)
at
jakarta.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:681)
at jakarta.faces.webapp.FacesServlet.service(FacesServlet.java:437)
at
org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1540)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:119)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:611)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:550)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:75) at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:114)
at
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:199)
at
com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:440)
at
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:144)
at
org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:174)
at
org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:153)
at
org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:196)
at
org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:88)
at
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:246)
at
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:178)
at
org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:118)
at
org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:96)
at
org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:51)
at
org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:510)
at
org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:82)
at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:83)
at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:34)
at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:101)
at
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:535)
at
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:515)
at java.base/java.lang.Thread.run(Thread.java:833) Caused by:
jakarta.el.PropertyNotFoundException: Target Unreachable, identifier
'messageView' resolved to null at
com.sun.el.parser.AstValue.getTarget(AstValue.java:148) at
com.sun.el.parser.AstValue.getType(AstValue.java:62) at
com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:160)
at
org.jboss.weld.module.web.el.WeldValueExpression.getType(WeldValueExpression.java:93)
at
com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:62)
... 42 more
Here are some of the related files
index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!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://xmlns.jcp.org/jsf/core">
<h:head>
</h:head>
<h:body>
<f:view>
<h:form>
<h:outputLabel value="Message:"/><h:inputText value="#{messageView.message.message}"/>
<h:commandButton action="#{messageView.postMessage}" value="Post Message"/>
</h:form>
</f:view>
</h:body>
</html>
MessageView.java
package my.presentation;
import boundary.MessageFacade;
import entities.Message;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
#Named(value = "messageView")
#RequestScoped
public class MessageView {
#EJB
private MessageFacade messageFacade;
private Message message;
public MessageView() {
this.message = new Message();
}
public Message getMessage(){
return message;
}
public int getMessagesCount(){
return messageFacade.findAll().size();
}
public String postMessage(){
this.messageFacade.create(message);
return "theend";
}
}
faces-config.xml
<?xml version='1.0' encoding='UTF-8'?>
<faces-config xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-facesconfig_3_0.xsd"
version="3.0">
</faces-config>
beans.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
https://jakarta.ee/xml/ns/jakartaee/beans_3_0.xsd"
version="3.0" bean-discovery-mode="annotated">
</beans>
pom.xml
<dependencies>
<dependency>
<groupId>jakarta.faces</groupId>
<artifactId>jakarta.faces-api</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.5.1</version>
</dependency>
</dependencies>
glassfish-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<!--
Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->
<glassfish-web-app error-url="">
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</glassfish-web-app>
Already checked this and this with no luck.

How to make awesome font work in Spring Boot with PrimeFaces

I have sample Spring Boot project for PrimeFaces and looking for a way to make awesomefont to work as shown in PF Showcase.
So I created awesomefont-test.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!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://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Awesomefont Test</title>
</h:head>
<h:body>
<p:commandButton value="Edit" icon="fa fa-fw fa-edit" type="button"/>
</h:body>
</html>
and the result is (no icon)
I tried several things:
1.) web.xml
I created web.xml and I tried to put it next to faces-config.xml (which is in jsf-primefaces-spring-boot/src/main/resources/META-INF/).
I tried to put it to jsf-primefaces-spring-boot/src/main/resources/WEB-INF/ not working too.
I do not know how to check it is read.
content:
<?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">
<context-param>
<param-name>primefaces.FONT_AWESOME</param-name>
<param-value>true</param-value>
</context-param>
</web-app>
2.) SpringBootServletInitializer
package com.codenotfound.primefaces;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.support.SpringBootServletInitializer;
#SpringBootApplication
public class SpringPrimeFacesApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(SpringPrimeFacesApplication.class, args);
}
#Override
public void onStartup(ServletContext servletContext) throws ServletException {
servletContext.setInitParameter("primefaces.FONT_AWESOME", "true");
super.onStartup(servletContext);
}
}
source: How to set context-param in spring-boot
3.) application.properties
From same source I tried to set property in application.properties
server.context_parameters.primefaces.FONT_AWESOME=true
also I tried variant with
server.servlet.context-parameters.primefaces.FONT_AWESOME=true
4.) webjars
This is a workaround, I just wanted to give it a try.
I also tried to add webjars dependencies (and modify xhtml) as described here - http://www.littlebigextra.com/add-bootstrap-css-jquery-to-springboot-mvc/
but none of those approaches worked for me.
After defining the dependency in pom.xml:
<dependency>
<groupId>org.webjars</groupId>
<artifactId>font-awesome</artifactId>
<version>4.7.0</version>
</dependency>
You need to add config into application.yml:
jsf:
primefaces:
FONT_AWESOME: true
or if use application.properties add:
jsf.primefaces.FONT_AWESOME=true
You don't need to create a web xml, just add the dependency and in your application.properties add this:
jsf.primefaces.font-awesome=true
And if you what to configure a theme add this:
jsf.primefaces.theme= theme-name

Spring MVC Error 404 Bad Request Kotlin

I am using Kotlin for developing Spring MVC Application.
I have a simple form which when i submit, I am getting Error 404 bad Request. I am using Jetty server and Intellij Community Edition.I tried debugging but since i have never debugged a web application, it wasnt that helpful.
web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>frontDispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>frontDispatcher</servlet-name>
<url-pattern>/springkotlinmvc/*</url-pattern>
</servlet-mapping>
</web-app>
frontDispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context = "http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:annotation-config/>
<mvc:annotation-driven/>
<context:component-scan base-package="org.manya.kotlin"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
DataClasses.kt
package org.manya.kotlin
data class Address (val city : String, val state : String)
data class Student ( val name : String , val age : Int, val address : Address)
StudentController.kt
package org.manya.kotlin
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.*
import org.springframework.web.servlet.ModelAndView
#Controller
#RequestMapping("/student")
class StudentController
{
//#GetMapping("/student/form")
#GetMapping("form")
fun studentForm() : ModelAndView{
println("called from studentForm()")
return ModelAndView("form")
}
//#PostMapping("springkotlinmvc/student/submitted")
//#RequestMapping(value = "/student/submitted" , method = arrayOf(RequestMethod.POST))
//#RequestMapping("/submitted")
#PostMapping("/submitted")
fun submitted(#ModelAttribute("student") stud : Student) : ModelAndView {
println("called from submitted()")
return ModelAndView("submitted")
}
}
Here the method studentForm() is perfectly getting mapped to the view(form.jsp) but the method submitted is not getting mapped.
form.jsp
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="./submitted" method="post">
NAME : <input id="name"/>
AGE : <input id="age"/>
CITY : <input id="address.city"/>
STATE : <input id="address.state"/>
<input type="submit"/>
</form>
</body>
</html>
check your link 404 means not found ,it may cause by not pointing to root here ./submitted , change to ${pageContext.request.contextPath}/foo or configuration of WEB-INF location.
4×× Client Error
400 Bad Request
401 Unauthorized
402 Payment Required
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable
407 Proxy Authentication Required
408 Request Timeout
409 Conflict
410 Gone
411 Length Required
412 Precondition Failed
413 Payload Too Large
414 Request-URI Too Long
415 Unsupported Media Type
416 Requested Range Not Satisfiable
417 Expectation Failed
418 I'm a teapot
421 Misdirected Request
422 Unprocessable Entity
423 Locked
424 Failed Dependency
426 Upgrade Required
428 Precondition Required
429 Too Many Requests
431 Request Header Fields Too Large
444 Connection Closed Without Response
451 Unavailable For Legal Reasons
499 Client Closed Request
I found the mistake in my code and it was a small mistake but i was not aware of it because of my lack of knowledge in web domain.
In form.jsp, in the form I was giving id attribute to all the input elements. I changes those to the name and it was working fine.

Ajax poll does not work in my project

First of all, I'm sorry for my bad English.
I´m new working with JSF, so I am sure that this is really stupid question but I couldn't find any post that help me. I´m using ajax poll in my project because I need refresh components in the page. I founded an example in the primefaces 5 showcase. In this example there is a counter that increments every 3 seconds. I used the code of the example in the exactly same way but the counter never increments. I think that this could be a bad configuration that I used in my project. Also, its showed the next message in the Eclipse console (I don´t know if this has something to do with my problem):
Información: No state saving method defined, assuming default server
state saving
Here is my sorce code:
<!DOCTYPE HTML>
<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:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"></meta>
<title>Insert title here</title>
</h:head>
<h:body>
<h:form>
<h:outputText id="txt_count" value="#{globalCounterView.count}"/>
<p:poll interval="3" listener="#{globalCounterView.increment}" update="txt_count"/>
</h:form>
</h:body>
</html>
In the bean:
import java.io.Serializable;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.event.ActionEvent;
#ManagedBean
#ApplicationScoped
public class GlobalCounterView implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private int count;
public int getCount() {
return count;
}
public void increment(ActionEvent actionEvent) {
count++;
}
public void setCount(int count) {
this.count = count;
}
}
web.xml:
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>SAEGraph</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
In the end, the thing what I want to do is update a primeface component from backing bean periodically. Also, Can you tell me if exists any other way to do this not using poll ????
Thanks and sorry again for the bad english.
I'm using primefaces 5.0, Tomcat 7, Eclipse Version: 4, JDK 7
Just remove the argument in increment method.
public void increment(ActionEvent actionEvent) {
count++;
}
to:
public void increment() {
count++;
}

function not getting called in autocomplete jsf

I am new to jsf and trying to implement autocomplete box.
So here is what i did.
home.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition 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:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:form>
<rich:autocomplete mode="ajax" layout="table" autocompleteMethod="#{searchCity.searchCityByMatchChar}" autocompleteList="#{searchCity.listOfCity}"
var="city" fetchValue="#{city.cityName}">
<rich:column>
#{city.cityName}
</rich:column>
</rich:autocomplete>
</h:form>
</ui:composition>
SearchCity.java
package com.cheapesto.cheapbilly.model;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import com.cheapesto.cheapbilly.dto.City;
#ManagedBean(name = "searchCity")
#SessionScoped
public class SearchCity {
private List<City> listOfCity;
public List<City> getListOfCity() {
return listOfCity;
}
public void setListOfCity(List<City> listOfCity) {
this.listOfCity = listOfCity;
}
public List<City> searchCityByMatchCharforauto() {
City city1 = new City();
city1.setCityId(1l);
city1.setCityName("New York");
City city2 = new City();
city2.setCityId(1l);
city2.setCityName("New Jesrsey");
City city3 = new City();
city3.setCityId(1l);
city3.setCityName("Seattle");
List<City> listOfCity = new ArrayList<City>();
listOfCity.add(city1);
listOfCity.add(city2);
listOfCity.add(city3);
return listOfCity;
}
}
faces-config.xml
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
</faces-config>
I am getting error as :
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/MyFirstFaces] threw exception [/faces/home.xhtml: Property 'searchCityByMatchChar' not found on type com.cheapesto.cheapbilly.model.SearchCity] with root cause
javax.el.ELException: /faces/home.xhtml: Property 'searchCityByMatchChar' not found on type com.cheapesto.cheapbilly.model.SearchCity
at com.sun.faces.facelets.compiler.AttributeInstruction.write(AttributeInstruction.java:91)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:78)
at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:179)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:164)
I am not getting why it is considering method as a property. can someone please help me with correct changes and explanation.
RichFaces is not properly installed. Your RichFaces tag is basically interpreted as plain text, which is recognizable as UIInstructions in the stack trace:
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:78)
It's essentially the same problem as when you would do e.g.
<p>#{searchCity.searchCityByMatchChar}</p>
EL in template text is by default resovled as a property value expression, requiring a getter method.
Verify if you installed RichFaces right. It are 7 JAR files in /WEB-INF/lib.
There is not method searchCityByMatchChar on your bean. It's called searchCityByMatchCharforauto. This may be the root cause of your error.

Resources