seam page parameters not working as expected - seam

I am learning seam and following a book Seam In Action by Dan Allen.
This is an example from this book.
Seam 2.2.0.GA
JBoss 5.1.0.GA
Here the page parameter roundId is always null even after a round is serialized, it is never passed. Neither to Roud.xhtml nor to RoundEdit.xhtml after clicking save on RoundEdit.xhtml. The entity always stays unmanaged.
RoundEdit.page.xml
<?xml version="1.0" encoding="UTF-8"?>
<page xmlns="http://jboss.com/products/seam/pages"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd"
login-required="true">
<begin-conversation join="true" />
<param name="roundId" value="#{roundHome.id}" converterId="javax.faces.Long"/>
<param name="teeSetId" value="#{teeSetHome.teeSetId}" />
<param name="roundFrom" />
<action execute="#{roundHome.wire}" />
<navigation from-action="#{roundHome.persist}">
<rule if-outcome="persisted">
<end-conversation/>
<redirect view-id="#{null != roundFrom ? roundFrom : '/Round.xhtml'}" />
</rule>
</navigation>
</page>
RoundEdit.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!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:s="http://jboss.com/products/seam/taglib"
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:a="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
template="layout/template.xhtml">
<ui:define name="body">
<h:form id="roundform">
<rich:panel>
<f:facet name="header>">
#{roundHome.managed ? 'Edit' : 'Add' } Round
</f:facet>
<s:decorate id="dateField" template="layout/edit.xhtml">
<ui:define name="label">Date:</ui:define>
<rich:calendar id="date" datePattern="dd/MM/yyyy" value="#{round.date}"/>
</s:decorate>
<s:decorate id="notesField" template="layout/edit.xhtml">
<ui:define name="label">Notes:</ui:define>
<h:inputTextarea id="notes" cols="80" rows="3" value="#{round.notes}" />
</s:decorate>
<s:decorate id="totalScoreField" template="layout/edit.xhtml">
<ui:define name="label">Total Score:</ui:define>
<h:inputText id="totalScore" value="#{round.totalScore}" />
</s:decorate>
<s:decorate id="weatherField" template="layout/edit.xhtml">
<ui:define name="label">Weather:</ui:define>
<h:selectOneMenu id="weather" value="#{round.weather}">
<s:selectItems var="_weather" value="#{weatherCategories}" label="#{_weather.label}"
noSelectionLabel=" Select " />
<s:convertEnum/>
</h:selectOneMenu>
</s:decorate>
<h:messages/>
<div style="clear: both;">
<span class="required">*</span> required fields
</div>
</rich:panel>
<div class="actionButtons">
<h:commandButton id="save" value="Save"
action="#{roundHome.persist}"
rendered="#{!roundHome.managed}"
disabled="#{!roundHome.wired}" />
<h:commandButton id="update" value="Update" action="#{roundHome.update}"
rendered="#{roundHome.managed}" />
<h:commandButton id="delete" value="Delete" action="#{roundHome.remove}"
rendered="#{roundHome.managed}" />
<s:button id="discard" value="Discard changes" propagation="end"
view="/Round.xhtml" rendered="#{roundHome.managed}" />
<s:button id="cancel" value="Cancel" propagation="end"
view="/#{empty roundFrom ? 'RoundList' : roundFrom}.xhtml"
rendered="#{!roundHome.managed}" />
</div>
<rich:tabPanel>
<rich:tab label="Tee Set">
<div class="association">
<h:outputText value="Tee set not selected" rendered="#{round.teeSet == null}" />
<rich:dataTable var="_teeSet" value="#{round.teeSet}" rendered="#{round.teeSet != null}">
<h:column>
<f:facet name="header">Course</f:facet>#{_teeSet.course.name}
</h:column>
<h:column>
<f:facet name="header">Color</f:facet>#{_teeSet.color}
</h:column>
<h:column>
<f:facet name="header">Position</f:facet>#{_teeSet.pos}
</h:column>
</rich:dataTable>
</div>
</rich:tab>
</rich:tabPanel>
</h:form>
</ui:define>
</ui:composition>
Round.page.xml
<?xml version="1.0" encoding="UTF-8"?>
<page xmlns="http://jboss.com/products/seam/pages"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd">
<param name="roundId" value="#{roundHome.id}" converterId="javax.faces.Long"/>
</page>
Round.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!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:s="http://jboss.com/products/seam/taglib"
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:a="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
template="layout/template.xhtml">
<ui:define name="body">
<h:form id="roundform">
<rich:panel>
<f:facet name="header>">Round</f:facet>
<s:decorate id="id" template="layout/display.xhtml">
<ui:define name="label">Id:</ui:define>
<h:outputText value="#{null == roundHome.id ? 'null' : roundHome.id}">
<s:convertDateTime type="date" />
</h:outputText>
</s:decorate>
<s:decorate id="date" template="layout/display.xhtml">
<ui:define name="label">Date:</ui:define>
<h:outputText value="#{roundHome.instance.date}">
<s:convertDateTime type="date" />
</h:outputText>
</s:decorate>
<s:decorate id="golfer" template="layout/display.xhtml">
<ui:define name="label">Golfer:</ui:define>
#{roundHome.instance.golfer.name}
</s:decorate>
<s:decorate id="totalScore" template="layout/display.xhtml">
<ui:define name="label">Total Score:</ui:define>
#{roundHome.instance.totalScore}
</s:decorate>
<s:decorate id="weather" template="layout/display.xhtml">
<ui:define name="label">Weather:</ui:define>
#{roundHome.instance.weather}
</s:decorate>
<s:decorate id="notes" template="layout/display.xhtml">
<ui:define name="label">Notes:</ui:define>
#{roundHome.instance.notes}
</s:decorate>
<div style="clear:both"/>
</rich:panel>
<div class="actionButtons">
<s:button id="edit" view="/RoundEdit.xhtml" value="Edit" />
</div>
<rich:tabPanel>
<rich:tab label="Tee Set">
<div class="association">
<h:outputText value="Tee set not selected" rendered="#{roundHome.instance.teeSet == null}" />
<rich:dataTable var="_teeSet" value="#{roundHome.instance.teeSet}" rendered="#{roundHome.instance.teeSet != null}">
<h:column>
<f:facet name="header">Course</f:facet>#{_teeSet.course.name}
</h:column>
<h:column>
<f:facet name="header">Color</f:facet>#{_teeSet.color}
</h:column>
<h:column>
<f:facet name="header">Position</f:facet>#{_teeSet.pos}
</h:column>
</rich:dataTable>
</div>
</rich:tab>
</rich:tabPanel>
</h:form>
</ui:define>
</ui:composition>
The entityHome RoundHome.java
#Name("roundHome")
public class RoundHome extends EntityHome<Round>{
#In(required = false)
private Golfer currentGolfer;
#In(create = true)
private TeeSetHome teeSetHome;
#Logger
private Log logger;
public void wire() {
logger.info("wire called");
TeeSet teeSet = teeSetHome.getDefinedInstance();
if (null != teeSet) {
getInstance().setTeeSet(teeSet);
logger.info("Successfully wired the teeSet instance with color: " + teeSet.getColor());
}
}
public boolean isWired() {
logger.info("is wired called");
if(null == getInstance().getTeeSet()) {
logger.info("wired teeSet instance is null, the button will be disabled !");
return false;
}
else {
logger.info("wired teeSet instance is NOT null, the button will be enabled !");
logger.info("teeSet color: "+getInstance().getTeeSet().getColor());
return true;
}
}
#RequestParameter
public void setRoundId(Long id) {
logger.info("in Setter RoundId is: " + id);
super.setId(id);
}
public Long getRoundId() {
Long id = (Long) getId();
logger.info("Setting RoundId : " + id);
return id;
}
#Override
protected Round createInstance() {
Round round = super.createInstance();
round.setGolfer(currentGolfer);
round.setDate(new java.sql.Date(System.currentTimeMillis()));
logger.info("Created a Round with roundId: " + round.getId());
return round;
}
#Override
protected Round loadInstance() {
logger.info("loadInstance for id: " + getId());
return (Round) getEntityManager().createQuery(
"select r from Round r " +
"join fetch r.golfer g " +
"join fetch r.teeSet ts " +
"join fetch ts.course c " +
"where r.id = :id ")
.setParameter("id",getId())
.getSingleResult();
}
}

