How update my panelGrid with CommandButton? - jsf

I try to update my PanelGrid from my CommandButton with update attribute, but it doesn't work:
<h:body>
<p:dialog id="dialog" header="Add Memo" widgetVar="dialogMemo" resizable="false" >
<h:form id="formDialog">
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="commentInput" value="Comment:" />
<p:inputTextarea id="commentInput" value="#{dashboardBean.currentComment}" rows="6" cols="25" label="commentInput" required="true"/>
<p:watermark for="commentInput" value="Enter your memo..."/>
<h:outputLabel for="selectShare" value="Share Memo: " />
<p:selectBooleanCheckbox id="selectShare" />
<h:outputLabel for="choosePriority" value="Priority:" />
<p:selectOneMenu id="choosePriority" value="#{dashboardBean.currentPriority}" label="choosePriority">
<f:selectItem itemLabel="Low Priority" itemValue="1" />
<f:selectItem itemLabel="Medium Priority" itemValue="2" />
<f:selectItem itemLabel="High Priority" itemValue="3" />
</p:selectOneMenu>
<p:commandButton id="submitDialog" icon="ui-icon-check" value="Confirm" update=":formPanel:myPanelGrid" oncomplete="dialogMemo.hide();" type="submit">
</p:commandButton>
<p:commandButton icon="ui-icon-close" onclick="dialogMemo.hide();" value="Cancel"/>
</h:panelGrid>
</h:form>
</p:dialog>
<p:layout fullPage="true">
<p:layoutUnit id="leftPanel" position="west" size="250" header="My Memos" resizable="false" closable="false" collapsible="false">
<h:form id="formPanel">
<p:commandButton id="addMemo" icon="ui-icon-plus" onclick="dialogMemo.show();" type="submit" actionListener="#{dashboardBean.getEditControl}"/>
<h:panelGrid id="myPanelGrid" columns="1" width="100%" >
</h:panelGrid>
</h:form>
</p:layoutUnit>
</h:body>
I set the actionListener of my commandButton("submitDialog") dynamically, when i click to commandButton("addMemo").
The method is properly called, but the panelGrid("myPanelgrid") is not updated.
When i reload the page all components are properly displayed. But for me the update attribute of "submitDialog" is correctly set.
My methods to add panels dynamically,the first is called in postConstruct method(component is displayed correctly) and the second is called in commandButton("SubmitDialog") actionListener(Panelgrid is not Updated):
public void createMemoList()
{
if (panelGridUI != null && _countMemos > 0)
{
for (int i = 0; _countMemos > i; i++)
{
int u = _memosId.get(i);
Panel panel = (Panel)_application.createComponent(FacesContext.getCurrentInstance(), "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer");
MethodExpression editExpression = _ef.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{panelListener.handleEdit}", Void.class, new Class[]{ActionEvent.class});
MethodExpression me = _ef.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{panelListener.handleClose}", null, new Class[]{AjaxBehaviorEvent.class});
AjaxBehavior ajaxBehavior = new AjaxBehavior();
Draggable draggable = new Draggable();
panel.setId("mymemo_" + String.valueOf(u));
panel.setHeader(_userNames.get(i));
panel.setClosable(true);
panel.setToggleable(true);
HtmlOutputText memo = new HtmlOutputText();
memo.setValue(_userMemos.get(i));
memo.setId("text_" + String.valueOf(u));
panel.getChildren().add(memo);
HtmlPanelGroup panelGroup = new HtmlPanelGroup();
panelGroup.setId("group_" + u);
CommandButton button = new CommandButton();
button.setIcon("ui-icon-pencil");
button.addActionListener(new MethodExpressionActionListener(editExpression));
button.setOnclick("dialogMemo.show()");
button.setStyle("width:20px;height:20px;margin-right:5px;");
HtmlOutputText header = new HtmlOutputText();
header.setValue(_userNames.get(i));
header.setStyle("font-size:15px;");
panelGroup.getChildren().add(button);
panelGroup.getChildren().add(header);
panel.getFacets().put("header", panelGroup);
ajaxBehavior.addAjaxBehaviorListener(new AjaxBehaviorListenerImpl(me, me));
panel.addClientBehavior("close", ajaxBehavior);
draggable.setFor("mymemo_" + String.valueOf(u));
draggable.setRevert(true);
draggable.setHandle(".ui-panel-titlebar");
draggable.setStack(".ui-panel");
getPanelGrid().getChildren().add(panel);
getPanelGrid().getChildren().add(draggable);
}
}
}
public void createLastMemo()
{
if (panelGridUI != null && _countMemos > 0)
{
int u = _memosId.get(_countMemos - 1);
Panel panel = (Panel)_application.createComponent(FacesContext.getCurrentInstance(), "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer");
MethodExpression editExpression = _ef.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{panelListener.handleEdit}", Void.class, new Class[]{ActionEvent.class});
MethodExpression me = _ef.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{panelListener.handleClose}", null, new Class[]{AjaxBehaviorEvent.class});
AjaxBehavior ajaxBehavior = new AjaxBehavior();
Draggable draggable = new Draggable();
panel.setId("mymemo_" + String.valueOf(u));
panel.setHeader(_userNames.get(_countMemos - 1));
panel.setClosable(true);
panel.setToggleable(true);
HtmlOutputText memo = new HtmlOutputText();
memo.setValue(_userMemos.get(_countMemos - 1));
memo.setId("text_" + String.valueOf(u));
panel.getChildren().add(memo);
HtmlPanelGroup panelGroup = new HtmlPanelGroup();
panelGroup.setId("group_" + String.valueOf(u));
CommandButton button = new CommandButton();
button.setIcon("ui-icon-pencil");
button.addActionListener(new MethodExpressionActionListener(editExpression));
button.setOnclick("dialogMemo.show()");
button.setStyle("width:20px;height:20px;margin-right:5px;");
HtmlOutputText header = new HtmlOutputText();
header.setValue(_userNames.get(_countMemos - 1));
header.setStyle("font-size:15px;");
panelGroup.getChildren().add(button);
panelGroup.getChildren().add(header);
panel.getFacets().put("header", panelGroup);
ajaxBehavior.addAjaxBehaviorListener(new AjaxBehaviorListenerImpl(me, me));
panel.addClientBehavior("close", ajaxBehavior);
draggable.setFor("mymemo_" + String.valueOf(u));
draggable.setRevert(true);
draggable.setHandle(".ui-panel-titlebar");
draggable.setStack(".ui-panel");
getPanelGrid().getChildren().add(panel);
getPanelGrid().getChildren().add(draggable);
}
}
And this method is where i set the actionListener to my commandButton("addMemo")
:
public void getEditControl()
{
System.out.println("I am in getEditContol!!!");
UIViewRoot view = FacesContext.getCurrentInstance().getViewRoot();
CommandButton button = (CommandButton) view.findComponent("formDialog:submitDialog");
for(ActionListener act : button.getActionListeners()) {
button.removeActionListener(act);
}
MethodExpression getLastmemo = _ef.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{dashboardBean.getLastMemo}", Void.class, new Class[]{ActionEvent.class});
button.addActionListener(new MethodExpressionActionListener(getLastmemo));
}
My MethodExpression("getLastMemo") call my method createLastmemo. ActionListener is correctly called, but the view is not updated. I am in ViewScoped.

