Timeout via idlemonitor (primefaces) does not work - jsf-2

i want to use the idle monitor of primefaces for the session timeout.
Properly it works. But the redirect to my login-page (login.xhtml it doesn't work.
I use this the idle-monitor in my body of the template of my xhtml pages:
Template.xhtml
<p:idleMonitor timeout="1800000" >
<p:ajax event="idle" listener="#{pageServiceBean.timeout()}" oncomplete="alert('Die Session ist abgelaufen.')"/>
</p:idleMonitor>
The code of the pageServiceBean is:
PageServiceBean.xhtml
#ManagedBean
#SessionScoped
/**Die Page-Service Bean wird in der Fußzeile der Seite eingesetzt und beinhaltet den Zurück-Button bzw. den Logout Button*/
public class PageServiceBean implements Serializable{
/**
*
*/
private static final long serialVersionUID = 3251724422690388588L;
/**Leitet auf zur Auswahlseite zurück*/
public String cancel(){
return"/sampleForDB.xhtml";
}
/**Leitet zur Loginseite zurück*/
public String cancelSampleButton(){
return"/login.xhtml";
}
public void timeout() throws IOException {
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
FacesContext.getCurrentInstance().getExternalContext().redirect("...login.xhtml");
}
}
I have no redirect to the login.xhtml. But the user ist logged out. So the stuff is not valid any more. The to other function (cancel and cancelSampleButton) works. So they navigate to the correct page.
I looked at the answer from Answer in another post But that don't fixed my problem.
In this post the person speaks to set the time in the web.xml. But i don't no which code did i write in the xhtml.
And i don't know what does the three dots in the redirect method do FacesContext.getCurrentInstance().getExternalContext().redirect("...login.xhtml");
Any idea?

I found a solution.
in the xhtml-page PrimefacsIdleMonitor.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:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<body>
<h:form>
<p:growl id="msg" showDetail="true" sticky="true" />
<!-- nach 10 Sekunden wird der idelDialog gestartet -->
<p:idleMonitor timeout="10000" onidle="idleDialog.show()" />
<p:confirmDialog id="confirmDialog"
message="Die Session ist abgelaufen. Bitte klicke auf Ok um weiter zu arbeiten."
header="Session ist abgelaufen" severity="alert" widgetVar="idleDialog">
<p:commandButton id="confirm" value="Ok" update="msg"
oncomplete="idleDialog.hide()"
actionListener="#{pageServiceBean.welcomeListener}" />
<p:commandButton id="Logout" value="Abmelden" update="msg"
oncomplete="idleDialog.hide()"
actionListener="#{pageServiceBean.logoutListener}" />
</p:confirmDialog>
</h:form>
</body>
</html>
In any xhtml page where the idle-monitor is used:
<div id="idle">
<div id="id">
<ui:insert name="idle">
<ui:include src="/META-INF/templates/PrimefacesIdleMonitor.xhtml"/>
</ui:insert>
</div>
</div>
In the PageServiceBean.java
public void welcomeListener() {
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_WARN, "Hallo",
"Du bist wieder eingeloggt."));
}
public void logoutListener() throws IOException {
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_WARN,
"Du bist ausgeloggt!", "Bis dann"));
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
ExternalContext ec =FacesContext.getCurrentInstance().getExternalContext();
System.out.println(ec.getRequestContextPath()+"/login.xhtml");
ec.redirect(ec.getRequestContextPath()+"/login.xhtml");
FacesMessage msg = new FacesMessage("Information ", " Die Session ist abgelaufen. Bitte melden sie sich erneut an.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
If the user klick "ok" he can work again. If he klick logout he will be redirect to the login-back. No error or something else is throw.

Related

PieChart using Prime faces 3.5 and jsf 2.0 coming empty

I am currently working on JSF 2.0 application which works as follows:
1) upload excel file using Prime faces(woerking fine)\ 2) access data
and update the third column of excel based on ping testing,set the
failed and passed count values in MultiplePingtesting bean(works
fine) 3) ChartBean4 should access the passed and failed count and
generate graph(Not working) 4) Testing with different files should
produce proper graph (Not working)
Working enviroment: JSF2.0 with prime faces 3.5, netbeans 7.1 using Glassfish server
Issue: If i try to access the failed and passed count in Chartbean4.java it is coming as zero and the piechart comes wrong!!! Please let me know if am wrong any where
faces-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<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">
<managed-bean>
<managed-bean-name>multiplepingtesting</managed-bean-name>
<managed-bean-class>control.MultiplePingTesting</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>chartbean4</managed-bean-name>
<managed-bean-class>control.ChartBean4</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>multiplepingtesting</property-name>
<value>#{multiplepingtesting}</value>
</managed-property>
</managed-bean>
</faces-config>
From.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"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:t="http://myfaces.apache.org/tomahawk">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>:: From ::</title>
</h:head>
<h:body>
<h:form enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{multiplepingtesting.handleFileUpload}"
mode="advanced" auto="true"
allowTypes="/(\.|\/)(xls|xlsx)$/" />
<p:growl id="display" showDetail="true" />
<p:commandButton value="suraj" action="PieChart" ajax="false"></p:commandButton>
</h:form>
//**MultiplePingTesting.java**//
public class MultiplePingTesting implements Serializable
{
public int passed, failed; //added getters and setters
private int i=0,j=0;
private UploadedFile fileName;//added getters and setters
public void handleFileUpload(FileUploadEvent event)
{
try
{
FileInputStream fileInputStream;
File fName=new File(event.getFile().getFileName());
fileInputStream = new FileInputStream(fName);
System.out.println("insdie try block ");
FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
POIFSFileSystem fsFileSystem = new POIFSFileSystem(fileInputStream);
HSSFWorkbook workbook = new HSSFWorkbook(fsFileSystem);
String ip,message;
double port;
message="";
HSSFSheet sheet = workbook.getSheet("IP");
FileOutputStream out = new FileOutputStream(fName);
short col=2;
int lastrow=sheet.getLastRowNum()+1;
for(int rownum=1;rownum<lastrow;rownum++)
{
System.out.println("********" + rownum);
HSSFRow row = sheet.getRow(rownum);
ip=row.getCell((short)0).getStringCellValue();
port=row.getCell((short)1).getNumericCellValue();
try{
Socket s1 = new Socket(ip, (int) port);
InputStream is = s1.getInputStream();
DataInputStream dis = new DataInputStream(is);
if (dis != null)
{
System.out.println("Connected with ip "+ip+" and port 21");
message="Connected";
i++;
}
else
{
System.out.println("Connection invalid");
message="Connection Timed Out";
}
dis.close();
s1.close();
}
catch(Exception e)
{
System.out.println("Server not Connected,Connection timed out");
message="Server not Connected,Connection timed out";
j++;
}
row.createCell(col).setCellValue(message);
}
workbook.write(out);
out.close();
setFailed(i);
setPassed(j);
System.out.println("value of failed" + i + "*******"+getFailed());
System.out.println("value of succes" + getPassed());
}
catch(Exception e)
{
System.out.println("exception\n"+ e.getStackTrace());
}
}
//*PieChart.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"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:t="http://myfaces.apache.org/tomahawk">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>:: Piechart::</title>
</h:head>
<h:body >
<h:form>
<td align="right">
<h:outputText value="#{chartbean4.sj}"/>
<p:pieChart id="sample" value="#{chartbean4.pieModel}" legendPosition="w"
title="Sample Pie Chart" style="width:400px;height:300px" />
<h:commandButton name ="multiple_testing" action="From"/>
</td>
</h:form>
</h:body>
</html>
//*ChartBean4.java*/
public class ChartBean4 implements Serializable {
private MultiplePingTesting multiplepingtesting;
public MultiplePingTesting getMultiplepingtesting() {
return multiplepingtesting;
}
public void setMultiplepingtesting(MultiplePingTesting multiplepingtesting) {
this.multiplepingtesting = multiplepingtesting;
}
private PieChartModel pieModel;
#PostConstruct
public void init()
{
System.out.print("***********multiple_test.failed" + multiplepingtesting.getFailed());
createPieModel();
}
public PieChartModel getPieModel() {
return pieModel;
}
private void createPieModel() {
System.out.print("*****Inside Create Pie model******multiple_test.failed" + multiplepingtesting.getFailed());
pieModel = new PieChartModel();
pieModel.set("failed", multiplepingtesting.getFailed());
pieModel.set("success", multiplepingtesting.getPassed());
System.out.print("***********'");
}
}
Finally i got my answer with some workaround , here are the changes done
Changed both the scope in faces-config,xml to "request"
Introduced i and j variables as static in MultiplePingTesting.java.
In forward method of MultiplePingTesting failed and passed properties are set using i and j variables
***** Below are the updated files*******
From.xhtml
<h:form enctype="multipart/form-data">
<p:fileUpload fileUploadListener="#{multiplepingtesting.handleFileUpload}"
mode="advanced" auto="true"
allowTypes="/(\.|\/)(xls|xlsx)$/" />
<p:commandButton value="PieChart" action="#{multiplepingtesting.forward}" ajax="false"></p:commandButton>
<p:growl id="display" showDetail="true" />
</h:form>
MultiplePingTesting.java
(Commented setFailed() and setPassed() code & appended forward() method in file
public String forward()
{
setFailed(j);
setPassed(i);
return "PieChart" ;
}

JSF Message on SUBMIT action

I begin with my case:
JSF 2.1
Tomcat 7.0.27
Netbeans as IDE
JSF and PRIMEFace (but optional)
Level JSF beginner
Level JAVA good and not god
I have done a simple JSF site to learn how to works with JSF. My question is based on Login example at this step the problem is not related about that login that is obviously insicure.
A bit of code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
/**
*
* #author
*/
#ManagedBean
#SessionScoped
//#RequestScoped
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private final String userName = "User";
private final String userPassword = "12345";
private String name;
private String password;
private boolean isLogged=false;
public String getName() {
return name;
}
public void setName( String name ) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword( String password ) {
this.password = password;
}
public String login() {
if( !(userName==null || password==null)
&&
(userName.equals( name ) && userPassword.equals( password ))) {
isLogged=false;
return "main";
} else {
isLogged=true;
return "index";
}
}
public boolean getIsLogged(){
return isLogged;
}
}
The page index
<?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">
<h:head>
<title>TSAM 7.5 Login</title>
</h:head>
<h:body>
Login system
<br />
<!--<h:link outcome="welcomePrimefaces" value="Primefaces welcome page" />-->
<h:form>
User : <h:inputText value="#{user.name}" />
Password : <h:inputSecret value="#{user.password}" />
<h:commandButton action="#{user.login()}" value="Submit" />
<h:commandButton value="reset" type="reset" />
<h:commandButton value="otherpage" action="otherpage"></h:commandButton>
</h:form>
</h:body>
</html>
The main page
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.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"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<f:event type="preRenderView" listener="#{user.isLogged}"/>
<f:view contentType="text/html">
<h:head>
<f:facet name="first">
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
<title>PrimeFaces</title>
</f:facet>
</h:head>
<h:body>
<p:layout fullPage="true">
<p:layoutUnit position="north" size="100" resizable="true" closable="true" collapsible="true">
Header
</p:layoutUnit>
<p:layoutUnit position="south" size="100" closable="true" collapsible="true">
Footer
</p:layoutUnit>
<p:layoutUnit position="west" size="175" header="Left" collapsible="true">
<p:menu>
<p:submenu label="Resources">
<p:menuitem value="Demo" url="http://www.primefaces.org/showcase-labs/ui/home.jsf" />
<p:menuitem value="Documentation" url="http://www.primefaces.org/documentation.html" />
<p:menuitem value="Forum" url="http://forum.primefaces.org/" />
<p:menuitem value="Themes" url="http://www.primefaces.org/themes.html" />
</p:submenu>
</p:menu>
</p:layoutUnit>
<p:layoutUnit position="center">
Welcome to PrimeFaces
</p:layoutUnit>
</p:layout>
</h:body>
</f:view>
</html>
First
I use action="#{user.login()}" to make navigation action is this correct or there is a better pattern?
But the real question is: How to show a message If I redirect?
I like to show a message I know the example by PrimeFace http://www.primefaces.org/showcase/ui/dialogLogin.jsf. but it doesn't redirect or show anything.
But if i use only "plain" JSW without PrimeFace, i like to put a
because it is similar to PrimeFaces so switch is simple.
I'd like to adopt a "pattern" so i can reuse it for eg when i do a serch an no data is present, or when i call "erease DB" and application say work in progress an then say OK all bank account are esreased (Only an example!! but interesting because there are 2 message).
Thanks
I try
public String login() {
if (!(userName == null || password == null)
&& (userName.equals( name ) && userPassword.equals( password ))) {
isLogged = true;
return "main";
} else {
isLogged = false;
FacesMessage facesMsg;
facesMsg = new FacesMessage( FacesMessage.SEVERITY_ERROR, "No login", "No login because username or passsword are incorrect etc" );
FacesContext fc = FacesContext.getCurrentInstance();
fc.addMessage( "loginError", facesMsg );
return "index";
}
}
And edited the page
<h:body>
Login system
<br />
<!--<h:link outcome="welcomePrimefaces" value="Primefaces welcome page" />-->
<h:form>
User : <h:inputText value="#{user.name}" />
Password : <h:inputSecret value="#{user.password}" />
<h:commandButton action="#{user.login()}" value="Submit" />
<h:commandButton value="reset" type="reset" />
<h:commandButton value="Cambio Password" action="changePassword"></h:commandButton>
</h:form>
<h:message for="" style="color:red;margin:8px;"/>
</h:body>
It works but it's not ok because it's not ok to put a string in the bean. And I need the multilanguage this string has to generated by the beans.... mmm this is not OK something i'm missing.
There's extremely a lot of noise in the question. I understand that your question ultimately boils down to:
How do I create a localized faces message in bean action method?
In that case, just get the message from the current resource bundle yourself.
As you're talking about localization, you should surely already have something like as
<resource-bundle>
<base-name>com.example.i18n.text</base-name>
<var>text</var>
</resource-bundle>
in your faces-config.xml. You could just get it in the bean as well with help of ResourceBundle which JSF itself is actually also using under the covers
Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
ResourceBundle text = ResourceBundle.getBundle("com.example.i18n.text", locale);
This way you could compose your message as
String summary = text.getString("messages.no_login_summary");
String detail = text.getString("messages.no_login_detail");
new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, detail);

