I have a JSF page where I can add or delete "planes" in my database (JBDC). To help with that I have two beans (Both #RequestScoped), one "controller" and one "backing bean".
Here is the JSF page:
And with some inputs:
After inputting info and adding a photo, the "airplane" is added to my page, and I reload the page.
Here is how the page looks after submitting:
My issue here is that, the input textfields gets "populated" from the bean with the info, and also the delete plane field gets populated with the airplane id. I want these fields to be empty after refreshing, and thats why I thought using #RequestScoped would be useful. Also, If I try to refresh the page from my web browser, it just tries to resend the form.
How can I avoid the fields being populated with data from the bean?
Also, here is bean code:
#Named
#RequestScoped
public class AddAirplaneCtrl implements Serializable{
#Inject
private FlightModel flightModel;
private ListAirplaneBB listAirplaneBB;
protected AddAirplaneCtrl(){
;
}
#Inject
public void addListAirplaneBB(ListAirplaneBB listAirplaneBB){
this.listAirplaneBB = listAirplaneBB;
}
public String addPlane(){
listAirplaneBB.setError(null);
listAirplaneBB.setMessage(null);
if(failed any of the validation parts){
return /some/site?faces-redirect=false";
}
//add plane
return /some/site?faces-redirect=true";
}
}
And the Backing Bean:
#Named
#RequestScoped
public class ListAirplaneBB implements Serializable{
#Inject
private FlightModel flightModel;
//private variable fields
public List<Airplane> getAllPlanes(){
return flightModel.getAirplaneList().findAll();
}
public int getTotalPlanes(){
return getAllPlanes().size();
}
//GETTERS and SETTERS
}
And finally my jsf page:
<div class="contbox">
<h3>
<h:outputLabel value="Edit Planes" />
</h3>
<c:if test="#{not empty listAirplaneBB.error}">
<div class="alert alert-danger"
id="success-alert">
<span class="glyphicon glyphicon-remove" />
<h:outputText value="#{listAirplaneBB.error}" />
<button type="button"
class="close"
data-dismiss="alert">
<h:outputLabel value="x" />
</button>
</div>
</c:if>
<c:if test="#{not empty listAirplaneBB.message}">
<div class="alert alert-success">
<span class="glyphicon glyphicon-remove" />
<h:outputText value="#{listAirplaneBB.message}" />
<button type="button"
class="close"
data-dismiss="alert">
<h:outputLabel value="x" />
</button>
</div>
</c:if>
<h4>Add A Plane</h4>
<h:form enctype="multipart/form-data">
<table id="addtable"
class="table">
<thead>
<tr>
<th>
<h:outputLabel value="Plane Make" />
</th>
<th colspan="1">
<h:outputLabel value="Plane Model" />
</th>
<th colspan="1">
<h:outputLabel value="Plane Seats" />
</th>
<th colspan="1">
<h:outputLabel value="Plane Photo" />
</th>
</tr>
</thead>
<tr>
<td>
<h:inputText value="#{listAirplaneBB.make}">
</h:inputText>
</td>
<td>
<h:inputText value="#{listAirplaneBB.model}">
</h:inputText>
</td>
<td>
<h:inputText value="#{listAirplaneBB.seats}">
</h:inputText>
</td>
<td>
<h:inputFile value="#{listAirplaneBB.file}" >
</h:inputFile>
</td>
<td>
<h:commandButton value="Add Plane"
class="btn btn-primary"
action="#{addAirplaneCtrl.addPlane()}" >
</h:commandButton>
</td>
</tr>
</table>
</h:form>
<h4>Delete Plane</h4>
<h:form>
<h:panelGrid columns="3" class="table">
<h:outputLabel value="Plane ID" />
<h:inputText value="#{listAirplaneBB.airPlaneId}"/>
<h:commandButton value="Delete"
class="btn btn-primary"
action="#{addAirplaneCtrl.deleteAirplane}" >
</h:commandButton>
</h:panelGrid>
</h:form>
</div>
Your browser cache the inputs.
JSF 2.2 Solution
<ui:composition 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:pt="http://xmlns.jcp.org/jsf/passthrough">
...
<f:passThroughAttribute name="autocomplete" value="off"/>
...
jQuery Solution:
<h:form styleClass="form">...</h:form>
<script>
$(function(){
$(".form").attr("autocomplete", "off");
});
</script>
You can find more information here.
Related
I got trouble in JSF when I try to delete the row content from database through commandLink inside dataTable element.
So I got the bean with viewScopped and managedScoped like this :
#ViewScoped
#ManagedBean
public class DivisiController implements Serializable{
private static final long serialVersionUID = 1L;
private String konten;
private String deskripsi;
private Long id;
private Divisi selectedDivisi;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Divisi getSelectedDivisi() {
if(selectedDivisi == null){
selectedDivisi = new Divisi();
}
return selectedDivisi;
}
public void setSelectedDivisi(Divisi selectedDivisi) {
this.selectedDivisi = selectedDivisi;
}
public String getKonten() {
return konten;
}
public void setKonten(String konten) {
this.konten = konten;
}
public String getDeskripsi() {
return deskripsi;
}
public void setDeskripsi(String deskripsi) {
this.deskripsi = deskripsi;
}
public void halo(){
System.out.println("Hi, I'm halo");
}
public void delete(){
DivisiDAO dao = new DivisiDAO();
dao.beginTransaction();
try{
Divisi persistedDivisi = dao.findReferenceOnly(selectedDivisi.getId());
dao.delete(persistedDivisi);
}
catch(Exception e){
dao.rollback();
addMessage("System Error", "Please try again later.");
e.printStackTrace();
}
dao.commitAndCloseTransaction();
}
public void addMessage(String summary, String detail) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary, detail);
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
Then, I try to set selectedDivisi value when delete button clicked from the jsf page. And hope that my delete method would be delete the selected value.
I attempt to send item, as a division value, through f:setPropertyActionListener
But unfortunately, I always stuck with null value at my backing bean (DivisiController).
I try to debug, set breakpoint at my selectedDivisi setter, and the result is, the selectedDivisi value null. It seems like, my selectedDivisi never set with #{item} from my button.
Here is the snippet of, how I manage to draw html from jsf, and call my backing bean to perform an action.
<div class="col-md-12">
<!-- Custom Tabs -->
<h:form id="form">
<div class="nav-tabs-custom">
<ul class="nav nav-tabs">
<li class="active" >
<a id="lampiran" data-toggle="tab" href="#tab_2" aria-expanded="false">
<i class="fa fa-list">
</i> Daftar Divisi</a></li>
<li class="">
<a data-toggle="tab" href="#tab_1" aria-expanded="false">
<i class="fa fa-pencil"></i> Buat Divisi</a>
</li>
</ul>
<div class="tab-content">
<div id="tab_2" class="tab-pane active">
<h:panelGroup layout="block" id="berkas" class="row">
<div class="col-md-12">
<div class="box-footer text-right top-buffer">
<ui:include src="list.xhtml"/>
</div>
</div>
</h:panelGroup>
</div><!-- /.tab-pane -->
<div id="tab_1" class="tab-pane">
<h:panelGroup layout="block" id="tembusan" class="row">
<div class="col-md-12">
<ui:include src="create-form.xhtml"/>
</div>
</h:panelGroup>
<div class="box-footer text-right top-buffer">
<h:commandLink action="#{divisiController.create}" class="btn btn-primary">
Buat Baru <i class="fa fa-arrow-circle-right"></i>
</h:commandLink>
</div>
</div><!-- /.tab-pane -->
</div><!-- /.tab-content -->
</div><!-- nav-tabs-custom -->
</h:form>
<p:confirmDialog header="Confirmation"
message="#{divisiController.selectedDivisi.id}"
global="true"
showEffect="fade"
hideEffect="fade"
widgetVar="confirmDialogWidget">
<h:form>
<h:outputText value="#{divisiController.selectedDivisi.id}"/>
<p:commandButton value="Yes" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" action="#{divisiController.delete()}" />
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</h:form>
</p:confirmDialog>
</div>
That was the index.html, which included the list.xhtml (as you can see), and here is list.xhtml snippet :
<?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">
<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:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:dv="http://xmlns.jcp.org/jsf/composite/mycomp">
<div class="row">
<div class="col-md-12 complex">
<dv:data-table value="#{divisiController.view()}"
id="surat"
scrollable="true"
scrollableHeight="500">
<p:column headerText="Konten" width="40%" styleClass="text-left" style="width: 44%">
<h:outputText value="#{item.konten}"/>
</p:column>
<p:column headerText="Deskripsi" width="40%" styleClass="text-left" style="width: 44%">
<h:outputText value="#{item.deskripsi}"/>
</p:column>
<p:column headerText="Aksi" styleClass="text-left">
<h:outputLink styleClass="btn btn-primary text-white" value="edit.xhtml">
<i class="fa fa-edit"></i>
<f:param name="id" value="#{item.id}" />
</h:outputLink>
<p:commandLink styleClass="btn btn-primary text-white" update=":form">
<h:panelGroup styleClass="fa fa-trash" />
<f:setPropertyActionListener value="#{item}" target="#{divisiController.selectedDivisi}" />
<p:confirm header="Confirmation" message="Are you sure?" icon="ui-icon-alert" />
</p:commandLink>
</p:column>
</dv:data-table>
</div>
</div>
</ui:composition>
As you can see at the last snippet, I try to set the selectedDivisi through this snippet :
<f:setPropertyActionListener value="#{item}" target="#{divisiController.selectedDivisi}" />
But it always error. And if I try to direct pass the {item} to my delete method from bean (if I set the delete method with input parameter), then it will goes same with the previous technique(from <f:setPropertyActionListener>).
So, how this can happened, and what the thing that makes it mess?
Thanks in advance with your help.
I don't have enough reputation to comment. I think it is setting nulls due to the scope.
If you see #BalusC answer on View scoped managed bean with setPropertyActionListener he advises us to use f:param and f:viewParam in #ViewScoped
Updated on comment from #user3057361: Do not call the action="#{divisiController.delete()} from the confirmDialog's yes Button if you are using the global mode of ConfirmDialog. IMHO, your p:commandLink in list.xhtml should be changed to a . Keep everything else. The yes and no button in the confirmDialog should not have action methods for global confirm dialog. Once you click yes, the action in the caller of your confirmDialog is called automatically
I have a datatable and form. Both are wrapped by html5 section tag. The table rendered correctly for edit, delete and cancel edit options, but doesn't work with save (save edits) and add new record(f:ajax execute).
I'm so new in JSF, so i can't understand very well how works ajax here.
I'm using JSF 2.2 (Mojarra) and GlassFish 4.1
Facelet:
<h:form id="toDoForm">
<!-- todo table -->
<section class="todo-table">
<h:dataTable id="toDoTable" value="#{toDoBean.toDoList}" var="toDo" styleClass="table">
<h:column>
<f:facet name="header"><h:outputText value="ToDo name"/></f:facet>
<h:inputText value="#{toDo.name}" rendered="#{toDo.editable}"/>
<h:outputText value="#{toDo.name}" rendered="#{not toDo.editable}"/>
</h:column>
<!-- action command links -->
<h:column>
<f:facet name="header"><h:outputText value="Actions"/></f:facet>
<h:commandLink value="Edit" action="#{toDoBean.edit(toDo)}" rendered="#{not toDo.editable}">
<f:ajax render="toDoForm:toDoTable"/>
</h:commandLink>
<h:commandLink value="Save" action="#{toDoBean.save(toDo)}" rendered="#{toDo.editable}">
<f:ajax execute="toDoForm" render="toDoForm:toDoTable"/>
</h:commandLink>
<h:commandLink value="Cancel" action="#{toDoBean.cancelEdit(toDo)}" rendered="#{toDo.editable}">
<f:ajax render="toDoForm:toDoTable"/>
</h:commandLink>
<h:commandLink value="Delete" action="#{toDoBean.delete(toDo)}" rendered="#{not toDo.editable}">
<f:ajax render="toDoForm:toDoTable"/>
</h:commandLink>
</h:column>
</h:dataTable>
</section>
<!-- new toDo -->
<section class="new-todo">
<section class="frm-group">
<h:outputLabel for="todo-name" value="ToDo name"/>
<h:inputText id="todo-name" p:placeholder="Some task here..." value="#{toDoBean.toDo.name}"/>
</section>
<section class="frm-group">
<h:outputLabel for="todo-date" value="Limit date"/>
<h:inputText id="todo-date" p:placeholder="dd-MM-yyyy" value="#{toDoBean.toDo.expDate}"/>
</section>
<!-- just for add a fontawesome icon to button -->
<button type="submit" jsf:action="toDoBean.add()">
<i class="fa fa-check"></i>
Add record
<f:ajax execute="toDoForm" render="toDoForm:toDoTable"/>
</button>
</section>
</h:form>
UPDATE
The developer tools shows the ajax request:
Request headers
The response of ajax request is this:
<?xml version='1.0' encoding='UTF-8'?>
<partial-response id="j_id1"><changes><update id="toDoForm:toDoTable"><![CDATA[<table id="toDoForm:toDoTable" class="table">
<thead>
<tr>
<th scope="col">ToDo name</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>Learn JSF 2.2</td>
<td><a id="toDoForm:toDoTable:0:j_idt17" href="#" onclick="mojarra.ab(this,event,'action',0,'toDoForm:toDoTable');return false">Edit</a><a id="toDoForm:toDoTable:0:j_idt20" href="#" onclick="mojarra.ab(this,event,'action',0,'toDoForm:toDoTable');return false">Delete</a></td>
</tr>
<tr>
<td>Learn CDI</td>
<td><a id="toDoForm:toDoTable:1:j_idt17" href="#" onclick="mojarra.ab(this,event,'action',0,'toDoForm:toDoTable');return false">Edit</a><a id="toDoForm:toDoTable:1:j_idt20" href="#" onclick="mojarra.ab(this,event,'action',0,'toDoForm:toDoTable');return false">Delete</a></td>
</tr>
<tr>
<td>Learn JPA 2.1</td>
<td><a id="toDoForm:toDoTable:2:j_idt17" href="#" onclick="mojarra.ab(this,event,'action',0,'toDoForm:toDoTable');return false">Edit</a><a id="toDoForm:toDoTable:2:j_idt20" href="#" onclick="mojarra.ab(this,event,'action',0,'toDoForm:toDoTable');return false">Delete</a></td>
</tr>
<tr>
<td>Learn WebSockets</td>
<td><a id="toDoForm:toDoTable:3:j_idt17" href="#" onclick="mojarra.ab(this,event,'action',0,'toDoForm:toDoTable');return false">Edit</a><a id="toDoForm:toDoTable:3:j_idt20" href="#" onclick="mojarra.ab(this,event,'action',0,'toDoForm:toDoTable');return false">Delete</a></td>
</tr>
<tr>
<td>Learn EJB 3.1</td>
<td><a id="toDoForm:toDoTable:4:j_idt17" href="#" onclick="mojarra.ab(this,event,'action',0,'toDoForm:toDoTable');return false">Edit</a><a id="toDoForm:toDoTable:4:j_idt20" href="#" onclick="mojarra.ab(this,event,'action',0,'toDoForm:toDoTable');return false">Delete</a></td>
</tr>
</tbody>
</table>
]]></update><update id="j_id1:javax.faces.ViewState:0"><![CDATA[758921174082037358:-1177618745060004189]]></update></changes></partial-response>
Thanks.
I am using to enter address field .by default am setting active-index="-1" so the panel will be closed when the page gets loaded.After the details has been entered by user i want the panel area which means i want the accordion panel to be closed on button(save) click.but i tried a lot using java script but am not able to achieve ,and here is page
<h:body>
<ui:composition template="/WEB-INF/templates/layout.xhtml">
<ui:define name="content">
<h:form id="quotesForm">
<div class="headerbg">
<div id="innerheaderbg">
<div id="iconarea">
<img src="#{request.contextPath}/images/headerimages/productlist.png" />
</div>
<div id="headertextarea">
<p class="headingtext">New Quote</p>
<p id="breadCrumbtext">Order <img src="#{request.contextPath}/images/error-bullet.gif" />
Quote List <img src="#{request.contextPath}/images/error-bullet.gif" />
New Quote
</p>
</div>
</div>
</div>
<p:growl id="msgs" />
<div class="widget widget-table action-table">
<div class="widget-header" style="text-align:center;padding-top: 52px">
<h3>Create New Quote</h3>
</div>
<div class="widget-content" style="background-color: #DAEDF4;height: 600px;" >
<div id="calender" style="margin-left: 52px;margin-top: -26px">
<table>
<tr>
<td>
<p:outputLabel id="qDate" value="#{quotesBean.qtCreationDate}"></p:outputLabel>
</td>
<td>
<p:calendar id="popup" showOn="button" display="inline" >
<p:ajax event="dateSelect" listener="#{quotesBean.onDateSelect}" update="qDate" />
</p:calendar>
</td>
</tr>
</table>
<p:outputLabel value="Invoice # #{quotesBean.qCount}" style="margin-top:-15px;margin-left:10px;"/>
</div>
<div id="company">
<table align="right" style="margin-right: 52px">
<thead>
<tr>
<th style="text-align: center;padding: 0;"><img src="#{request.contextPath}/images/favicon.ico"/><p:spacer width="5px"/>SolvEdge</th>
</tr>
</thead>
<tr><td style="text-align: center;padding: 0;">Zameen Pallavaram,</td></tr>
<tr><td style="text-align: center;padding: 0;">Chennai,</td></tr>
<tr><td style="text-align: center;padding: 0;">INDIA</td></tr>
</table>
</div>
<h:form id="addForm">
<p:accordionPanel id="accordion" cache="false" activeIndex="-1" style="margin-bottom:20px;width:330px;" widgetVar="acc" >
<p:tab title="Bill To Address:" titleStyle="width:330px;background-color:#DAEDF4" >
<h:panelGrid columns="2">
<h:outputLabel value="Name" />
<h:inputText value="#{quotesBean.name}"/>
<h:outputLabel value="Street" />
<h:inputText value="#{quotesBean.street}"/>
<h:outputLabel value="City" />
<h:inputText value="#{quotesBean.city}"/>
<h:outputLabel value="ZIP" />
<h:inputText value="#{quotesBean.zip}"/>
</h:panelGrid>
<p:commandButton icon="ui-icon-save" value="Save" action="#{quotesBean.saveAddress}" update=":quotesForm:addForm:accordion" ajax="false" onclick="PF('quotesForm:addForm:accordion').hide();"/>
</p:tab>
</p:accordionPanel>
</h:form>
</div>
</div>
<script type="text/javascript">
var link = document.getElementById('quotesForm:popup_input');
link.style.display = 'none';
function closeAccordianPanel()
{
var panel = document.getElementById('quotesForm:addForm:accordion');
link.style.activeIndex = '-1';
/* PF('widget_accordion').unselect(0); */
}
</script>
</h:form>
<br></br>
</ui:define>
</ui:composition>
</h:body>
</html>
Note:Java Script i tried here is nothing worked for me,i would like to close the accordion panel on button click.
I bet you have javascript errors in the console...(PF('quotesForm:addForm:accordion').hide(); is wrong, it should be PF('acc').hide(); IF it works at all (nothing about that in the PrimeFaces docs). And why close a ui component via javascript if you do an 'ajax="false"'. And sending a click event to the tab you want to toggle works, but even better is to use the official client-side api: PF('acc').unselect(...);
Ahhhh... you have additional code below the commandbutton... but there is a wrong widgetVar value... and it is commented out... and the other part does nothing...
Unselect(index of tab) method only hide the p:tab.
If you want to hide your accordionPanel, you can use rendered attribute.
Here is the panel:
<p:panel id="toggleable" header="Toggleable" toggleable="true"
toggleOrientation="horizontal" toggleSpeed="500" closeSpeed="500"
widgetVar="panel" class="left-menu-panel" >
</p:panel>enter code here`
and button or commandLink which collapse panel
<p:commandLink styleClass="open-left-menu-button"
onclick="PF('panel').toggle()">
</p:commandLink>
You can set it with toggleOrientation="horizontal/vertical".
normal panel - not collapsed
collapsed
hi I'm working with PrimeFaces. When I encountered this problem. I want to display the values I entered in the form while clicking the save button
and the XHTML file is
<!DOCTYPE html>
<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"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>
calender popup problem
</title>
</h:head>
<body>
<h:form>
<TABLE>
<tr>
<td><h:outputText value="*"/></td>
<td><h:outputText value="COUPOUN NAME" /></td>
<td><p:inputText id="coupounname" maxlength="50" value="#{office.coupounname}"/></td>
</tr>
<tr style="padding-top: 10px">
<td><h:outputText value="*"/></td>
<td><h:outputText value="COUPOUN CODE" /></td>
<td><p:inputText id="couponcode" value="#{office.coupouncode}"/></td>
</tr>
<tr style="padding-top:10px">
<td><h:outputText value="*"/></td>
<td><h:outputText value="COUPOUN DESCRIPTION"/></td>
<td><p:inputTextarea id="coupoundes" value="#{office.coupouncode}"/></td>
</tr>
<tr style="padding-top: 10px">
<td><h:outputText value= "*"/></td>
<td><h:outputText value="Discount"/></td>
<!-- <td>
<p:selectOneRadio id="radiobuttons" value="#{office.percentage}">
<f:selectItem itemLabel="in ruppes" itemValue="ByCash"/>
<f:selectItem itemLabel="inpercentage" itemValue="InPercentage"/>
</p:selectOneRadio>
</td> -->
</tr>
<tr>
<td><h:outputText value="*"/></td>
<td><h:outputText value="Validity"/></td>
<td><p:calendar value="#{office.startdate}"/></td>
<td><p:calendar value="#{office.enddate}"/></td>
</tr>
<tr>
<td><p:commandButton id="save" value="save" action="#{officebean.save}"/></td>
<td><p:commandButton id="cancel" value="cancel"/></td>
</tr>
</TABLE>
</h:form>
<ui:include src="dialogs.xhtml"/>
</body>
</html>
and the dialog is stored in the file
<p:dialog id="listdialog" visible="${officebean.dialogvisible eq 'Bean'} " dynamic="true" minHeight="120">
<h:form id="dialogform">
<h:outputText value=" the value entered by the users were"/>
<table>
<tr>
<td>name:=<h:outputText value="#{office.coupounname}"/></td>
<td>code:<h:outputText value="#{officebean.dialogvisible}"/</td>
</tr>
</table>
</h:form>
</p:dialog>
now the bean class which contains the action for save button which sets the condition which makes the dialog visible
#ManagedBean(name="officebean")
#RequestScoped
public class Officebean {
private List<Office>officeList;
private Office office;
private String Dialogvisible;
public void save() {
Dialogvisible="Bean";
}
public List<Office> getOfficeList() {
return officeList;
}
public void setOfficeList(List<Office> officeList) {
this.officeList = officeList;
}
public Office getOffice() {
return office;
}
public void setOffice(Office office) {
this.office = office;
}
public String getDialogvisible() {
return Dialogvisible;
}
public void setDialogvisible(String dialogvisible) {
Dialogvisible = dialogvisible;
}
}
but dialog is not showing up when save button is clicked any held would be appreciated
I'd guess you need to use
<h:body> instead of <body>
<p:dialog id="listdialog" widgetVar="listdialog".... >
<p:commandButton oncomplete="PF('listdialog').show()" ... />
and maybe remove visible from the dialog.
try
<p:commandButton id="save" value="save" action="#{officebean.save}" update="listdialog"/>
but if you want to show as a popup you are going to have to use
<p:commandButton id="save" value="save" action="#{officebean.save}" update="listdialog" oncomplete="#{p:widgetVar('listDialog')}.show();"/>
First you have to know that a dialog doesn't show until you call in some way the show() function...
if the other answers don't work for you maybe you can add in dialogs.xhtml this:
firt you have to add the widgetVar variable at the dialog like something like:
<p:dialog id="listdialog" visible="${officebean.dialogvisible eq 'Bean'} " dynamic="true" minHeight="120" widgetVar="listdialog">
Then outside the dialog something like:
<p:remoteCommand id="rc1" name="showDialog"oncomplete="PF('listdialog').show();" />
And to finish:
<script type="text/javascript">
showDialog();
</script>
This should open your dialog as soon you open the dialogs.xhtml....
Good luck!
I have an inputText and an inputTextArea in JSF (shown below) that I carry out an ajax action on. However, after my ajax event, the values remain in the input boxes. Is there a simple way to refresh these text boxes after the commandButton is involked? Thanks.
<table>
<tr>
<td><div class="white"><H2>Comments</H2></div>
<h:inputText class="inputboxes" id="username"
value="#{commentBean.comment.commentname}" size="20">
</h:inputText><br/><br/>
<h:inputTextarea rows="5" cols="55" id="comment" class="inputbox" value="#{commentBean.comment.commentText}"
size="20" /></td>
</tr>
<tr>
<td></td>
<td><h:commandButton id="update"
action="#{commentBean.addComment(searchBean.companyId)}" class="myButton2" value="Add Comment" >
<f:ajax execute="#form" render=":results"/>
</h:commandButton></td>
</tr>
</table>
</h:form>
<h:form id="results">
<table>
<tr>
<td>
<h:dataTable value="#{commentBean.viewComments(searchBean.companyId)}" var="c">
<h:column>
<div class="commentsbox">#{c.commentText}</div>
</h:column>
<h:column>
<div class="boldfont">#{c.commentdate}</div>
</h:column>
<td><h:column>
<div class="commentname">#{c.commentname}</div>
</h:column>
</td>
</h:dataTable>
</td>
</tr>
</table>
In your view :
<f:ajax execute="#this" render=":results, username, comment"/>
In your backing bean, in the addComment() method :
comment.setCommentname(null);
comment.setCommentText(null);
or simply (I guess only)
comment = null;