In Round.xhtml you have:
<div class="actionButtons">
<s:button id="edit" view="/RoundEdit.xhtml" value="Edit" />
</div>
This navigates to RoundEdit but it doesn't pass a roundId to be edited. When you add an id to the url you're setting that id manually. To set it in the code you could use a get action and pass it as a param:
<s:button id="edit" view="/RoundEdit.xhtml" value="Edit" >
<param name="roundId" value="#{roundHome.id}"/>
</s:button>
Check out the URL, you'll see the param being passed.

Related

JSF primefaces convertDateTime pattern year for the year 2020 is incorrect

Issue with the pattern year 2020
In the calendar popup it is selected as is but upon selection it is set as 3/29/20
The value gets stored as 29-MAR-20 in the database
Data type of date2 is DATE in the database
But the outputText value shows it as 03/29/0020.
Correct output text should be 03/20/2020
<h:form id="form">
<p:growl id="msgs" showDetail="true" skipDetailIfEqualsSummary="true" />
<h:panelGrid columns="2" cellpadding="5">
<p:outputLabel for="popup" value="Popup:" />
<p:calendar id="popup" value="#{calendarView.date2}" />
</h:panelGrid>
<p:commandButton value="Submit" update="msgs" action="#{calendarView.click}" icon="pi pi-check" />
<p:dialog modal="true" resizable="false" header="Values" widgetVar="dlg" showEffect="fold">
<p:panelGrid id="display" columns="2" columnClasses="label,value">
<h:outputText value="Popup:" />
<h:outputText value="#{calendarView.date2}">
<f:convertDateTime pattern="MM/dd/yyyy" />
</h:outputText>
</p:panelGrid>
</p:dialog>
</h:form>
web.xml
<context-param>
<param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
<param-value>true</param-value>
</context-param>
Tested with the date selection of 6/27/99
The value gets stored as 27-JUN-99 in the database
The output was shown as expected / correct out put - 06/27/1999

