Ajax is not working with richfaces - java

I'm trying to use AJAX to change the content of my page and include some other contents, but it just does not work. I tried a lot of different solutions. I need that my menuItem_Cursos call that managed bean changePage and render the component panelGroup_Target. When i try to debug the java it just doesn't get there. Please help.
This is the page
<?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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>PenSAE</title>
<f:metadata>
<f:event listener="#{logon.verificaLogon}" type="preRenderView" />
</f:metadata>
<h:outputScript name="common.js" />
</h:head>
<h:body>
<f:view id="view_Principal">
<rich:toolbar id="toolbar_Principal" itemSeparator="">
<rich:menuItem id="menuItem_Cursos" label="Cursos" mode="ajax"
actionListener="#{principalProfessor.changePage}" render="panelGroup_Target"/>
<rich:menuItem id="menuItem_Estudos" label="Estudos de Casos"
value="Estudos de Casos" />
<rich:dropDownMenu id="dropDownMenu_Acompanhamento"
label="Acompanhamento" value="Acompanhamento" mode="ajax">
<rich:menuItem label="Acompanhamento por Estudante" />
<rich:menuItem label="Acompanhamento por Estudo de Caso" />
</rich:dropDownMenu>
<rich:dropDownMenu id="dropDownMenu_Sobre" label="Sobre o Sistema"
value="Sobre o Sistema">
<rich:menuItem label="Mapa do Software" />
<rich:menuItem label="Ajuda" />
</rich:dropDownMenu>
</rich:toolbar>
<h:panelGroup id="panelGroup_Target">
<rich:panel rendered="#{principalProfessor.page == 'listaCursos'}">
<ui:include src="#{principalProfessor.page}" />
</rich:panel>
</h:panelGroup>
</f:view>
</h:body>
</html>
And this is my java code:
package magicBeans.professor;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;
import classesBasicas.Curso;
import classesBasicas.Pessoa;
import fachada.Fachada;
/**
* #author Jesus
*
*/
#ManagedBean(name="principalProfessor")
#ViewScoped
public class PrincipalProfessorBean {
#SuppressWarnings("unused")
private static Fachada fachada;
private Pessoa usuarioLogado;
private Curso curso;
private String page = "";
public PrincipalProfessorBean(){
fachada = Fachada.getInstance();
}
/**
* #return the usuarioLogado
*/
public Pessoa getUsuarioLogado() {
return usuarioLogado;
}
/**
* #param usuarioLogado the usuarioLogado to set
*/
public void setUsuarioLogado(Pessoa usuarioLogado) {
this.usuarioLogado = usuarioLogado;
}
/**
* #return the curso
*/
public Curso getCurso() {
return curso;
}
/**
* #param curso the curso to set
*/
public void setCurso(Curso curso) {
this.curso = curso;
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
public void changePage() {
page = "listaCursos.xhtml";
System.out.println("AJAX PEGOU!");
}
}

Thanks to chrome (ctrl+shift+j) on chrome, the console told that it needed a form around anything with ajax to work. =]

Related

How to reference static variables using EL 3.0?