Related

How to get the value of <p:selectOneMenu> in Bean

I'm trying to get value of selectOneMenu from primefaces to Bean. it returns the old value not the new.
ManagedBean
public void doSetPrivilege( AjaxBehaviorEvent event)
{
SelectOneMenu selectOneMenu = (SelectOneMenu) event.getSource();
String value = selectOneMenu.getValue().toString();
System.out.println(value);
}
I get property privilegeApp from database
public Privilege getPrivilegeApp() {
TreeTable treeTable = new TreeTable();
treeTable = (TreeTable) FacesContext.getCurrentInstance().getViewRoot().findComponent(":idform:apps");
data = treeTable.getRowNode();
if (data.getType().equals("type1")) {
Application app = applicationService.loadApplicationByDesignation(data.getData().toString());
privilegeApp = privilegeService.getPrivilegeApplicationUtilisateur(getUtilisateur().getIdUtilisateur(),
app.getIdApplication());
}
return privilegeApp;
}
xhtml
<p:treeTable id="apps" value="#{treeTableTest3.root}" var="app" selectionMode="single" selection="#{treeTableTest3.selectedNode}" >
<p:column headerText="Designation" >
<h:outputText value="#{app}" />
</p:column>
<p:column headerText="Etat" >
<center>
<p:selectOneMenu value="#{treeTableTest3.privilegeApp.etat}" id="etat" style="width:100px; size:30px; float:center;">
<f:selectItem itemLabel="::Etat::" itemValue="#{null}"/>
<f:selectItems value="#{treeTableTest3.etats}"
var="etat"
itemValue="#{etat}" >
</f:selectItems>
<p:ajax event="change" listener="#{treeTableTest3.doSetPrivilege}" process="#all"/>
</p:selectOneMenu>
</center>
</p:column>
</p:treeTable>
Thank's for your help