Seam pageflow example NumberGuess Not landing on to the second page

I'm trying to run simple Seam PageFlow example NumberGuss. I have deployed it on Jboss Server. When I access the URL it lands on the first page but if I hit any of the button provided on that page it says "The page isn't redirecting properly".On server log I found
SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (default task-16) Error Rendering View[/debug.xhtml]: org.jboss.weld.context.NonexistentConversationException: WELD-000321: No conversation found to restore for id 1.
I'm using wildfly-8.1.0 and jboss-seam-2.3.1
Attaching pageflow.jpdl.xml and numberGuess.xhtml for reference. Please help me resolve the issue I'm facing.
<!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:s="http://jboss.org/schema/seam/taglib">
<h:head>
<title>Guess a number...</title>
<link href="niceforms.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="niceforms.js"><!-- --></script>
</h:head>
<body>
<h1>Guess a number...</h1>
<h:form id="NumberGuessMain" styleClass="niceform">
<div>
<h:messages id="messages" globalOnly="true"/>
<h:outputText id="Higher"
value="Higher!"
rendered="#{numberGuess.randomNumber gt numberGuess.currentGuess}"/>
<h:outputText id="Lower"
value="Lower!"
rendered="#{numberGuess.randomNumber lt numberGuess.currentGuess}"/>
</div>
<div>
I'm thinking of a number between <h:outputText id="Smallest" value="#{numberGuess.smallest}"/> and
<h:outputText id="Biggest" value="#{numberGuess.biggest}"/>. You have
<h:outputText id="RemainingGuesses" value="#{numberGuess.remainingGuesses}"/> guesses.
</div>
<div>
Your guess:
<h:inputText id="inputGuess" value="#{numberGuess.currentGuess}" required="true" size="3"
rendered="#{(numberGuess.biggest-numberGuess.smallest) gt 20}">
<f:validateLongRange maximum="#{numberGuess.biggest}"
minimum="#{numberGuess.smallest}"/>
</h:inputText>
<h:selectOneMenu id="selectGuessMenu" value="#{numberGuess.currentGuess}" required="true" rendered="#{numberGuess.selectMenuRendered}">
<s:selectItems id="PossibilitiesMenuItems" value="#{numberGuess.possibilities}" var="i" label="#{i}"/>
</h:selectOneMenu>
<h:selectOneRadio id="selectGuessRadio" value="#{numberGuess.currentGuess}" required="true" rendered="#{numberGuess.radioButtonRendered}">
<s:selectItems id="PossibilitiesRadioItems" value="#{numberGuess.possibilities}" var="i" label="#{i}"/>
</h:selectOneRadio>
<h:commandButton id="GuessButton" value="Guess" action="guess"/>
<s:button id="CheatButton" value="Cheat" action="cheat"/>
<s:button id="GiveUpButton" value="Give up" action="giveup"/>
</div>
<div>
<h:message id="message" for="inputGuess" style="color: red"/>
</div>
</h:form>
</body>
</html>
<!--
An example of pageflow in jPDL. This exemplifies the
approach where action handlers are attached transitions
and decision nodes, instead of view components.
An alternative approach would be to attach all action
handlers to view components, and let the jPDL define
only the navigation rules.
-->
<pageflow-definition
xmlns="http://jboss.org/schema/seam/pageflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://jboss.org/schema/seam/pageflow http://jboss.org/schema/seam/pageflow-2.3.xsd"
name="numberGuess">
<start-page name="displayGuess" view-id="/numberGuess.xhtml">
<redirect/>
<transition name="guess" to="evaluateGuess">
<action expression="#{numberGuess.guess}"/>
</transition>
<transition name="giveup" to="giveup"/>
<transition name="cheat" to="cheat"/>
</start-page>
<decision name="evaluateGuess" expression="#{numberGuess.correctGuess}">
<transition name="true" to="win"/>
<transition name="false" to="evaluateRemainingGuesses"/>
</decision>
<decision name="evaluateRemainingGuesses" expression="#{numberGuess.lastGuess}">
<transition name="true" to="lose"/>
<transition name="false" to="displayGuess"/>
</decision>
<page name="giveup" view-id="/giveup.xhtml">
<redirect/>
<transition name="yes" to="lose"/>
<transition name="no" to="displayGuess"/>
</page>
<process-state name="cheat">
<sub-process name="cheat"/>
<transition to="displayGuess"/>
</process-state>
<page name="win" view-id="/win.xhtml">
<redirect/>
<end-conversation/>
</page>
<page name="lose" view-id="/lose.xhtml">
<redirect/>
<end-conversation/>
</page>
</pageflow-definition>
Resolved the issue.Weld is scanning the archive, which seems to cause the problem.The Weld Docs says:
You can either set this up for your deployment only by adding the following content to the META-INF/jboss-all.xml file of your application.
jboss-all.xml file goes to your META-INF for ear archive and likely to WEB-INF for war archive
<jboss xmlns="urn:jboss:1.0">
<weld xmlns="urn:jboss:weld:1.0" require-bean-descriptor="true"/>
</jboss>
It worked for me.

