Code: Select all
<?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:p="http://primefaces.prime.com.tr/ui">
<h:head>
<title>Show</title>
<link type="text/css" rel="stylesheet" href="Css/default.css" />
<script type="text/javascript">
function onInsertComplete(xhr, status, args) {
if(args.validationFailed || !args.flag) {
$(PrimeFaces.escapeClientId('form:dialog')).parent().effect("shake", { times:5 }, 100);
} else {
dlg.hide();
}
}
</script>
</h:head>
<h:body>
<p:growl id="growl" showDetail="true" life="3000" />
<f:view>
<h:form id="form" style="text-align: center" >
<p:commandButton value="Insert" title="Insert" image="ui-icon ui-icon-disk" oncomplete="dlg.show()" />
<p:dialog id="dialog" header="Login" widgetVar="dlg">
<h:panelGrid columns="2" cellpadding="4" style="text-align: center;">
<h:outputLabel value="Username:" />
<h:inputText id="username" value="#{userBean.userTbl.username}"/>
<h:outputLabel value="Password:" />
<h:inputText id="password" value="#{userBean.userTbl.password}"/>
<h:outputLabel value="Address:" />
<h:inputText id="address" value="#{userBean.userTbl.address}"/>
<h:outputLabel value="TblGroup:" />
<h:selectOneMenu id="tblGroup" value="#{userBean.userTbl.tblGroup}">
<!-- TODO: update below reference to list of available items-->
<f:selectItems value="#{userBean.groupList}"/>
</h:selectOneMenu>
<p:commandButton value="Save" actionListener="#{userBean.insert}" update="growl"
oncomplete="onInsertComplete(xhr, status, args)"/>
</h:panelGrid>
</p:dialog>
</h:form>
</f:view>
</h:body>
</html>
Code: Select all
public void insert(ActionEvent actionEvent) {
RequestContext context = RequestContext.getCurrentInstance();
FacesMessage msgs = null;
boolean flag = false;
if (userTbl.getUsername().trim().equals("")) {
flag = false;
msgs = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Invalid User Name", "User Name can't null !");
} else if (userTbl.getPassword().trim().equals("")) {
flag = false;
msgs = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Invalid Password", "Password can't null !");
} else if (userTbl.getAddress().trim().equals("")) {
flag = false;
msgs = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Invalid Address", "Address can't null !");
} else {
userSessionLc.insertUser(userTbl);
flag = true;
msgs = new FacesMessage(FacesMessage.SEVERITY_INFO, "OK", "Insert successful !");
}
FacesContext.getCurrentInstance().addMessage(null, msgs);
context.addCallbackParam("insert", flag);
}
Please Help me.