JSF Primefaces c:foreach issue with ajaxlistner

I need to solve this issue.
I am using jsf primefaces with c:foreach here is my code. but this code is not running.
<p:tab id="catagoryTab" title="#{hardvalue['tutor.reg.tab2']}">
<p:panel header="#{hardvalue['tutor.reg.tab2']}" id="rowCreator">
<h:outputLabel value="#{hardvalue['tutor.reg.selectStmt']}"></h:outputLabel>
<h:panelGrid columns="3" style="width:100%;">
<p:outputLabel value="#{hardvalue['tutor.reg.category.table.collection']}"/>
<p:outputLabel value="#{hardvalue['tutor.reg.category.table.level']}"/>
<p:outputLabel value="#{hardvalue['tutor.reg.category.table.subject']}"/>
</h:panelGrid>
<c:forEach begin="0" end="#{Registerbean.size -1}" varStatus="loop" var="row">
<h:panelGrid columns="3"
style="width:100%; border: 1px solid #d4f1ff; border-radius: 3px 3px 3px 3px; background:#F7FDFF 50% 50% repeat-x ;">
<p:selectOneMenu
value="#{Registerbean.selectedtutorialType[loop.index]}"
style="font-size:15px !important; width:100px;">
<p:ajax process="#this" update="levellist1_#{loop.index}, levellist2_#{loop.index}, subjectlist_#{loop.index}" event="change"
listener="#{Registerbean.updateRecords(loop.index)}" />
<f:selectItem itemLabel="#{hardvalue['tutor.tutorial']}"
itemValue="tutorial" />
<f:selectItem itemLabel="#{hardvalue['tutor.conversaion']}"
itemValue="conversation" />
<f:selectItem itemLabel="#{hardvalue['tutor.music']}"
itemValue="music" />
<f:selectItem itemLabel="#{hardvalue['tutor.other']}"
itemValue="other" />
</p:selectOneMenu>
<h:panelGrid columns="3" >
<p:selectOneMenu style="width:230px" id="levellist1_#{loop.index}" value="#{Registerbean.selectedtutorialLevelFrom[loop.index]}"
>
<f:selectItems value="#{Registerbean.levellist}" />
</p:selectOneMenu>
<p:outputLabel value=" #{hardvalue['tutor.reg.to']} " />
<p:selectOneMenu style="width:230px" id="levellist2_#{loop.index}" value="#{Registerbean.selectedtutorialLevelTo[loop.index]}"
>
<f:selectItems value="#{Registerbean.levellist}" />
</p:selectOneMenu>
</h:panelGrid>
<p:selectOneMenu id="subjectlist_#{loop.index}" value="#{Registerbean.selectedtutorialSubject[loop.index]}"
style="width:230px;"
label="#{hardvalue['tutorsearch.select']}" filter="true" filterMatchMode="startsWith"
panelStyle="width:383px">
<f:selectItems value="#{Registerbean.subjectslist}" />
</p:selectOneMenu>
</h:panelGrid>
</c:forEach>
<p:commandButton id="moreButton" value="#{hardvalue['tutor.reg.addmore']}" update="rowCreator" process="#this" actionListener="#{Registerbean.addNewRow}" />
</p:panel>
</p:tab>
The above code is a tab in wizard. So I need to move on the next page after this one.
But I am not able to get the values as it do not let me assign to the array variables using indexes. Here is my backingbean
bean name: #ManagedBean(name="Registerbean")
private Tutor tutor= new Tutor();
private String[] selectedtutorialType= new String[size];
private String[] selectedtutorialLevelFrom= new String[size];
private String[] selectedtutorialLevelTo= new String[size];
private String[] selectedtutorialSubject= new String[size];
public void addNewRow(){
System.out.println("In add row");
size++;
selectedtutorialSubject=selectedtutorialLevelTo= selectedtutorialLevelFrom=selectedtutorialType=new String[size];
}
Here is my flowlistner through which I am just checking about the values of this tab. flowListener="#{Registerbean.onFlowProcess}"
public String onFlowProcess(FlowEvent event) {
System.out.println("tab id is:"+event.getOldStep());
if(event.getOldStep().equalsIgnoreCase("catagoryTab")){
for(int i=0;i<selectedtutorialType.length;i++){
System.out.println("selectedtutorialType : "+selectedtutorialType[i]);
System.out.println("selectedtutorialLevelFrom : "+selectedtutorialLevelFrom[i]);
System.out.println("selectedtutorialLevelTo : "+selectedtutorialLevelTo[i]);
System.out.println("selectedtutorialSubject : "+selectedtutorialSubject[i]);
}
}
return event.getNewStep();
}
What I want is : I want to draw components. on add row A component line will be added here. first one of the component's value changes, it reflacts the values of other two in that row only. but I is not doing the same. As the next button of p:wizard is not allowing me to move upword.
for updates it uses this function of backing bean.
public void updateRecords(int index) {
System.out.println("In update records: "+index);
levellist = new ArrayList<String>();
if (selectedtutorialType[index].equals("tutorial")) {
subjectslist = Arrays.asList(tutorialSubject);
levellist = Arrays.asList(tutorialLevel);
System.out.println("tutorial selection done..");
return;
} else if (selectedtutorialType[index].equals("conversation")) {
subjectslist = Arrays.asList(conversationSubject);
levellist = Arrays.asList(conversationLevel);
System.out.println("Conversation selection done..");
return;
} else if (selectedtutorialType[index].equals("music")) {
subjectslist = Arrays.asList(musicSubject);
levellist = Arrays.asList(musicLevel);
System.out.println("Music selection done..");
return;
} else {
subjectslist = Arrays.asList(otherSubject);
levellist = Arrays.asList(otherLevel);
System.out.println("Other selection done..");
return;
}
}
What to do. Plz help. Any other detail for this, if I am missing, let me know.
Thanks