Highlighting tab in p:tabview when I click a corresponding button

I am using multiple tabs in p:tabview. On top of this I have a series of static image (like progress bar) so that when I click the first image it move on to highlight the first tab and so on.
<h:form>
<h:commandLink action="#tab1">
<h:graphicImage src="image1"/>
</h:commandLink>
<p:tabView>
<p:tab title="tab1" id="tab1">
<ui:include src="some.xhtml></ui:include>
</p:tab>
.
.
.
.
</p:tabview>
<h:form>
If you want to avoid ajax requests you should be able to change tabs using jQuery. In order to do that you will need to specify a widgetVar to you tabView.
<p:tabView id="tabView" widgetVar="tabViewVar">
....
</p:tabView>
With this approach you can use only the image
<h:graphicImage value="image1" onclick="jQuery(jQuery(tabViewVar.jqId + " li[role=tab] a").get(0)).trigger("click");" />
<h:graphicImage value="image2" onclick="jQuery(jQuery(tabViewVar.jqId + " li[role=tab] a").get(1)).trigger("click");" />
<h:graphicImage value="image3" onclick="jQuery(jQuery(tabViewVar.jqId + " li[role=tab] a").get(2)).trigger("click");" />
...
In case you don't mind extra ajax requests, you can do that as follows:
<p:commandLink action="#{tabViewBean.submit}" process="#this" update="tabView">
<h:graphicImage value="image1" />
<f:setPropertyActionListener value="0" target="#{tabViewBean.activeIndex}" />
</p:commandLink>
<p:commandLink action="#{tabViewBean.submit}" process="#this" update="tabView">
<h:graphicImage value="image2" />
<f:setPropertyActionListener value="1" target="#{tabViewBean.activeIndex}" />
</p:commandLink>
<p:commandLink action="#{tabViewBean.submit}" process="#this" update="tabView">
<h:graphicImage value="image3" />
<f:setPropertyActionListener value="2" target="#{tabViewBean.activeIndex}" />
</p:commandLink>

ValueChangeListener is not changing values in input text field and in dropdown