I am trying to get a static variable in my JSF page.
I followed instructions on this post. I am able to get the variables using the Primefaces extension, however, I am not getting anything in the xhtml when doing the following.
I have a constants file:
public class Test {
public static final String NAME = "EL Test";
}
And following the post by balusC, I added an application scoped bean (however, this is being called with every request):
import java.lang.reflect.Field;
import javax.annotation.PostConstruct;
import javax.el.ELContextEvent;
import javax.el.ELContextListener;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
#ManagedBean(eager = true)
#ApplicationScoped
public class Config {
#PostConstruct
public void init() {
FacesContext.getCurrentInstance().getApplication().addELContextListener(new ELContextListener() {
#Override
public void contextCreated(ELContextEvent event) {
event.getELContext().getImportHandler().importClass("my.package.constants.Test");
Class<?> clazz = event.getELContext().getImportHandler().resolveClass("Test");
for (Field field : clazz.getFields()) {
System.out.println(field.getName());
}
System.out.println("clazz = " + clazz);
System.out.println(clazz.getPackage());
}
});
}
}
And my xhtml page:
<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta charset="utf-8"></meta>
<meta http-equiv="X-UA-Compatible" content="IE=edge"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1"></meta>
</h:head>
<h:body>
<h:outputText value="#{Test}"></h:outputText>
<h:outputText value="#{Test.NAME}"></h:outputText>
</h:body>
</html>
Is there anything I am missing?
p:importConstants was added in PrimeFaces 6.x.
XHTML:
<p:importConstants type="com.example.Constants" var="Constants" />
<h:outputText value="#{Constants.TEST}" />
Java:
package com.example;
public class Constants {
public final static String TEST = "Imported Constant";
}
JSF 2.3 supports referencing static variables in EL using the f:importConstants tag.
Your constants file
public class Test {
public static final String NAME = "EL Test";
}
can be imported in the view by adding the following metadata.
<f:metadata>
<f:importConstants type="mypackage.Test" />
</f:metadata>
And then be referenced using EL.
#{Test.NAME}
So your view becomes:
<!DOCTYPE html >
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<f:metadata>
<f:importConstants type="mypackage.Test" />
</f:metadata>
<h:head>
<meta charset="utf-8"></meta>
<meta http-equiv="X-UA-Compatible" content="IE=edge"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1"> </meta>
</h:head>
<h:body>
<h:outputText value="#{Test.NAME}"></h:outputText>
</h:body>
</html>
Source: Arjan Tijms' Weblog.
You can use o:importConstants by omnifaces for that
For example:
public class Foo {
public static final String FOO1 = "foo1";
public static final String FOO2 = "foo2";
}
public interface Bar {
public String BAR1 = "bar1";
public String BAR2 = "bar2";
}
public enum Baz {
BAZ1, BAZ2;
}
The constant field values of the above types can be mapped into the request scope as follows:
<o:importConstants type="com.example.Foo" />
<o:importConstants type="com.example.Bar" />
<o:importConstants type="com.example.Baz" var="Bazzz" />
...
#{Foo.FOO1}, #{Foo.FOO2}, #{Bar.BAR1}, #{Bar.BAR2}, #{Bazzz.BAZ1}, #{Bazzz.BAZ2}
As I see you're using JSF 2, you could go with the Omnifaces library:
public class Test {
public static final String NAME = "EL Test";
}
Then in the facelet:
<o:importConstants type="com.example.Test " />
#{Test.NAME}
Otherwise, if you want to avoid using third party libraries, use an #ApplicationScoped managed bean with a getter for this aim:
#ManagedBean
#ApplicationScoped
public class Test{
public static final String name = "EL Test";
public String getName(){
return name;
}
}
Which you can reference with:
#{test.name}
See also:
The importConstants tag

Primefaces datatable onrowselect event doesn't work in IE 8

I'm trying to make the following code work in IE 8 with no result (though it works in Google chrome fine):
xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
</h:head>
<h:body>
<h:form id="form">
<p:dataTable id="eventsDT" var="answer" value="#{verify.answers}" rowKey="#{answer.id}" selectionMode="single" >
<p:ajax event="rowSelect" listener="#{verify.onRowSelectTest}" />
<p:column headerText="Id">
<h:outputText value="#{answer.id}" />
</p:column>
<p:column headerText="Text">
<h:outputText value="#{answer.text}" />
</p:column>
</p:dataTable>
</h:form>
</h:body>
</html>
Answer.java:
package ru.trust.appVerification;
public class Answer {
private int id;
private String text = "Undefined";
public Answer(int id, String text) {
this.id = id;
this.text = text;
}
public int getId() {
return id;
}
public String getText() {
return text;
}
public void setId(int id) {
this.id = id;
}
public void setText(String text) {
this.text = text;
}
}
Verify.java
package ru.trust.appVerification;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.*;
import java.util.stream.*;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.AjaxBehaviorEvent;
import org.primefaces.event.SelectEvent;
#ManagedBean
#ViewScoped
public class Verify implements Serializable {
public List<Answer> getAnswers() {
List<Answer> answers = new ArrayList<Answer>();
answers.add(new Answer(1, "Yes"));
answers.add( new Answer(2, "No"));
return answers;
}
public void onRowSelectTest(SelectEvent event) {
Answer answer = (Answer)event.getObject();
}
}
Is anything wrong in my code or Internet Explorer 8 does not support it at all?
Try adding this at the top of your 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"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<f:facet name="first">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
</f:facet>
// other head code goes here
</h:head>
in place of :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
</h:head>
I had a similar issue.Adding this worked fine for me.