Spring Web flow with JSF evaluation

I am new to Spring Web flow.
This is my code.
main-flow.xml
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<var name="hello" class="org.springframework.webflow.samples.booking.hello"/>
<view-state id="hello">
<transition on="click" to="test"></transition>
</view-state>
<action-state id="test">
<evaluate expression="hello.saytest()">
</evaluate>
<transition on="yes" to="page1" ></transition>
<transition on="no" to="page2"></transition>
</action-state>
<view-state id="page1"></view-state>
<view-state id="page2"></view-state>
</flow>
Hello.java
package org.springframework.webflow.samples.booking;
import java.io.Serializable;
public class hello implements Serializable {
String name;
/**
*
*/
#Override
public String toString() {
return "hello [name=" + name + "]";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
private static final long serialVersionUID = 1L;
public boolean saytest() {
System.out.println(name);
String test = "new";
if (name == test) {
return true;
} else {
return false;
}
}
}
hello.xhtml
<!DOCTYPE composition 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: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"
template="/WEB-INF/layouts/standard.xhtml">
<ui:define name="notes">
<p>
Check the calendar widget and the tooltips on the credit card fields.
The form uses Ajax-based validations to redisplay server-side errors without refreshing the entire page.
The booking bean backing the form is a flow-scoped object (see <strong>booking-flow.xml</strong>).
</p>
</ui:define>
<ui:define name="content">
<h:form>
<h:outputLabel for="price">Enter the Name:</h:outputLabel>
<h:inputText id="name" value="#{hello.name}">
</h:inputText>
<p:commandButton id="click" action="click" value="click" />
</h:form>
</ui:define>
</ui:composition>
Here I am trying to get some value from hello.xhtml and try to evaluate it in main-flow.xml.
If the value which i tried is new then it have to navigate to page1 or it have to take it to page2.xhtml.Now I my case even i enter new in inputtext box it take to me to page2 only.
Can anyone help me.
Change
if (name == test)
to
if (name.equals(test))
Or, simply,
if (name.equals("new"))
See http://www.javabeginner.com/learn-java/java-string-comparison

inputText validator doesn't display error message

I have a simple form that get code then display his libelle, I added a validator bean that check if the code exist.
My problem is I can't display the error message whith when the code doesn't exist.
Here is the code:
test.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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head><title>Test</title>
</h:head>
<body class="bodyMain">
<h:form>
<h:panelGrid columns="3">
<h:outputText value="Code: " />
<h:inputText id="code" value="#{myBean.code}"
validator="#{myBean.validateCode}">
<f:ajax execute="#this" render="libelle" listener="#{myBean.setLibelle()}"/>
</h:inputText>
<h:message for="code" style="color:red"/>
</h:panelGrid>
<h:panelGrid id="libelle" columns="2">
<h:outputText value="Libelle: " />
<h:outputText value="#{myBean.libelle}" />
</h:panelGrid>
</h:form>
</body>
</html>
MyBean.java
#ManagedBean
#ViewScoped
public class MyBean implements java.io.Serializable{
private static final long serialVersionUID = 1L;
private String code="";
private String libelle="";
public String getCode() {
return this.code;
}
public void setCode(String code) {
this.code=code;
}
public String getLibelle() {
return this.libelle;
}
public void setLibelle(String libelle) {
this.libelle=libelle;
}
public void setLibelle() {
if (code.compareTo("1")==0)
libelle="One";
else
libelle="";
}
public void validateCode(FacesContext context, UIComponent toValidate, Object value) throws ValidatorException {
String code = (String)value;
if (code.compareTo("1") != 0) {
FacesMessage message = new FacesMessage("Code doesn't exist");
throw new ValidatorException(message);
}
}
}
Thank you for your help to resolve this problem
You're not updating the <h:message> component by the <f:ajax>. You need to give the <h:message> an id and include it in the <f:ajax render>.
<h:inputText id="code" value="#{myBean.code}" validator="#{myBean.validateCode}">
<f:ajax execute="#this" render="libelle codeMessage" listener="#{myBean.setLibelle()}"/>
</h:inputText>
<h:message id="codeMessage" for="code" style="color:red"/>
Unrelated to the concrete problem, don't initialize properties to empty strings. Let them by default null. Also, comparing objects should be done with equals() method, not with compareTo(). Finally, using a dropdown list with all available values instead of an input field would be more user friendly.

SelectBooleanCheckbox rendered state does not match the backing bean

I'm using JSF2.0 and am building up a wizard. I have encountered a problem with SelectBooleanCheckboxes. Here is the workflow:
Load page with checkboxes (values are bound to a SortedMap in the backing bean).
Tick them, and click next. This increments a cursor, which the page uses to determine which PanelGroup the load.
The (correct) values are persisted to the bean.
Click back (cursor is decremented) and page renders the editable checkboxes. The first checkbox is not ticked (even though the bound variable holds a value of true for that box).
This cursor-based approach (which contains all of the wizard screens) doesn't seem to work. However, if i slightly modify this so that the prev/next buttons bring up different xhtml pages, this issue disappears.
Unfortunately I cant do this. We are going to plug this wizard into a modal dialog, so visiting a new page on prev/next will not work
I've written up a smallish example of this (rather than asking you to wade through the entire wizard).
Here is the Java class:
#ConversationScoped
#Named("hashBool")
public class HashBoolTest2 implements Serializable {
private static final long serialVersionUID = 1962031429874426411L;
#Inject private Conversation conversation;
private List<RestrictionItem> list;
private SortedMap<String, Boolean> values;
private int cursor;
public HashBoolTest2( ) {
List<String> none = new ArrayList<String>();
none.add("");
this.setList( new ArrayList< RestrictionItem >( ) );
this.getList().add( new RestrictionItem( "a", "a", none ) );
...
this.getList().add( new RestrictionItem( "e", "e", none ) );
this.setValues( new TreeMap< String, Boolean >() );
this.setCursor( 0 );
}
#PostConstruct
public void andThis() {
this.conversation.begin( );
}
// getters and setters for instance variables
#Override
public String toString() {
return "Values : " + this.values.toString( ) + " List: " + this.list.toString( );
}
public void kill() {
this.conversation.end( );
}
public void doNext(ActionEvent e) {
this.cursor++;
}
public void doPrev(ActionEvent e) {
this.cursor--;
}
}
Here is the XHTML fragment:
<?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"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>IGNORED</title>
</head>
<body>
<ui:composition>
<h:panelGroup id="container">
<h:form>
<!-- edit state -->
<h:panelGroup id="edit" rendered="#{hashBool.cursor eq 0}">
<code>
<h:outputText value="#{hashBool.toString()}" escape="false"/>
</code>
<ul>
<ui:repeat value="#{hashBool.list}" var="elem">
<li>
<h:selectBooleanCheckbox id="elem" value="#{hashBool.values[elem.id]}" title="#{elem.displayName}" />
<h:outputLabel for="elem" value="#{elem.displayName}"/>
</li>
</ui:repeat>
</ul>
</h:panelGroup>
<!-- view state -->
<h:panelGroup id="view" rendered="#{hashBool.cursor eq 1}">
<code>
<h:outputText value="#{hashBool.toString()}" escape="false"/>
</code>
</h:panelGroup>
<br/>
<!-- buttons -->
<h:panelGroup id="buttons">
<f:ajax render=":container">
<h:commandButton value="Prev" actionListener="#{hashBool.doPrev}"/>
<h:commandButton value="Next" actionListener="#{hashBool.doNext}"/>
</f:ajax>
<h:commandButton value="Kill" actionListener="#{hashBool.kill()}"/>
</h:panelGroup>
</h:form>
</h:panelGroup>
</ui:composition>
</body>
</html>
Any suggestions are welcome! (And sorry if this is a double post, i havnt been able to uncover anything similar while searching here)
Mainly to ensure that the Wisdom of the Ancients remains properly documented (http://xkcd.com/979/): Turns out this is a bug within JSF 2.0.2 (which comes bundled with Liferay 6.0 GA 4). See here for more info: http://java.net/jira/browse/JAVASERVERFACES-1561

Resources