In my application, I call the value change listener on change of values in a listbox.
The value change listener should update the values of four fields - 2 input text fields and 2 combo boxes ( dropdown boxes). The bean scope is request. I am using JSF 1.2 version.
the jsp file:
<h:selectManyListbox id="FSIBUCKET" required="true"
rendered="#{mangAreaSignOff.renderSelectedFSIBUCKET}"
valueChangeListener="#{mangAreaSignOff.handleFSIBucketValueChange}"
onchange="submit(); javascript:waiton();" style="width:230px"value="#{mangAreaSignOff.selectedFsiBucket}" >
<f:selectItems value="#{mangAreaSignOff.fsiBucketList}" />
</h:selectManyListbox>
the java code:
public void handleFSIBucketValueChange(ValueChangeEvent vce)
{
Object[] selectedFSIBucket = (Object[]) vce.getNewValue();
setSelectedFsiBucket(selectedFSIBucket);
getFSIBucketValueChangeResults();
}
public void getFSIBucketValueChangeResults()
{
Object [] tempFSIBucket = getSelectedFsiBucket() ;
String FSIBucket = getArrayToString(tempFSIBucket, ";");
List<String> result = mangAreaAPI.getFSIBucketValueChanges(FSIBucket);
mangAreaVO.setSelectedThresholdcategory(result.get(0));
mangAreaVO.setSelectedThresholdAmount(result.get(1));
mangAreaVO.setSelectedThresholdType(result.get(2));
mangAreaVO.setSelectedThresholdPercent(result.get(3));
}
I need help to identify where the flow goes wrong.
On change of the listbox value, the 4 fields are not updated. In java class I am able to see the updated values. but in screen it is not updated. Please let me know if any more explanation is needed in my question.
<h:panelGrid columns="10">
.
some other fields
.
.
<!-- Threshold Category -->
<h:panelGroup styleClass="text2"
rendered="#{mangAreaSignOff.renderInputThresholdCategory}">
<h:outputText value="MGT_LABEL_THRESHOLDCATEGORY" escape="false"
converter="com.db.smis.planus.TermConverter" styleClass="text2" />
<f:verbatim>:</f:verbatim>
</h:panelGroup>
<h:panelGroup
rendered="#{!mangAreaSignOff.renderInputThresholdCategory}">
<h:outputText value=" " escape="false" />
</h:panelGroup>
<!-- Threshold Amount -->
<h:panelGroup styleClass="text2"
rendered="#{mangAreaSignOff.renderInputAmount}">
<h:outputText value="MGT_LABEL_THRESHOLD" escape="false"
converter="com.db.smis.planus.TermConverter" styleClass="text2" />
<f:verbatim>:</f:verbatim>
</h:panelGroup>
<h:panelGroup rendered="#{!mangAreaSignOff.renderInputAmount}">
<h:outputText value=" " escape="false" />
</h:panelGroup>
<!-- Threshold Type -->
<h:panelGroup styleClass="text2"
rendered="#{mangAreaSignOff.renderThresholdType}">
<h:outputText value="MGT_LABEL_THRESHOLDTYPE" escape="false"
converter="com.db.smis.planus.TermConverter" styleClass="text2" />
<f:verbatim>:</f:verbatim>
</h:panelGroup>
<h:panelGroup rendered="#{!mangAreaSignOff.renderThresholdType}">
<h:outputText value=" " escape="false" />
</h:panelGroup>
<!-- Threshold Percentage -->
<h:panelGroup styleClass="text2"
rendered="#{mangAreaSignOff.renderThresholdPercent}">
<h:outputText value="MGT_LABEL_THRESHOLDPERCENT" escape="false"
converter="com.db.smis.planus.TermConverter" styleClass="text2" />
<f:verbatim>:</f:verbatim>
</h:panelGroup>
<h:panelGroup
rendered="#{!mangAreaSignOff.renderThresholdPercent}">
<h:outputText value=" " escape="false" />
</h:panelGroup>
.
.
.
.
</h:panelGrid>
I need to update the above 4 fields only.

JSF Primefaces reload issue, could this be CSS issue or any other?