Keep track of games played JSF

I was wondering if anyone can help me?
I am creating a simple game using JSF. I have managed to complete the main functionality but I would like to tell the user how many games they have played.
For some reason, the code I have written for it does not work.
Bean:
import java.util.Random;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
#ManagedBean
#SessionScoped
public class GameBeans {
private int randomNumber;
private int userGuess;
private int gamesPlayed;
public String getWin() {
if(this.userGuess == this.randomNumber)
{
return "Congratulations! You've Won!";
}
else
{
return "You Lose!";
}
}
/**
*
* #return randomNumber
*/
public int getRandomNumber() {
return randomNumber;
}
/**
* sets the generated random number
* #param randomNumber
*/
private void setRandomNumber(int randomNumber) {
this.randomNumber = randomNumber;
}
/**
*
* #return the guess of the user
*/
public int getUserGuess() {
return userGuess;
}
/**
* Sets the guess of the user into userGuess
* #param userGuess
*/
public void setUserGuess(int userGuess) {
this.userGuess = userGuess;
}
/**
*
* #return number of games played by the user
*/
public int getGamesPlayed()
{
return gamesPlayed;
}
private void setGamesPlayed(int played)
{
this.gamesPlayed=played;
}
/**
* Creates a new instance of GameBeans
* Generates a new random number
*
* Compares random number to user's
* choice
*
* Keeps total of games played
*/
public GameBeans() {
Random number = new Random();
int rNumber = number.nextInt(1000);
setRandomNumber(rNumber);
int played = this.gamesPlayed++;
setGamesPlayed(played);
}
}
First page (play_game.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">
<h:head>
<title>Guess Numbers Page</title>
</h:head>
<h:body>
<h:form>
<h1>Welcome to Your Game Session</h1>
<p>Number of games played this session: #{gameBeans.gamesPlayed}</p>
<p>Enter your lucky number guess and then click play</p>
<p>Your guess: <h:inputText id="iptxt1" value="#{gameBeans.userGuess}" /></p>
<h:commandButton id="cmdBtn1" value="Play" action="game_result" />
</h:form>
</h:body>
</html>
game_result.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">
<h:head>
<title>Game Results</title>
</h:head>
<h:body>
<h:form>
<p>Your Guess: <h:outputText id="outText1" value="#{gameBeans.userGuess}"></h:outputText></p>
<p>Random Number: <h:outputText id="outText2" value="#{gameBeans.randomNumber}"></h:outputText></p>
<p><h:outputText id="outText4" value="#{gameBeans.win}"></h:outputText></p>
<p>Number of Games Played: #{gameBeans.gamesPlayed}</p>
<h:commandButton id="cmdBtn1" value="Play Again" action="play_game" />
</h:form>
</h:body>
</html>
I would like to allow the user to play again even if they win or lose, the count (game played) should be kept track of. This is not working currently!
Can anyone help please??
Thanks
#SessionScoped bean is only created once when the client visit your page for the 1st time. It will then live until the end of the session. In other words, the constructor of your #SessionScoped bean is only called once. It's not the place to increment your gamesPlayed.
#ManagedBean
#SessionScoped
public class GameBeans {
private int randomNumber;
private int userGuess;
private int gamesPlayed;
public GameBeans() {
Random number = new Random();
this.randomNumber = number.nextInt(1000);
this.gamesPlayed = 0;
}
public void getWin() {
if (this.userGuess.equals(this.randomNumber))
return "Congratulations! You've Won!";
else return "You Lose!";
}
public void incrementGamesPlayed() {
this.gamePlayed++;
}
// Getters and Setters
}
And this is the play_game.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">
<h:head>
<title>Guess Numbers Page</title>
</h:head>
<h:body>
<h:form>
<h1>Welcome to Your Game Session</h1>
<p>Number of games played this session: #{gameBeans.gamesPlayed}</p>
<p>Enter your lucky number guess and then click play</p>
<p>Your guess: <h:inputText id="iptxt1" value="#{gameBeans.userGuess}" /></p>
<h:commandButton id="cmdBtn1" value="Play" action="game_result"
actionListener="#{gameBeans.incrementGamesPlayed}" />
</h:form>
</h:body>
</html>

ConversationScoped bean action not fired using a rendered commandlink

I'm having trouble understanding why a action method on my ConversationScope'd bean doesnt fire. The bean is:
package org.work;
import java.io.Serializable;
import javax.enterprise.context.ConversationScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Named;
#Named
#ConversationScoped
public class NewClass implements Serializable {
private static final long serialVersionUID = 6470665657635110586L;
private boolean b1;
public boolean isB1() {
return b1;
}
public void setB1(boolean b1) {
this.b1 = b1;
}
public void preRenderView(ComponentSystemEvent evt) {
}
public String peformAction() {
return null;
}
}
and my XHTML is:
<?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">
<f:view>
<h:head>
</h:head>
<f:metadata>
<f:viewParam name="b1"
value="#{newClass.b1}" />
<f:event type="preRenderView"
listener="#{newClass.preRenderView}"/>
</f:metadata>
<h:body>
<h:form>
<h:commandLink action="#{newClass.setB1(!newClass.b1)}"
style="background-color: #{newClass.b1 ? 'darkorchid' : 'aquamarine'};"
value="btn3"/>
<h:panelGrid rendered="#{newClass.b1}"
columns="1">
<h:commandLink value="edit"
action="#{newClass.peformAction()}" />
</h:panelGrid>
</h:form>
</h:body>
</f:view>
</html>
The performAction() method is not fired after I press the commandLink that should invert the boolean making the other commandLink rendered. When debugging I can see that the boolean is set to true, but it seems to me the "rendered" attribute is evaluated before the viewparams is set. Is this true?
The example works fine with #ManagedBean and #javax.faces.bean.ViewScoped.
I think that you don't have long-running conversation. You could read more information on this site: http://docs.oracle.com/javaee/6/api/javax/enterprise/context/ConversationScoped.html
If you have transient conversation this bean is recreated after every request

getting values from primefaces components

I have facelets page and managed bean that is associated with it.
i have used primefaces components and my problem is i want to get the values selected by the user of each components when a commandbutton is clicked.
when i try to write a JoptionPane or system.out.print it does not work. i have set the commandbutton action property to btnsearchFlight method whcih is found in the managedbean. so any one what is the problem what i am missing. Or an example will be very much appreciated.
Here is the Facelets page
<?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:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
<link href="./resources/css/cssLayout.css" rel="stylesheet" type="text/css" />
<title>Airline Travel Planner</title>
</h:head>
<h:body>
<h:form id="form">
<div id="top">
<ui:insert name="top">AirLine Travel Planner</ui:insert>
</div>
<div>
<div id="left">
<ui:insert name="left"></ui:insert>
</div>
<div>
<div id="right">
<ui:insert name="right"></ui:insert>
</div>
<div id="content" class="right_content" style="height: 500px">
<ui:insert name="content">
<p:selectOneRadio binding="#{calendarBean1.rdbTripType}" id="rdbTripType" value="#{calendarBean1.rdbTripType}">
<f:selectItem itemLabel="One Way" itemValue="1" />
<f:selectItem itemLabel="Round Trip" itemValue="2" />
</p:selectOneRadio>
<br/>
<h:outputLabel>From:</h:outputLabel>
<p:selectOneMenu value="#{calendarBean1.cityInfo}" style="" effect="fold" editable="true">
<f:selectItems value="#{calendarBean1.cityInfo}" />
</p:selectOneMenu>
<h:outputLabel style="position: relative">To:</h:outputLabel>
<p:selectOneMenu value="#{calendarBean1.cityInfo}" effect="fold" editable="true">
<f:selectItems value="#{calendarBean1.cityInfo}" />
</p:selectOneMenu>
<br/><br/>
<h:outputLabel>Depart On:</h:outputLabel>
<p:calendar value="#{calendarBean1.date3}" id="popupButtonDepartOn" showOn="button" />
<h:outputLabel>Arrive On:</h:outputLabel>
<p:calendar value="#{calendarBean1.date2}" id="popupButtonArriveOn" showOn="button" />
<br/> <br/>
<h:outputText value="Passenger Type" />
<p:selectOneMenu id="selectOneMenuPassengerType" binding="#{calendarBean1.selectOneMenuPassengerType}" value="#{calendarBean1.selectOneMenuPassengerType}" >
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItem itemLabel="Adult" itemValue="1" />
<f:selectItem itemLabel="Child" itemValue="2" />
<f:selectItem itemLabel="Infant" itemValue="3" />
</p:selectOneMenu>
<br/> <br/>
<p:selectBooleanCheckbox value="#{calendarBean1.lowestFareChecked}" />
<h:outputText value="Lowest Fare" />
<br/>
<p:commandButton id="btnSearchFlight" value="Search" action="#{calendarBean1.searchFlight}" >
</p:commandButton>
Here is the managed bean class
package test.sample;
import java.io.Serializable;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import javax.faces.bean.ManagedBean;
import javax.faces.model.SelectItem;
import javax.swing.JOptionPane;
import org.primefaces.component.commandbutton.CommandButton;
import org.primefaces.component.selectonemenu.SelectOneMenu;
import org.primefaces.component.selectoneradio.SelectOneRadio;
import storageMethods.FlightMethod;
/**
*
* #author Nati
*/
#ManagedBean(name = "calendarBean1")
public class CalendarBean1 implements Serializable{
/**
* Creates a new instance of CalendarBean1
*/
public CalendarBean1() {
}
private Date date1;
private Date date2;
private Date date3;
private boolean lowestFareChecked;
public boolean isLowestFareChecked() {
return lowestFareChecked;
}
public void setLowestFareChecked(boolean lowestFareChecked) {
this.lowestFareChecked = lowestFareChecked;
}
public Date getDate1() {
return date1;
}
public void setDate1(Date date1) {
this.date1 = date1;
}
public Date getDate2() {
return date2;
}
public void setDate2(Date date2) {
this.date2 = date2;
}
public Date getDate3() {
return date3;
}
public void setDate3(Date date3) {
this.date3 = date3;
}
private SelectOneRadio rdbTripType = new SelectOneRadio();
public SelectOneRadio getRdbTripType() {
return rdbTripType;
}
public void setRdbTripType(SelectOneRadio rdbTripType) {
this.rdbTripType = rdbTripType;
}
public CommandButton btnSearchFlight = new CommandButton();
public CommandButton getBtnSearchFlight() {
return btnSearchFlight;
}
public void setBtnSearchFlight(CommandButton btnSearchFlight) {
this.btnSearchFlight = btnSearchFlight;
}
private SelectOneMenu selectOneMenuPassengerType = new SelectOneMenu();
public SelectOneMenu getSelectOneMenuPassengerType() {
return selectOneMenuPassengerType;
}
public void setSelectOneMenuPassengerType(SelectOneMenu selectOneMenuPassengerType) {
this.selectOneMenuPassengerType = selectOneMenuPassengerType;
}
public ArrayList<SelectItem> CityInfo;
public ArrayList<SelectItem> getCityInfo() {
CityInfo = CityInfo();
return CityInfo;
}
public void setCityInfo(ArrayList<SelectItem> CityInfo) {
this.CityInfo = CityInfo;
}
public String SearchFlight() {
// JOptionPane.showMessageDialog(null, rdbTripType.getValue().toString());
// JOptionPane.showMessageDialog(null, selectOneMenuPassengerType.getValue().toString());
JOptionPane.showMessageDialog(null,date3);
// System.out.print("hi");
// System.out.print(isLowestFareChecked());
return null;
}
}
Maybe just a typo when posting on stackoverflow, but your method is Capitalized:
SearchFlight
And your action in .xhtml button is lowercase.
action="#{calendarBean1.searchFlight}
Shouldn't it be
public String searchFlight() {
I never used Swing components in a JSf franework. But the system.out should work when commented out. If you method is called. Don't you get any errors in your logs?
I think you mixed webapp development (JSF) with desktop development (Swing). With JSF you don't need to create a backing bean component for every single facelet component. You don't need
org.primefaces.component.commandbutton.CommandButton
org.primefaces.component.selectonemenu.SelectOneMenu
org.primefaces.component.selectoneradio.SelectOneRadio
in your bean if you only want to bind the input values of these components.
Of course in some situations you will get benefits from component binding but it is not necessary in your example.
In the facelet you use the value attribute and the binding attribute, but they have the same content.
If you are only interested in input values, the value attribute is all you need. Let this attribute point to a backing bean field that only will hold the value, e.g. an int or String.

Categories

Resources