I have created a simple XHTML file and a corresponding Java Bean. Inside the Java Bean, I generate an ArrayList with objects of my custom class "FilePreview", which is defined in a different package (I imported it into the Bean, of course). In my XHTML-File I use ui-repeat to iterate over the list and display each element. I try to access the properties of my objects using get-Methods.
My XHTML-File
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:b="http://bootsfaces.net/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<link href="css/stylesheet.css" rel="stylesheet" type="text/css" />
</h:head>
<body>
<ui:composition template="./template.xhtml">
<ui:define name="title">
Dateien
</ui:define>
<ui:define name="content">
<b:container>
<ui:repeat value="#{FileBean.files}" var="files">
<b:panel title="#{files.headline}" look="primary">
<h:outputText value="#{files.description}" />
</b:panel>
<b:alert class= "file" severity="success"><strong>#{files.headline}</strong><br></br> <span>#{files.description}</span></b:alert>
</ui:repeat>
</b:container>
</ui:define>
</ui:composition>
</body>
</html>
My JavaBean:
import de.unibremen.st.gradelog.model.FilePreview;
import java.util.ArrayList;
#ManagedBean(name = "FileBean")
#SessionScoped
public class FileBean implements Serializable {
// private DBHandler handler;
private ArrayList<FilePreview> files;
public void create() {
files = new ArrayList();
files.add(new FilePreview("Hausordnung",
"Anbei findet Ihr die aktualisierte Hausordnung. Bitte gründlich lesen!",
null, null, null));
}
public ArrayList getFiles() {
/**
* DBHandler.getFiles(userID);
*/
System.out.println("Lese die Dateien aus.");
create();
return files;
}
}
And finally, the class FilePreview:
package de.unibremen.st.gradelog.model.FilePreview
public class FilePreview {
private String headline, description, authorID, fileID;
private File file;
public FilePreview(String headline, String description, String authorID,
String fileID, File file) {
this.headline = headline;
this.description = description;
this.authorID = authorID;
this.fileID = fileID;
this.file = file;
}
public String getHeadline() {
return headline;
}
//... more simple getters and setters
}
Everything seems to work just find, but when I run the application and access my new page, I get the following error:
Schwerwiegend: Error Rendering View[/files.xhtml]
javax.el.ELException: /files.xhtml #51,82 value="#{FileBean.files}": java.lang.NoClassDefFoundError: de/unibremen/st/gradelog/model/FilePreview
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
at com.sun.faces.facelets.component.UIRepeat.getValue(UIRepeat.java:279)
at com.sun.faces.facelets.component.UIRepeat.getDataModel(UIRepeat.java:255)
...
Caused by: javax.el.ELException: java.lang.NoClassDefFoundError: de/unibremen/st/gradelog/model/FilePreview
at javax.el.BeanELResolver.getValue(BeanELResolver.java:368)
Do I have to make the class known to JSF in some way? I'm working with an existing JSF project, and when I tried to do the same thing with a new project, everything worked just fine.
Anyone got an idea what could cause this?
You have to generate a faces-config.xml file where you declare that your managed bean is FileBean. You have to do something like this:
enter image description here
Related
I have 2 questions here for the code below.
The first one is, how can I have an itemValue in selectItem for my selectOneRadio as a return value from a function? I know this is working for a normal itemValue, if I put just "0", it shows up on the next page, but any of the getCaseValueByIndex() returns nothing.
My second question is, instead of listing each selectItem one by one, can i dynamically create them? What I was thinking is creating a function called getCasesCount which would return the size of the cases array (in this case, its 6) and then run a for loop like so:
for (int i = 0; i < casesCount; i++) {
<f:selectItem itemValue="#{CustomBuild.getCaseValueByIndex(i)}" itemLabel="# {CustomBuild.getCaseKey(i)}"/>
}
So then what would happen is that would create the same code I have but dynamically so that If i added or removed items in my LinkedHashMap, the code would reflect those changes rather than crashing for an outofbounds or null pointer error.
index.xhtml
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="css/stylesheet.css" rel="stylesheet" type="text/css" />
<title>Jadestar's PC Solutions</title>
</head>
<body>
<h4>Please choose your components.</h4>
<h4>To be eligible for the system builder's discount,
you must select at least <span class ='highlight'> 1 </span> component from each category.</h4>
<br></br>
#{CustomBuild.initialize()}
<h3>Computer Case</h3>
<h:form>
<h:selectOneRadio value="#{CustomBuild.chosenCase}">
<f:selectItem itemValue="#{CustomBuild.getCaseValueByIndex(0)}" itemLabel="#{CustomBuild.getCaseKeyByIndex(0)}"/>
<f:selectItem itemValue="#{CustomBuild.getCaseValueByIndex(1)}" itemLabel="#{CustomBuild.getCaseKeyByIndex(1)}"/>
<f:selectItem itemValue="#{CustomBuild.getCaseValueByIndex(2)}" itemLabel="#{CustomBuild.getCaseKeyByIndex(2)}"/>
<f:selectItem itemValue="#{CustomBuild.getCaseValueByIndex(3)}" itemLabel="#{CustomBuild.getCaseKeyByIndex(3)}"/>
<f:selectItem itemValue="#{CustomBuild.getCaseValueByIndex(4)}" itemLabel="#{CustomBuild.getCaseKeyByIndex(4)}"/>
<f:selectItem itemValue="#{CustomBuild.getCaseValueByIndex(5)}" itemLabel="#{CustomBuild.getCaseKeyByIndex(5)}"/>
</h:selectOneRadio>
<br></br>
<h:commandButton id="submit" value="submit" action="responsePage" />
</h:form>
</body>
</html>
responsePage.xhtml
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="css/stylesheet.css" rel="stylesheet" type="text/css" />
<title>Response</title>
</head>
<body>
<h4><h:outputText escape="false" value="#{CustomBuild.chosenCase}"/></h4>
<h:form prependId="false">
<h:commandButton id="backButton" value="Back" action="index" />
</h:form>
</body>
</html>
CustomBuild.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Part1;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;
/**
*
* #author Administrator
*/
#ManagedBean(name = "CustomBuild")
#SessionScoped
public class CustomBuild implements Serializable {
LinkedHashMap <String, String> cases = new LinkedHashMap<String, String>();
String chosenCase;
public String getChosenCase() {
return chosenCase;
}
public void setChosenCase(String chosenCase) {
this.chosenCase = chosenCase;
}
public float getCaseValueByKeyFloat(String key) {
float caseValueByValue = Float.parseFloat(cases.get(key));
return caseValueByValue;
}
public String getCaseKeyByIndex(int index) {
Object newKey = cases.keySet().toArray()[index];
//String tempKey = getCaseValueByIndex(index);
//String newKey = getCaseKeyByValue(tempKey);
return newKey.toString();
}
public String getCaseValueByIndex(int index) {
String caseValue = (new ArrayList<String>(cases.values())).get(index);
return caseValue;
}
public void initialize() {
cases.put("59.95" ,"Eleo 500 $59.95");
cases.put("79.95" ,"Eleo 700 $79.95");
cases.put("99.95" ,"Star Maker $99.95");
cases.put("104.95" ,"Anzooc 1200 $104.95");
cases.put("119.95" ,"Eleo 900 $119.95");
cases.put("139.95" ,"Criticase 1000 $139.95");
}
public CustomBuild() {
System.out.println("Custom Computer");
}
}
You can create an object which holds your key and value pairs.
After that you can use a list of these objects in your bean and use the following code in the xhtmls:
<h:selectOneRadio value="#{CustomBuild.chosenCase}">
<f:selectItems value="#{CustomBuild.getCases}" var="case" itemValue="#{case.value}" itemLabel="#{case.key}" />
</h:selectOneRadio>
Note: if you use an object in selectItem's value, you will need a converter, and to set the proper value you will need a proper equals in your bean.
If you want to stick with the hashmap, here a possible solution for you:
<h:selectOneRadio value="#{CustomBuild.chosenCase}">
<f:selectItems value="#{CustomBuild.cases.keySet()}" var="key" itemValue="#{CustomBuild.getValueByKez(key)}" itemLabel="#{key}" />
</h:selectOneRadio>
I am trying to search a database that I have developed using JSF as the front end technology. I am getting an error saying the following:
Unable to find method [searchContractors] with [0] parameters
Here is the code that I have used. Can anyone tell me if there is something obvious that I am doing wrong because I can't understand why I am getting this error. Thanks for the help.
JSF code
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<head>
<title>Search</title>
</head>
<body>
<h:form id="searchForm">
<H2>Search</H2>
<H4>Please select the county that you live in.
</H4>
<table>
<tr>
<td><h:outputLabel for="county">
<h:outputText id="countyLabel" value="County" />
</h:outputLabel></td>
<td><h:selectOneMenu id="countyName"
value="#{searchBean.countyId}">
<f:selectItems value="#{registerBean.counties}" var="county"
itemLabel="#{county.name}" itemValue="#{county.id}" />
</h:selectOneMenu></td>
</tr>
<tr>
<td><h:commandButton id="searchContractors"
action="#{searchBean.searchContractors(searchBean.countyId)}">
<h:outputText value="Search Contractors" />
</table>
</h:form>
</body>
</html>
Java code
#ManagedBean
#SessionScoped
public class SearchBean implements Serializable {
private static final long serialVersionUID = -2107387060867715013L;
private static final String PERSISTENCE_UNIT_NAME = "NeedABuilderUnit";
private static EntityManagerFactory factory;
private int countyId;
public List<BusinessAccount> searchContractors(int countyId) {
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
List<BusinessAccount> contractorList = new ArrayList<BusinessAccount>();
em.getTransaction().begin();
Query myQuery = em.createQuery("SELECT u FROM BusinessAccount u WHERE u.county.id=:CountyId");
myQuery.setParameter("CountyId", countyId);
contractorList=myQuery.getResultList();
em.getTransaction().commit();
em.close();
return contractorList;
}
public int getCountyId() {
return countyId;
}
public void setCountyId(int countyId) {
this.countyId = countyId;
}
}
the following should work:
<ui:param name="countyId" value="#{searchBean.countyId}" />
...
<h:commandButton id="searchContractors"
action="#{searchBean.searchContractors(countyId)}">
I am working on some Java JSF and Richfaces 4 application, I'm new to all those technos, including Java, so everything you can tell me, even basics, could help me :) .
I have
an a4j:commandButton triggering a bean method through its actionListener attribute
This bean method publishes a list of ids on a topic called "updateGUI"
Back in the view file, there is an a4j:push, that listens to this "updateGUI" topic, with a child node a4j:ajax, with event "dataavailable"
These 3 points work. My only problem here is that I want the a4j:ajax to render ids contained in the javascript event.rf.data , but I didn't succeed in doing so. If I write ids by hand, instead of using the event.rf.data, they get rendered.
here is the xhtml :
<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" template="/templates/template.xhtml">
<ui:define name="title">RichFaces Sample</ui:define>
<ui:define name="body">
<a4j:push address="updateGUI">
<!-- here, instead of render="main butt0" (the added button and the parent node),
I'd like to use event.rf.data, a javascript variable containing the ids
I don't want to call a bean's getter, since the bean could have created/
updated/deleted other ids, and we could miss old updated ids, and also
getters are called multiple times (so can't make a FIFO of updated ids) -->
<a4j:ajax event="dataavailable" limitRender="true" render="main butt0" />
</a4j:push>
<h:form id="main">
<h:inputText value="#{pushtest.text}">
<a4j:ajax event="change" />
</h:inputText>
<a4j:commandButton value="create a new button!" actionListener="#{pushtest.makemodifthread}" />
<a4j:outputPanel id="status">
last updated ids: #{pushtest.logupdated_ids}
</a4j:outputPanel>
<br />
</h:form>
</ui:define>
</ui:composition>
and its templates/template.xhtml :
<!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:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j">
<h:head>
<title>RichFaces Application</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</h:head>
<h:body>
<ui:insert name="body">Default content</ui:insert>
</h:body>
</html>
here is the bean :
package unit1;
import java.util.Date;
import java.lang.Thread;
import java.lang.Runnable;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.richfaces.application.push.MessageException;
import org.richfaces.application.push.TopicKey;
import org.richfaces.application.push.TopicsContext;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.richfaces.component.UICommandButton;
import javax.faces.event.ActionEvent;
#ManagedBean
#ViewScoped
public class pushtest {
// from http://illegalargumentexception.blogspot.fr/2009/02/jsf-working-with-component-ids.html
private UIComponent findComponent(UIComponent c, String id) {
if (id.equals(c.getId())) {
return c;
}
java.util.Iterator<UIComponent> kids = c.getFacetsAndChildren();
while (kids.hasNext()) {
UIComponent found = findComponent(kids.next(), id);
if (found != null) {
return found;
}
}
return null;
}
public void makemodifthread(ActionEvent event) throws MessageException
{
UICommandButton butt = new UICommandButton();
updated_ids = "butt"+ count;
butt.setId("butt" + count);
count++;
butt.setValue(this.text);
UIComponent parent = findComponent(FacesContext.getCurrentInstance().getViewRoot(), "main");
parent.getChildren().add(butt);
updated_ids += " " + parent.getId();
TopicKey topicKey = new TopicKey("updateGUI");
TopicsContext topicsContext = TopicsContext.lookup();
topicsContext.publish(topicKey, updated_ids);
}
public String getLogupdated_ids()
{
System.out.println("LOG updated ids: " + log_updated_ids);
return (log_updated_ids);
}
public String getUpdated_ids()
{
System.out.println("updated ids: " + updated_ids);
if (!updated_ids.isEmpty())
{
log_updated_ids = updated_ids;
updated_ids = "";
return (log_updated_ids);
}
return (updated_ids);
}
public void setText(String text)
{
this.text = text;
}
public String getText()
{
return (text);
}
private String text = "button name";
private String updated_ids = "";
private String log_updated_ids = "";
private int count = 0;
}
Bye
Actually, I solved this problem in a more simple way, thanks to this : http://www.coderanch.com/t/562602/JSF/java/assign-JSF-Ajax-Render-attribute#post_text_2554972
FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add(target.getClientId());
In the bean, I can now add/update jsf nodes, without having to worries about websockets, id getters or other weird stuff.
edit : actually, this solution is not perfect, I needed to combine it with an a4j:push. More info next week!
This is my code: botoes.xhtml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h=" http://java.sun.com/jsf/html"
xmlns:f=" http://java.sun.com/jsf/core">
<h:head>
<title>K19 - Eventos</title>
</h:head>
<h:body>
<h:form>
<h:commandButton id="botao-jonas" value="Jonas" disabled="false" actionListener="#{BotaoBean.sorteiaBotao}" />
<h:commandButton id="botao-marcelo" value="Marcelo" disabled="true" actionListener="#{BotaoBean.sorteiaBotao}" />
<h:commandButton id="botao-rafael" value="Rafael" disabled="true" actionListener="#{BotaoBean.sorteiaBotao}" />
</h:form>
</h:body>
</html>
and BotaoBean.java:
import javax.faces.bean.ManagedBean;
import javax.faces.component.*;
import javax.faces.event.ActionEvent;
#ManagedBean(name="BotaoBean")
public class BotaoBean {
public void sorteiaBotao(ActionEvent event) {
UIComponent formulario = event.getComponent().getParent();
UIComponent botaoJonas = formulario.findComponent("botao-jonas");
UIComponent botaoMarcelo = formulario.findComponent("botao-marcelo");
UIComponent botaoRafael = formulario.findComponent("botao-rafael");
botaoJonas.getAttributes().put("disabled",true);
botaoMarcelo.getAttributes().put("disabled",true);
botaoRafael.getAttributes().put("disabled",true);
double numero = Math.random();
if (numero<1.0/3.0) {
botaoJonas.getAttributes().put("disabled",false);
} else if (numero<2.0/3.0) {
botaoMarcelo.getAttributes().put("disabled",false);
} else {
botaoRafael.getAttributes().put("disabled",false);
}
}
}
I run and gives the following exception:
javax.servlet.ServletException: /botoes.xhtml: Property 'sorteiaBotao'
not found on type BotaoBean
javax.faces.webapp.FacesServlet.service(FacesServlet.java:321)
I don't know how to solve. I did the same as tutorial example. Can anyone help me?
Thanks!
The exception indicates that the actionListener="#{BotaoBean.sorteiaBotao}" is been treated as a value expression instead of a method expression (it's looking for a property and thus it's trying to just print the value returned by a getter, which obviously doesn't exist at all; as the exception says).
This in turn indicates that the whole component and the attribute are not been recognized by the JSF renderer.
This in turn indicates that the h: tag library of the component isn't (properly) been declared.
And indeed, you've there a dangling space in the taglib URI:
xmlns:h=" http://java.sun.com/jsf/html"
This space doesn't belong there in the taglib URI. Fix it accordingly:
xmlns:h="http://java.sun.com/jsf/html"
Don't forget to do the same for f: tag library, it has also a misplaced space in its URI.
This question already has answers here:
Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable
(18 answers)
Closed 7 years ago.
I want to have a list box in JSF. I have written a simple code but it does not work. In demo page I see an empty box with out list and in user page I have error.
UserBean.java
#ManagedBean
#SessionScoped
public class UserBean implements Serializable{
public String favYear3;//list box
public String getFavYear3() {
return favYear3;
}
public void setFavYear3(String favYear3) {
this.favYear3 = favYear3;
}
public static class Year{
public String yearLabel;
public String yearValue;
public Year(String yearLabel, String yearValue){
this.yearLabel = yearLabel;
this.yearValue = yearValue;
}
public String getYearLabel(){
return yearLabel;
}
public String getYearValue(){
return yearValue;
}
}
public Year[] year3List;
public Year[] getFavYear3Value() {
year3List = new Year[3];
year3List[0] = new Year("Year3 - 2000", "2000");
year3List[1] = new Year("Year3 - 2010", "2010");
year3List[2] = new Year("Year3 - 2020", "2020");
return year3List;
}
}
demo.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:f="http://java.sun.com/jsf/core">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>first jsf page</title>
</head>
<h:body>
<h1>JSF 2 check example</h1>
<h:form>
<h:selectOneListbox value="#{UserBean.favYear3}">
<f:selectItems value="#{UserBean.favYear3Value}" var="y"
itemLabel="#{y.yearLabel}" itemValue="#{y.yearValue}" />
</h:selectOneListbox>
</h:form>
</h:body>
</html>
user.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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>second jsf page</title>
</head>
<h:body>
<h:outputText value="#{UserBean.favYear3}"/>
</h:body>
</html>
My problem: in demo page I have an empty box.
in user page the error is:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: javax.el.PropertyNotFoundException: /demo.xhtml #24,55 value="#{UserBean.favYear3}": Target Unreachable, identifier 'UserBean' resolved to null
javax.faces.webapp.FacesServlet.service(FacesServlet.java:321)
root cause
javax.faces.component.UpdateModelException: javax.el.PropertyNotFoundException: /demo.xhtml #24,55 value="#{UserBean.favYear3}": Target Unreachable, identifier 'UserBean' resolved to null
javax.faces.component.UIInput.updateModel(UIInput.java:848)
javax.faces.component.UIInput.processUpdates(UIInput.java:730)
javax.faces.component.UIForm.processUpdates(UIForm.java:268)
javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1109)
javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1109)
javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:1218)
com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:74)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
What is wrong?
Your managed bean name in EL is wrong. You've declared the bean as follows:
#ManagedBean
#SessionScoped
public class UserBean implements Serializable{
When you don't specify the name attribute of the #ManagedBean, then it will conform the Javabeans Naming Conventions default to the classname with 1st character lowercased like so userBean, but yet you're trying to reference them with the exact classname #{UserBean}. You need to fix this name accordingly as #{userBean}.
The faces-config.xml registration is unnecessary for JSF 2.x. Remove it.
You have to make your bean reachable/managed. For this, you can either
annotate it with a CDI (#Named) or a JSF (#ManagedBean) annotation:
#Named
#SessionScoped
public class UserBean implements Serializable{...}
or describe it in the faces-config.xml as a managed-bean like this:
<managed-bean>
<managed-bean-name>userBean</managed-bean-name>
<managed-bean-class>com.example.UserBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>