In our web project we use JSF Myfaces, Primefaces 3.5. We have created our own primefaces theme for the project.
I find the following odd problems, which I suspect are due the css/library etc,
Multiple selection checkbox on p:dataTable works on odd tries. I.e on the first load of the page the selection works. If I visit one other page and comeback, the select check box doesn't work. If I visit one more page and comeback it works again. When it doesn't work, if I do a page reload from browser it works again. (the problem is the same in all browsers)
p:ajaxStatus onstart js function fires only for the first ajax call. For all subsequent calls this event is not fired. If I reload the page it again fires for the first ajax call and stops. We have not set any global setting on any ajax calls, I presume all calls default to global = true (the problem is the same in all browsers)
for a p:barChart on chrome, the x and y-axis labels fall in to the axis, but when I reload the page the display is adjusted and correct (as it appears in firefox), and no further reload is need during the session, even when navigate back and forth from other pages.
Our application has a menu area on the top and ouputPanel that is updated using ui:include based on the ajax menu selection.
I am not sure what could be causing these issues, and why things seem to work fine on reload. Where could the problem be?
The view code for the first issue related to the multiple selection checkbox is below.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
</h:head>
<h:body>
<h:form id="dataForm">
<p:messages id="tableMsgs" />
<h:panelGroup>
<p:dataTable value="#{usersBean.userDataModel}" var="user"
id="userDataModel" rows="20" paginator="true"
paginatorAlwaysVisible="false" editable="true"
selection="#{usersBean.selectedUsers}"
resizableColumns="false">
<f:facet name="header">
<p:commandButton value="Flag User" process="#form"
action="#{usersBean.flagUser}"
icon="ui-icon-custom-arrow" iconPos="right"
update=":dataForm:tableMsgs"></p:commandButton>
<p:spacer width="10"></p:spacer>
<p:commandButton value="Delete User" process="#form"
icon="ui-icon-custom-arrow" iconPos="right" update="#form"
action="#{usersBean.deleteUser}">
</p:commandButton>
</f:facet>
<p:ajax event="rowEdit" listener="#{usersBean.onEdit}"
oncomplete="resetCSS()"
update=":dataForm:tableMsgs />
<p:ajax event="rowEditCancel" oncomplete="resetCSS()" />
<p:column selectionMode="multiple" style="width:15px;" />
<p:column headerText="Department" sortBy="#{user.dept.name}"
style="white-space:pre-line;width:100px">
<h:outputText value="#{user.dept.name}"
style="white-space:pre-line;width:100px;display:block;">
</h:outputText>
</p:column>
<p:column headerText="UserName" sortBy="#{user.userLoginName}"
style="width:100px;">
<h:outputText value="#{user.userLoginName}"
style="width:100px;display:block;"></h:outputText>
</p:column>
<p:column headerText="Role" sortBy="#{user.role}"
style="width:100px;">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.role}"
style="width:100px;display:block;"></h:outputText>
</f:facet>
<f:facet name="input">
<p:selectOneMenu value="#{user.role}" style="width:95px" rendered="#{user.enabled eq true}" >
<f:selectItems
value="#{usersBean.rolesMap[user.dept.deptId]}"
var="role" itemLabel="#{role}" itemValue="#{role}"></f:selectItems>
</p:selectOneMenu>
<h:outputText value="#{user.role}" rendered="#{user.enabled eq false}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Manager" style="width:100px;">
<p:cellEditor>
<f:facet name="output">
<h:outputText
value="#{user.usermanagerByUserId.userByManagerId.userLoginName}"
style="width:100px;display:block;"></h:outputText>
</f:facet>
<f:facet name="input">
<p:selectOneMenu rendered="#{user.enabled eq true}"
value="#{usersBean.managerIdMap[user.userId]}"
style="width:95px;">
<f:selectItems
value="#{usersBean.managerMap[user.dept.deptId]}"
var="manager" itemLabel="#{manager.userLoginName}"
itemValue="#{manager.userId}"></f:selectItems>
</p:selectOneMenu>
<h:outputText
value="#{user.usermanagerByUserId.userByManagerId.userLoginName}" rendered="#{user.enabled eq false}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Email" style="width:100px;">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.email}"
style="width:100px;display:block;"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{user.email}" style="width:95px;"
validatorMessage="Enter Valid Email" maxlength="100">
<f:validateRegex
pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*#[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Last Login" style="width:60px;">
<h:outputText value="#{user.lastLogin}"
style="width:60px;display:block;">
<f:convertDateTime pattern="dd/MM/yyyy"></f:convertDateTime>
</h:outputText>
</p:column>
<p:column headerText="Status" style="width:40px;">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="Enable" rendered="#{user.enabled eq true}"></h:outputText>
<h:outputText value="Disable"
rendered="#{user.enabled eq false}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:selectBooleanCheckbox value="#{user.enabled}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Locked" style="width:40px;">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="Locked" rendered="#{user.locked eq true}"
style="width:40px;display:block;" />
<h:outputText value="UnLocked" style="width:40px;display:block;"
rendered="#{user.locked eq false}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:selectBooleanCheckbox value="#{user.locked}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit" style="width:30px;">
<p:rowEditor>
</p:rowEditor>
</p:column>
</p:dataTable>
</h:panelGroup>
</h:form>
</div>

Resources