<p:commandLink> updates <p:datatable> only after a second click

Basically, I'm trying to fire an action from a <p:commandLink> to update a <p:datatable> and a <p:growl>.
The <p:growl> is updated instantly, but the <p:datatable> is updated only after a second click.
Here is the XHTML code :
<h:body>
<h:form id="form1" >
<p:layout id="layout">
<p:layoutUnit id="north" position="north">
<p:growl id="msg" showDetail="true" />
<h:column>
<p:commandButton id="searchdate"
value="Rechercher"
actionListener="#{dyna.search}"
update=":form1:tabexam,:form1:msg"/>
</h:column>
</p:layoutUnit>
<p:layoutUnit position="center"
resizable="true"
collapsible="true"
effect="drop"
size="300"
styleClass="heighter">
<p:dataTable id="tabexam"
paginatorPosition="bottom"
var="exam"
value="#{dyna.listexam}"
widgetVar="examTable"
emptyMessage="aucun résultat."
filteredValue="#{dyna.filteredexams}"
paginator="true"
rows="20"
rowsPerPageTemplate="10,20,40,80"
binding="#{dyna.table}">
<f:facet name="header" >
<h:outputText value="Rechercher: "/>
<p:inputText id="globalFilter"
onkeyup="examTable.filter();"
style="width:200px" />
</f:facet>
</p:dataTable>
</p:layoutUnit>
<p:layoutUnit position="west" resizable="false" header="Liste Perso.">
<ui:repeat var="list" value="#{userBean.userLists}">
<center>
<p:commandLink id="listerlink"
title="Afficher la liste"
action ="#{dyna.refreshChildren(list.id.tbCode)}"
update=":form1:tabexam,:form1:msg">
<p:graphicImage id="imglist" value="/images/Liste_Cold.png"/><br></br>
<p:outputLabel value="#{list.id.tbCode}" /><br></br>
</p:commandLink>
</center>
</ui:repeat>
</p:layoutUnit>
</h:form>
</h:body>
Here is some code from my ManagedBean.
#ManagedBean(name = "dyna", eager = true)
#SessionScoped
public class DynamicDatatable implements java.io.Serializable {
#PostConstruct
public void init() {
listexam = DAO_Examen.getAllExamens();
selectedExamen = new Cotation();
etatExamOptions = createFilterOptions();
payExamOptions = createFilterOptions2();
salleOptions = DAO_Salle.getAllSalle(UserBean.user.getUserId());
refreshChildren("default");
}
public void refreshChildren(String listid) {
try {
//config
FacesContext fc = FacesContext.getCurrentInstance();
Application application = fc.getApplication();
ExpressionFactory ef = application.getExpressionFactory();
ELContext elc = fc.getELContext();
//Table
table = (DataTable) application.createComponent(DataTable.COMPONENT_TYPE);
//columns spec.
ArrayList<ColumnModel> columnmodel = DAO_UserLists.createUserColumnSpec(UserBean.user.getUserId(), "SITE1", listid);
if (columnmodel != null) {
for (int i = 0; i < columnmodel.size(); i++) {
if ((columnmodel.get(i) != null) && (columnmodel.get(i).getDbname() != null)) {
Column column = (Column) application.createComponent(Column.COMPONENT_TYPE);
column.setHeaderText(columnmodel.get(i).getUserListname());
column.setWidth("10");
column.setId("Col_" + columnmodel.get(i).getHeadername());
column.setStyleClass("dispo");
column.setSortBy(columnmodel.get(i).getDbname());
column.setRendered(columnmodel.get(i).isVisible());
table.getChildren().add(column);
}
}
FacesMessage msg = new FacesMessage("Terminé avec succes", "la liste " + listid + " est bien chargée");
FacesContext.getCurrentInstance().addMessage(null, msg);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
API's Version:
JSF 2.2
primefaces 4.0

Primefaces, Menuitem ActionListener on Right Click

i'm having some questions here. I will appreciate all of your helps.
I'm making some dynamic multilevel menu in primefaces, and i did it. There are parents, sub menus, and the menu items.
I want to give some CRUD action for each component via context menu, so I can edit the value/text for each level just with right-click.
I make the menu with bean called MenussBean.java, and you can see it below (just the correspond code).
public Submenu subMenus(Submenu parentMenus,String i, int id)
{
if(i==""&&parentMenus==null)
{
subList = menusdao.getRootMenu();
for(int a=0;a<subList.size();a++){
parentMenus = new Submenu();
parentMenus.setLabel(subList.get(a).getMenu());
model.addSubmenu(parentMenus);
i=subList.get(a).getMenu();
subMen = null;
id = a+1;
subList2 = subKategori(id);
for(Menus k:subList2){
if(String.valueOf(parentMenus.getLabel().toString()).equals(i)){
subMen = new Submenu();
subMen.setId("_"+k.getId());
subMen.setLabel(k.getMenu());
parentMenus.getChildren().add(subMen);
subMenus(subMen,k.getMenu(),k.getId());
}
}
}
}else{
subMen = null;
subList2 = subKategori(id);
for(Menus k:subList2){
if(String.valueOf(parentMenus.getLabel().toString()).equals(i)){
subList3=subKategori(k.getId());
if(subList3.size()==0)
{
UIParameter uiParam = new UIParameter();
UIParameter menuParam = new UIParameter();
UIParameter idParentParam = new UIParameter();
uiParam.setName("idParam");
uiParam.setValue(k.getId());
menuParam.setName("menuParam");
menuParam.setValue(k.getMenu());
idParentParam.setName("idParentParam");
idParentParam.setValue(k.getId_parent());
MenuItem mi = new MenuItem();
mi.setId("_"+k.getId());
Application app = FacesContext.getCurrentInstance().getApplication();
MethodExpression methodExpr = app.getExpressionFactory().createMethodExpression
(FacesContext.getCurrentInstance().getELContext(), "#{menussBean.onItemClick}", null ,new Class[]{ javax.faces.event.ActionEvent.class});
mi.addActionListener(new MethodExpressionActionListener(methodExpr));
mi.setOncomplete("");
mi.setValue(k.getMenu());
mi.setTarget("_self");
mi.setTitle(k.getLink());
mi.setAjax(false);
mi.getChildren().add(uiParam);
mi.getChildren().add(menuParam);
mi.getChildren().add(idParentParam);
mi.setProcess("#all");
parentMenus.getChildren().add(mi);
}
else if (subList3.size()!=0)
{
subMen = new Submenu();
subMen.setId("_"+k.getId());
subMen.setLabel(k.getMenu());
parentMenus.getChildren().add(subMen);
subMenus(subMen,k.getMenu(),k.getId());
}
}
}
}
return parentMenus;
}
public List<Menus> subKategori(int i)
{
arayList=new ArrayList<Menus>();
for(Menus k:getList()){
if(k.getId_parent()==i){
arayList.add(k);
}
}
return arayList;
}
public static List<Menus> getList() {
return list;
}
This is the value-getter method:
public void onItemClick() {
FacesContext context = FacesContext.getCurrentInstance();
idItem = context.getExternalContext().getRequestParameterMap().get("idParam");
menuItem = context.getExternalContext().getRequestParameterMap().get("menuParam");
idParentItem = context.getExternalContext().getRequestParameterMap().get("idParentParam");
}
And I want to use context menu to give the CRUD operations, so the user can right-click on the component he wants to edit. Here is my xhtml files.
<h:form>
<p:panelMenu id="panel" style="width:400px;font-size:12px"
model="#{menussBean.model}" var="detail" selectionMode="single" ajax="true"
widgetVar = "panelMen" styleClass="myMeineClass">
</p:panelMenu>
<p:contextMenu for="panel" style="font-size:12px">
<p:menuitem value="View" icon="ui-icon-search"
oncomplete="menuDialog.show()" update="display">
<f:param name="id_barangbaru" value="#{detail}" />
</p:menuitem>
<p:menuitem value="Add" icon="ui-icon-plus" />
<p:menuitem value="Edit" icon="ui-icon-pencil" />
<p:menuitem value="Delete" icon="ui-icon-close" />
</p:contextMenu>
<p:dialog header="Menu Detail" widgetVar="menuDialog"
resizable="false" width="200" showEffect="clip" hideEffect="fold"
id="dialog" appendToBody="true" modal="true">
<h:panelGrid id="display" columns="2" cellpadding="4" style="font-size:12px">
<h:outputText value="ID:" />
<h:outputText value="#{menussBean.idItem}"
style="font-weight:bold" />
<h:outputText value="Label:" />
<h:outputText value="#{menussBean.menuItem}"
style="font-weight:bold" />
<h:outputText value="Parent:" />
<h:outputText value="#{menussBean.idParentItem}"
style="font-weight:bold" />
</h:panelGrid>
</p:dialog>
</h:form>
Right now, I'm still getting the value into the context menu output text, but it needs to be left-clicked first. I need to pass the value directly just with right-click.
So, how can I get the value with actionListener with right-click? Please help...
I want to show the screenshot but I'm new here, so I haven't got any reputation.

Primefaces Wizard and selectOneRadio

I have a problem with using primeface's wizard component and the core selectOneRadio. My signup page looks like this
<ui:define name="content">
<f:view>
<h:form id="signUpForm">
<p:wizard widgetVar="wiz" flowListener="#{SignUpBean.onFlowProcess}">
<p:tab id="personalTab" title="">
<p:panel header="Personal">
<h:messages/>
<h:panelGrid id="panel1" columns="2">
<h:outputLabel for="firstName" value="First Name"/>
<h:inputText id="firstName" value="#{SignUpBean.firstName}" required="true"/>
<h:outputLabel for="lastName" value="Last Name"/>
<h:inputText id="lastName" value="#{SignUpBean.lastName}" required="true"/>
<h:outputLabel for="email" value="Email"/>
<h:inputText id="email" value="#{SignUpBean.email}" required="true">
<f:validator validatorId="emailValidator"/>
</h:inputText>
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="passwordTab" title="">
<p:panel header="Password">
<h:messages/>
<h:panelGrid id="panel2" columns="2">
<h:outputLabel for="password" value="Password"/>
<h:inputSecret id="password" value="#{SignUpBean.password}" required="true"/>
<h:outputLabel for="retypePass" value="Retype Password"/>
<h:inputSecret id="retypePass" value="#{SignUpBean.retypePassword}" required="true"/>
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="groupTab" title="">
<p:panel header="Group">
<h:messages/>
<h:panelGrid id="panel3" columns="2">
<h:outputLabel for="radioGroup" value=""/>
<h:selectOneRadio id="radioGroup" value="#{SignUpBean.join}">
<f:selectItem itemValue="true" itemLabel="Join existing group"/>
<f:selectItem itemValue="false" itemLabel="Create new group"/>
</h:selectOneRadio>
Group Name
<h:inputText id="group" value="#{SignUpBean.group}" required="true"/>
Group Password
<h:inputSecret id="groupPass" value="#{SignUpBean.groupPass}" required="true"/>
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="confirmTab" title="">
<p:panel header="Confirm">
<h:messages/>
<p:growl id="signUpGrowl" sticky="false" life="1000" showDetail="true" />
<h:panelGrid id="panel4" columns="4" cellpadding="5">
Firstname:
<h:outputText value="#{SignUpBean.firstName}"/>
Lastname:
<h:outputText value="#{SignUpBean.lastName}"/>
Email:
<h:outputText value="#{SignUpBean.email}"/>
Groupname:
<h:outputText value="#{SignUpBean.group}"/>
<h:panelGroup style="display:block; text-align:center">
<p:commandButton value="Submit" action="#{SignUpBean.signUp}" update="signUpGrowl"/>
</h:panelGroup>
</h:panelGrid>
</p:panel>
</p:tab>
</p:wizard>
</h:form>
</f:view>
</ui:define>
And the signUpBean like this:
#ManagedBean(name="SignUpBean")
#SessionScoped
public class SignUpBean {
private String groupName, groupPass, firstName, lastName,
email, password, retypePassword;
private boolean join;
private boolean skip;
#EJB
private MessageBeanRemote messageBean2;
/** Creates a new instance of SignUpBean */
public SignUpBean() {
this.skip = false;
this.join = true;
}
/**
* Signs up a user with all the data given on the signUp.jsf page.
* If everything is ok then a confirmation email is generated and send
* to the new user.
* #return Either signUpSucces or signUpFailure
*/
public void signUp() {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction tx = session.beginTransaction();
// Boolean to decide if the data should be commited or not.
boolean commitOK = true;
UserHelper uh = new UserHelper();
BasicUser user = uh.getByEmail(this.email);
GroupHelper gh = new GroupHelper();
Group group = gh.getByName(this.groupName);
// If email does not already exist
if(user == null) {
user = new BasicUser();
user.setEmail(this.email);
user.setFirstName(this.firstName);
user.setLastName(this.lastName);
if(this.password.equals(this.retypePassword)) {
user.setPassword(password);
}
else {
commitOK = false;
FacesMessage fm = new FacesMessage("Passwords does not match");
FacesContext.getCurrentInstance().addMessage(null, fm);
}
}
else {
commitOK = false;
FacesMessage fm = new FacesMessage("Email does already exist");
FacesContext.getCurrentInstance().addMessage(null, fm);
}
// If it's a joiner to a group
if(this.join) {
// Is it the right groupPassword and groupName
if(group != null && group.getGroupPassword().equals(this.groupPass)) {
user.setGroup(group);
}
else {
commitOK = false;
FacesMessage fm = new FacesMessage("Wrong group name or password");
FacesContext.getCurrentInstance().addMessage(null, fm);
}
}
else {
if(group == null) {
group = new Group();
group.setGroupName(this.groupName);
group.setGroupPassword(this.groupPass);
user.setGroup(group);
}
else {
commitOK = false;
FacesMessage fm = new FacesMessage("Group does already exist");
FacesContext.getCurrentInstance().addMessage(null, fm);
}
}
//--- IF EVERYTHING OK THEN UPDATE THE DB ---//
if(commitOK) {
session.save(group);
session.save(user);
tx.commit();
session = HibernateUtil.getSessionFactory().getCurrentSession();
tx = session.beginTransaction();
BasicUser newUser = uh.getByEmail(email);
int id = newUser.getId();
MobileUser mobile = new MobileUser();
mobile.setId(id);
mobile.setUseWhen("Lost");
StatUser stats = new StatUser();
stats.setId(id);
stats.setRating("");
DateUser dates = new DateUser();
dates.setId(id);
Calendar calendar = Calendar.getInstance();
Date date = calendar.getTime();
dates.setMemberSince(date);
dates.setLastLogin(date);
session.save(stats);
session.save(mobile);
session.save(dates);
tx.commit();
//----- SEND CONFIRMATION EMAIL ----------//
BasicUser emailUser = uh.getByEmail(email);
MailGenerator mailGenerator = new ConfirmationMailGenerator(emailUser);
try {
StringWriter plain = mailGenerator.generatePlain();
StringWriter html = mailGenerator.generateHTML();
messageBean2.sendMixedMail(email, "WMC: Account Info", plain.toString(),
html.toString());
}
catch (Exception ex) {
Logger.getLogger(SignUpBean.class.getName()).log(Level.SEVERE, null, ex);
}
FacesMessage msg = new FacesMessage("Successful", "Welcome :" + this.getFirstName());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
//---- DO NOTHING ----//
}
public String onFlowProcess(FlowEvent event) {
if (skip) {
skip = false; //reset in case user goes back
return "confirm";
} else {
return event.getNewStep();
}
}
... getters and setters
}
I know it is a bad signup method and it will be changed later. When i reach the last tab and submit I get this error:
When I debug I see that the join variable is either true or false not null. What is it complaining about?
Change the variable declaration to:
private Boolean join;
instead of
private boolean join;
Make sure that you have appropriate getter and setter!
I solved the problem by adding a
<h:inputHidden value="#{SignUpBean.join}"/>
Inside the confirmation tab. This works:)

Resources