Consider the following code:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Crear Personas</title>
</h:head>
<h:body>
<f:view>
<h:form>
<h1><h:outputText value="Create/Edit"/></h1>
<h:panelGrid columns="2">
<h:outputLabel value="Perid:" for="perid" />
<h:inputText id="perid" value="#{lineaControl.persona.perid}" title="Perid" required="true" requiredMessage="The Perid field is required."/>
<h:outputLabel value="Pernombre:" for="pernombre" />
<h:inputText id="pernombre" value="#{lineaControl.persona.pernombre}" title="Pernombre" required="true" requiredMessage="The Pernombre field is required."/>
<h:outputLabel value="Perapellido:" for="perapellido" />
<h:inputText id="perapellido" value="#{lineaControl.persona.perapellido}" title="Perapellido" required="true" requiredMessage="The Perapellido field is required."/>
<h:outputLabel value="Pertelefonofijo:" for="pertelefonofijo" />
<h:inputText id="pertelefonofijo" value="#{lineaControl.persona.pertelefonofijo}" title="Pertelefonofijo" required="true" requiredMessage="The Pertelefonofijo field is required."/>
<h:outputLabel value="Perfechanacimiento:" for="perfechanacimiento" />
<h:inputText id="perfechanacimiento" value="#{lineaControl.persona.perfechanacimiento}" title="Perfechanacimiento" required="true" requiredMessage="The Perfechanacimiento field is required.">
<f:convertDateTime pattern="MM/dd/yyyy" />
</h:inputText>
<h:outputLabel value="Percedula:" for="percedula" />
<h:inputText id="percedula" value="#{lineaControl.persona.percedula}" title="Percedula" required="true" requiredMessage="The Percedula field is required."/>
</h:panelGrid>
<h:commandButton value="Crear" action="#{personaControl.crearPersona()}" ></h:commandButton>
</h:form>
</f:view>
</h:body>
</html>
This one is the view:
#Named(value = "personaControl")
#SessionScoped
public class PersonaControl implements Serializable {
/**
* Creates a new instance of PersonaControl
*/
public PersonaControl() {
persona = new Persona();
}
#EJB
private Persona persona;
PersonaFacade personaFacade;
public Persona getPersona() {
return persona;
}
public void setPersona(Persona persona) {
this.persona = persona;
}
public List<Persona> listarPersonas(){
return personaFacade.findAll();
}
public void crearPersona(){
personaFacade.create(persona);
persona = new Persona();
}
public void eliminarPersona(Persona newPersona){
persona = newPersona;
personaFacade.remove(persona);
persona = new Persona();
}
public String editarPersona(Persona newPersona){
persona = newPersona;
return "/Equipo/Editar";
}
public String editarPersona(){
personaFacade.edit(persona);
persona = new Persona();
return "/Equipo/Editar";
}
}
This one is the controller:
Entity and facade were generated using the NetBeans IDE, so when I try to create the new user, I get this error output:
Exception attempting to inject Remote ejb-ref name=controlador.PersonaControl/persona,Remote 3.x interface =entidades.Persona,ejb-link=null,lookup=,mappedName=,jndi-name=entidades.Persona,refType=Session into class controlador.PersonaControl: Lookup failed for 'java:comp/env/controlador.PersonaControl/persona' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
I cannot understand why I am getting this error output. I can't create any user.
Related
In my code, I have a textbox in which you can insert text and a button to 'publish' that text. Beneath there is a grid, in which all the previously published posts appear. The issue is that, using the #NotifyChange doesn't work, or I dont know how it works well enough to make it update the grid. Here is the .zul:
<!--Skipping code-->
<center style="padding:15px;" border="none">
<window>
<window title="Make post" border="normal">
<textbox id="publish" placeholder="Make a post"
height="40px" width="67%" multiline="true">
<attribute name="onChanging">
<![CDATA[
String value = event.value;
publSize.setValue("" + value.length() + "/300");
]]>
</attribute>
</textbox>
<space width="1%"/>
<textbox id="publSize" height="40px" width="6%" style="text-align:center" disabled="true" placeholder="0/300"/>
<space width="1%"/>
<button id="publicaBttn" label="Publicar" height="40px" width="25%" onClick="#command('addNewPost', p=publish)"/>
</window>
<separator bar="false"/>
<grid id="postGrid" height="550px" model="#init(vm.posts)" emptyMessage="Nothing in Posts.">
<template name="model">
<row>
<window border="normal">
<caption id="userName" label="#load(each.username)"/>
<textbox id="infoPost" readonly="true" value="#load(each.info)" multiline="true" rows="4" width="100%" mold="rounded"/>
<separator bar="true"/>
<hlayout>
<div>
<button label="Like" onClick="#command('addLike', index=each.index)"/>
</div>
<div hflex="true">
<textbox id="likeTB" disabled="true" width="3%" style="text-align:center" value="#load(each.likes)"/>
</div>
<div style="padding-right">
</div>
</hlayout>
</window>
</row></template></grid></window></center><!--...--></borderlayout></zk>
Here is the java controller:
#Command("addNewPost")
#NotifyChange("hConn")
public void addPost(#BindingParam("p") Textbox tbx) {
String text = tbx.getValue();
if (text == "") {
Messagebox.show("There must be text in a post.", null, 0, Messagebox.ERROR);
}
if (text.length() > 300) {
Messagebox.show("Posts must be under 300 characters.", null, 0, Messagebox.ERROR);
} else {
hConn.addPost(usuario,text);
}
BindUtils.postNotifyChange(null,null,this,"postGrid");
tbx.setValue("");
}
#Command("addLike")
#NotifyChange("hConn")
public void addLike(#BindingParam("index") String index) {
hConn.addLike(Integer.parseInt(index));
BindUtils.postNotifyChange(null,null,this,"postGrid");
}
When I either add a like or make i new post, the grid doesnt update to show the new like or the new post added. How can i solve this?
#init method is called when the view model is initialised. If you want updates you need to change model="#init(vm.posts)" to model="#load(vm.posts)". (I assume getPosts() in your view model returns hConn.
Some other observations:
You could use a custom constraint for your textbox. Something like (untested):
<textbox placeholder="Make a post" height="40px" width="67%" multiline="true" constraint="#load(vm.max300Constraint)" />
and in your view model:
public Constraint getMax300Constraint() {
return new Constaint() {
public void validate(Component comp, Object value) throws WrongValueException {
// check if text is greater than 300 characters
}
}
}
Another option is as follows:
<textbox placeholder="Make a post" height="40px" width="67%" multiline="true" onChanging="#command('checkLength', text=event.value)" />
and in your view model:
#Command
public void checkLength(#BindingParam("text") String text) {
// check text length
}
Both of these options also mean you can avoid putting the textbox component in your view model thereby embracing the values of MVVM.
I have a been called “FooOneBean” and that has a number of properties, one of which is “fooOnePropA’ which is a list of Foo objects.
In a Java Controller, this bean is set in the request as follows:
request.setAttibute(“FooOneBean”, FooOneBean.instance());
Normally, this can be used in a JSP to display the dropdown as follows:
<tiles:importAttribute name="elementName" />
<c:set var=”dropdown” value=”${FooOneBean.fooOnePropA}” /> <!—Name of the bean and property hard-coded here -- >
<form:select path="${elementName}" id="${elementName}">
<form:options items="${dropdown}" itemLabel="displayName" itemValue="code" />
</form:select>
However, what we have is a very generic JSP that should be able to display the dropdown based on the String name of the bean and property set in the JSP. The name of the bean or property can change based on how the JSP is invoked. So,
<tiles:importAttribute name="elementName" />
<tiles:importAttribute name="resourceBean" />
<tiles:importAttribute name="resourceList" />
<%--
<c:out value="${resourceBean}" /> <!—Displays “FooOneBean” -->
<c:out value="${resourceList}" /> <!—Displays “fooOnePropA” -->
--%>
<c:set var="beanName" value="${resourceBean}" />
<c:set var="propName" value="${resourceList}" />
<c:set var="dropdown" value="${beanName.propName }" />
<form:select path="${elementName}" id="${elementName}">
<form:options items="${dropdown}" itemLabel="displayName" itemValue="code" />
</form:select>
This will fail with the message: '${beanName.propName}' Property 'propName' not found on type java.lang.String
On the otherhand if dropdown is set as:
<c:set var="dropdown" value="${beanName}.${propName}" />
It fails with the error: Type [java.lang.String] is not valid for option items
How can this be accomplished in JSP? I am able to do this using Scriptlets that I want to avoid.
Thanks for the comments from JB Nizet. This can be done as:
<tiles:importAttribute name="elementName" />
<tiles:importAttribute name="resourceBean" />
<tiles:importAttribute name="resourceList" />
<c:set var="dropdown" value="${requestScope[resourceBean][resourceList]}”/>
<form:select path="${elementName}" id="${elementName}">
<form:options items="${dropdown}" itemLabel="displayName" itemValue="code" />
</form:select>
how to show validation error message if user has not selected any value of spring web mvc dropdown box. Not able to use #Notnull and #Notempty because I'm mapping anothor bean values using #manytoone. How to achieve this?. thanks
#Entity()
#Table(name = "QuestionType")
public class QuestionType {
#Id
#GeneratedValue
#Column(name = "id", nullable = false)
private int id;
#Column(name = "questionTypeName", length = 25, nullable = false)
#Pattern(regexp="[a-z|A-Z|\\s]+$",message = "*invalid")
#Size(max = 25, message = "*invalid")
#NotEmpty(message = "*")
private String questionTypeName;
#ManyToOne
//Here not able to use #Notnull & NotEmpty. I'm getting validator should not be used for primitive type
#JoinColumn(name = "domainid", referencedColumnName = "id", insertable = true, updatable = true)
private Domain domainId;
//getters and setters omited
}
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="form" uri="../../tlds/spring-form.tld"%>
<%# taglib prefix="core" uri="../../tlds/c.tld"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Question Type Page</title>
<link href="../../css/default.css" rel="stylesheet" />
</head>
<body>
<form:form commandName="questionType" action="QuestionTypePage.htm" method="post">
<table style="width: 100%; height: 100%;">
<tr height="20px">
<td><span class="label_Heading">Question Type</span></td>
</tr>
<tr height="30px">
<td><form:hidden path="id" />
<div align="center" style="width: 100%; border: solid 1px;"
class="div_Padding">
<span class="label_Normal">Question type</span> <span><form:input
cssClass="textbox_Normal" path="questionTypeName" maxlength="25"/> <form:errors
cssClass="errorMsg" path="questionTypeName" /> </span>
</div>
<div align="center" style="width: 100%; border: solid 1px;"
class="div_Padding">
<span class="label_Normal">Domain</span>
<span>
<form:select path="domainId.id">
<form:option value="0">Select</form:option>
<core:forEach items="${domainList}" var="domain">
<form:option value="${domain.id}">${domain.domainName}</form:option>
</core:forEach>
</form:select><form:errors path="domainId.id" cssClass="errorMsg"/>
</span>
</div></td>
</tr>
<tr height="20px">
<td class="line_Normal">
<table style="width: 100%;">
<tr>
<td><label class="statusMsg">Status :</label><label
class="statusMsg_Small">${statusMsg}</label></td>
<td align="right"><input type="submit" name="button"
value="${buttonValue}" class="button_Normal" /></td>
</tr>
</table>
</td>
</tr>
</form:form>
</body>
</html>
Your data binding is flawed. You should be using the domainId field itself (IMHO that should be named domain instead). Use a Converter to convert to/from that object.
First change the select in your JSP.
<form:select path="domainId" items="${domainList}" itemValue="id" itemLabel="domainName" />
Then your entity should have the #NotNull on the domainId field
#ManyToOne
#JoinColumn(name = "domainid", referencedColumnName = "id", insertable = true, updatable = true)
#NotNull
private Domain domainId;
Finally you need a PropertyEditor to convert the incoming id to a actual Domain object.
public class DomainEditor extends PropertyEditorSupport {
private DomainRepository repository;
public DomainEditor(DomainRepository repository) { this.repository=repository;}
public String getAsText() {
Domain value = (Domain) getValue();
return value != null ? String.valueOf(value.getId()) : "";
}
public void setAsText(String text) {
setValue(text == null ? null : repository.findOne(Integer.valueOf(text));
}
}
You can register this in your #Controller annotated class by adding a #InitBinder annotated method.
#InitBinder
public void initBinder(WebDataBinder dataBinder) {
dataBinder.registerCustomEditor(Domain.class, new DomainEditor(this.repository);
}
A final note for this to properly work make sure that you have a proper implementation of the equals and hashcode methods in the Domain class!
Links
Data Binding / Type Conversion (reference guide)
I have a .cfm and .cfc that I am using to edit data in a cfgrid on the .cfm, and it works, however 10% of the time I will get the following error message:
"Error invoking CFC /test/editCFgrid.cfc: Internal Server Error"
I tried using the debugging advice, however no luck.
Here is the CFM code:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<cfform name="artistform">
<cfgrid format="html" name="artistgrid" pagesize=11
striperows="yes"
bind="cfc:editCFgrid.getArtists({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
delete="yes" insert="yes" selectmode="edit"
onchange="cfc:editCFgrid.saveArtist({cfgridaction},{cfgridrow},{cfgridchanged})">
<cfgridcolumn name="firstname" header="First Name" />
<cfgridcolumn name="lastname" header="Last Name" />
<cfgridcolumn name="address" header="Address" />
<cfgridcolumn name="city" header="City" />
<cfgridcolumn name="state" header="State" />
<cfgridcolumn name="postalcode" header="Postal Code" />
<cfgridcolumn name="email" header="Email" />
<cfgridcolumn name="phone" header="Phone" />
<cfgridcolumn name="fax" header="Fax" />
<cfgridcolumn name="thepassword" header="Password" />
</cfgrid>
</cfform>
</body>
</html>
Here is the CFC code:
<cfcomponent output="FALSE">
<cffunction name="getArtists" hint="I extract artists from the database" access="remote" output="FALSE" returntype="struct">
<cfargument name="page" required="TRUE" hint="the page the grid is on" />
<cfargument name="pagesize" required="TRUE" hint="records displayed per page" />
<cfargument name="gridsortcolumn" required="TRUE" hint="selected column to sort" />
<cfargument name="gridsortdirection" required="TRUE" hint="the sort direction" />
<cfset var qArtists = "" />
<cfif arguments.gridsortcolumn eq "">
<cfset arguments.gridsortcolumn = "lastname" />
<cfset arguments.gridsortdirection = "asc" />
</cfif>
<cfquery name="qArtists" datasource="test_database">
SELECT *
FROM Artists
ORDER BY #arguments.gridsortcolumn# #arguments.gridsortdirection#
</cfquery>
<cfreturn QueryConvertForGrid( qArtists, arguments.page, arguments.pagesize ) />
</cffunction>
<cffunction name="saveArtist" type="any" hint="I insert, update or delete an artist" access="remote" output="FALSE" returntype="void">
<cfargument name="gridaction" type="any" required="TRUE" hint="I for insert, U for update and D for delete" />
<cfargument name="gridrow" type="any" required="TRUE" hint="the rows being inserted or updated" />
<cfargument name="gridchanged" type="any" hint="the changes" />
<cfset var qInsertArtist = "" />
<cfset var qUpdateArtist = "" />
<cfset var qDeleteArtist = "" />
<cfif IsStruct( arguments.gridrow ) and IsStruct( arguments.gridchanged )>
<cfif arguments.gridaction eq "I">
<cfquery name="qInsertArtist" datasource="test_database">
INSERT INTO Artists
(firstname, lastname, address, city, state, postalcode, email, phone, fax, thepassword)
VALUES
(<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.firstname#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.lastname#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.address#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.city#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.state#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.postalcode#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.email#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.phone#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.fax#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.thepassword#" />)
</cfquery>
<cfelseif arguments.gridaction eq "U">
<cfset var colname = StructKeyList( arguments.gridchanged ) />
<cfset var value = StructFind( arguments.gridchanged, colname ) />
<cfquery name="qUpdateArtist" datasource="test_database">
UPDATE Artists
SET #colname# = <cfqueryparam value="#value#" />
WHERE artistid = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.gridrow.artistid#" />
</cfquery>
<cfelseif arguments.gridaction eq "D">
<cfquery name="qDeleteArtist" datasource="test_database">
DELETE FROM Artists
WHERE artistid = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.gridrow.artistid#" />
</cfquery>
</cfif>
</cfif>
</cffunction>
</cfcomponent>
Each function (edit, insert, delete, etc) works, but it randomly will generate the error. Ultimately, I am seeking a code that will ignore/block/"OK" the error message so the user won't see it.
Any help will be greatly appreciated! I have spent the entire day (9 hours) googling for an answer, but I haven't found any. I do not have access to the CF Admin Log, I'm just a regular developer. Thanks!
Google chrome, firebug in firefox, IE developer tools can all help you with this.
In google chrome (my preference), right click on your page > inspect element. Then go to the network tab. You'll have to refresh your web page. Then you will see your cfc in the list of files (probably RED). Right click > open in new tab, and you'll open the cfc directly with all the arguments being called. You should then be able to see your error.
There is no ignore/block/ok. You need to fix the error.
Perhaps a time out or a SQL error. To get the full error use: cferror, this tag show a full debug information (better than debug server info) I sent it to me by mail:
Put this on you Application file:
<cferror type="exception" template="error.cfm" />
<cferror type="request" template="error.cfm" />
Create a "error.cfm" file with:
"Error message"
<cfsavecontent variable="errorContent">
<cfoutput>
An error occurred: http://#cgi.server_name##cgi.script_name#?#cgi.query_string#<br />
Time: #dateFormat(now(), "short")# #timeFormat(now(), "short")#<br />
<h2>Error:</h2>
<cfdump var="#error#" label="Error">
<h2>Form:</h2>
<cfdump var="#form#" label="Form">
<h2>URL:</h2>
<cfdump var="#url#" label="URL">
<h2>SESSION:</h2>
<cfdump var="#SESSION#" label="SESSION">
</cfoutput>
</cfsavecontent>
<cfmail to="mail#mymail.com" from="mail#mymail.com" subject="Error on #cgi.server_name#: #error.message#" type="html">
#errorContent#
</cfmail>
There is a way to ignore/block/ok the "error" message with the following script:
<script>ColdFusion.setGlobalErrorHandler(function (error)
{mygrid = ColdFusion.Grid.refresh ('artistgrid', false);
}
);
</script>
Insert this script in the CFM files, and you're good to go! Being that the error that I was encountering was not impacting the function (editing the cells) of the cfgrid (the pop-up message was being more of a nuisance then anything else). Hopefully this solution will help others!
You do not need to use the 'Grid.refresh' command in the script, you can use anything command you want.
Thanks everyone who attempted to answer my issue!
I've been read this article : commandButton/commandLink/ajax action/listener method not invoked or input value not updated
but still i cant understand why my problems weren't solved.
i'm afraid that my understanding for the english explanation were not fully correctly. so i'll lay down my code snippets here.
fyi, i'm still got medium level of understanding english. my english capability is just so-so.
i'm using Primefaces 3.0.RC1, EL library 2.2, JSF 2.1, JSTL 1.1, GlassFish 3.x, coded with Netbeans 7.0.1
now here we come the codes:
template.xhtml
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<h:outputStylesheet name="default.css" library="css"/>
<h:outputStylesheet name="cssLayout.css" library="css"/>
<h:outputStylesheet name="style.css" library="css"/>
<title>MFI Core Banking System</title>
</h:head>
<h:body>
<f:view>
<div id="top">
<ui:include src="header.xhtml"/>
</div>
<div id="menuBar">
<ui:include src="menubar.xhtml"/>
</div>
<div id="content" class="center_content">
<ui:insert name="content">Content</ui:insert>
</div>
<div id="bottom">
<ui:include src="footer.xhtml"/>
</div>
</f:view>
</h:body>
header.xhtml and footer.xhtml just had UI:Composition declaration and <div/> and <a href/> tag only.
menubar.xhtml as below :
<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">
<f:view>
<h:form>
<p:menubar >
<p:menuitem value="Home" action="/index.xhtml?faces-redirect=true" icon="ui-icon ui-icon-home"/>
<p:submenu label="CIF" icon="ui-icon ui-icon-bookmark">
<p:menuitem value="Manajemen CIF" action="/modul/cif/cifManagement?faces-redirect=true"/>
<p:submenu label="CIF Grouping ">
<p:menuitem value="Search" action="/modul/cif/SearchGroupNew.xhtml?faces-redirect=true"/>
<p:menuitem value="Create" action="/modul/cif/CreateGroupNew.xhtml?faces-redirect=true"/>
</p:submenu>
<p:menuitem value="Analyze" url="#"/>
<p:menuitem value="Directorate " action="/modul/userManagement/Struktural.Directorate.xhtml?faces-redirect=true"/>
</p:submenu>
</p:menubar>
</h:form>
</f:view>
</ui:composition>
this is my example page (Directorate) :
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
template="./../../template.xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:define name="top">
Directorate
</ui:define>
<ui:define name="menuBar">
menuBar
</ui:define>
<ui:define name="content">
<f:view contentType="text/html">
<h:form prependId="false">
<p:panel toggleable="true" closable="true" header="Direktorat">
<p:fieldset legend="Tambah Direktorat"
toggleable="TRUE"
collapsed="#{directorateBean.fieldsetCollapse}"
toggleSpeed="500"
>
<h:panelGrid columns="3">
<h:outputLabel for="directorateCode" value="Kode Direktorat*"/>
<p:inputText id="directorateCode" value="#{directorateBean.directorate.directoratecode}" required="true" label="Kode Direktorat" maxlength="4"/>
<p:message for="directorateCode"/>
<h:outputLabel for="directorateName" value="Nama Direktorat*"/>
<p:inputText id="directorateName" value="#{directorateBean.directorate.directoratename}" required="true" label="Nama Direktorat" maxlength="40"/>
<p:message for="directorateName"/>
<h:outputLabel for="directorateStatus" value="Status Direktorat"/>
<p:selectOneRadio id="directorateStatus" value="#{directorateBean.directorate.directoratestatus}">
<f:selectItem itemValue="true" itemLabel="Aktif"/>
<f:selectItem itemValue="false" itemLabel="Tidak Aktif"/>
</p:selectOneRadio>
<p:spacer/>
<p:commandButton id="btnSubmitDirectorate" value="Submit" update="#form" action="#{directorateBean.add()}"/>
<p:commandButton value="Reset" type="reset"/>
</h:panelGrid>
</p:fieldset>
<p:spacer/><p:spacer/>
<p:dataTable
id="tableDirectorate"
emptyMessage="Tidak Ada Direktorat"
value="#{directorateBean.directorateList}"
var="dir"
paginator="true"
paginatorPosition="bottom"
rows="10"
rowsPerPageTemplate="10,20,50"
>
<f:facet name="header">Daftar Direktorat</f:facet>
<p:column sortBy="#{dir.directoratecode}" filterBy="#{dir.directoratecode}" filterMatchMode="contains" >
<f:facet name="header"><h:outputText value="Kode Direktorat"/></f:facet>
<h:outputText value="#{dir.directoratecode}"/>
<h:commandLink value="#{dir.directoratecode}" actionListener="#{directorateBean.test}"/>
</p:column>
<p:column sortBy="#{dir.directoratename}" filterBy="#{dir.directoratename}" filterMatchMode="contains" >
<f:facet name="header"><h:outputText value="Nama Direktorat"/></f:facet>
<h:outputText value="#{dir.directoratename}"/>
</p:column>
<p:column style="width: 100px;">
<f:facet name="header"><h:outputText value="Direktorat Status"/></f:facet>
<p:commandButton icon="ui-icon ui-icon-check" title="Active" rendered="#{dir.directoratestatus == true}"/>
<p:commandButton icon="ui-icon ui-icon-closethick" title="Inactive" rendered="#{dir.directoratestatus == false}"/>
</p:column>
<p:column style="width: 100px;">
<p:commandButton icon="ui-icon ui-icon-search" title="View #{dir.directoratename} Details"/>
<p:commandButton icon="ui-icon ui-icon-pencil" title="Edit #{dir.directoratename}" action="#{directorateBean.edit(dir)}" update="panelDetail" oncomplete="updateDlg.show();"/>
<p:commandButton icon="ui-icon ui-icon-trash" title="Delete #{dir.directoratename}"/>
</p:column>
</p:dataTable>
</p:panel>
<p:dialog header="Corfirmation" widgetVar="confirmDialog" resizable="false" id="confirm" showEffect="fade" modal="true" >
<h:outputText value="Confirm Delete ?"/>
<h:panelGrid columns="2">
<p:commandButton value="Cancel" update="#form" />
<p:commandButton value="Delete" update="#form"/>
</h:panelGrid>
</p:dialog>
<p:dialog header="Directorate Detail" widgetVar="updateDlg" resizable="false" id="updateDialog" showEffect="fade" modal="true" >
<h:panelGrid id="panelDetail" columns="3" cellpadding="2">
<h:outputLabel for="editDirectorateCode" value="Kode Direktorat*"/>
<p:inputText id="editDirectorateCode" value="#{directorateBean.selectedDirectorate.directoratecode}" required="true" label="Kode Direktorat" maxlength="4"/>
<p:message for="editDirectorateCode"/>
<h:outputLabel for="editDirectorateName" value="Nama Direktorat*"/>
<p:inputText id="editDirectorateName" value="#{directorateBean.selectedDirectorate.directoratename}" required="true" label="Nama Direktorat" maxlength="40"/>
<p:message for="editDirectorateName"/>
<h:outputLabel for="editDirectorateStatus" value="Status Direktorat"/>
<p:selectOneRadio id="editDirectorateStatus" value="#{directorateBean.selectedDirectorate.directoratestatus}">
<f:selectItem itemValue="true" itemLabel="Aktif"/>
<f:selectItem itemValue="false" itemLabel="Tidak Aktif"/>
</p:selectOneRadio>
<p:spacer/>
<p:commandButton id="btnUpdateDirectorate" value="Simpan" update="#form" action="#{directorateBean.update()}"/>
<p:commandButton value="Reset" type="reset"/>
</h:panelGrid>
</p:dialog>
</h:form>
</f:view>
</ui:define>
<ui:define name="bottom">
bottom
</ui:define>
</ui:composition>
and here is the managed bean :
#ManagedBean(name = "directorateBean")
#ViewScoped
public class structuralDirectorateManagedBean implements Serializable {
private DirectorateDAO directorateService;
/* Initialize variable */
private List<Directorate> directorateList;
private Directorate directorate = new Directorate();
private Directorate selectedDirectorate = new Directorate();
private static final String Creator;
private boolean fieldsetCollapse = true;
private boolean DirectorateStatus = false;
/* init */
#PostConstruct
public void init() throws SQLException {
if (directorateService == null) {
directorateService = FactoryDAO.getDirectorateDAO();
}
directorateList = directorateService.findAll();
directorate.setDirectoratestatus(DirectorateStatus);
directorate.setCreator(Creator);
}
/* Basic Method */
public void add() throws SQLException {
System.out.println("Directorate Code : " + directorate.getDirectoratecode());
directorateService.create(directorate); // insert record to datatabse
directorateList.add(directorate); // insert object to List<Object>
directorate = new Directorate(); // Reset Form
directorate.setDirectoratestatus(DirectorateStatus); // set default
directorate.setCreator(Creator); // set default
}
public void test(){
System.out.println("TEST!!");
}
public void edit(Directorate directorate) {
System.out.println("Directorate code to edit : " + directorate.getDirectoratecode());
this.selectedDirectorate = directorate;
}
public void delete(Directorate directorate) throws SQLException {
directorateService.remove(directorate); // delete record within Database
directorateList.remove(directorate); // delete record within List
}
public void update(ActionEvent event) throws SQLException {
directorateService.edit(selectedDirectorate); // update record to database
selectedDirectorate = new Directorate(); // reset form
}
/** Getter Setter */
public List<Directorate> getDirectorateList() throws SQLException {
return directorateList;
}
public Directorate getDirectorate() {
return directorate;
}
public boolean isFieldsetCollapse() {
return fieldsetCollapse;
}
public void setFieldsetCollapse(boolean fieldsetCollapse) {
this.fieldsetCollapse = fieldsetCollapse;
}
public Directorate getSelectedDirectorate() {
return selectedDirectorate;
}
public void setSelectedDirectorate(Directorate selectedDirectorate) {
this.selectedDirectorate = selectedDirectorate;
}
}
everything runs smooth, displaying record from database, p:selectOneMenu runs well.
this button were runs well too :
<p:commandButton id="btnSubmitDirectorate" value="Submit" update="#form" action="#{directorateBean.add()}"/>
but, this button and commandLink were not working, the Action and ActionListener both not fired :
<p:commandButton icon="ui-icon ui-icon-pencil" title="Edit #{dir.directoratename}" action="#{directorateBean.edit(dir)}" update="panelDetail" oncomplete="updateDlg.show();"/>
<p:commandLink value="#{dir.directoratecode}" actionListener="#{directorateBean.test}"/>
i'm sorry if i'm asking too much, maybe i'm the dumb here.. XD
but i just cannot get over it and just begin to frustated..
thanks for your responds.. :)
have a nice day..
You have one big <h:form> in the "Directorate" view with a lot of different sections. When you invoke an action in one of the sections, then the data of all other sections will also be submitted (and validated!). It look like that you didn't notice those "Value is required" validation messages at first sight because those sections are collapsed/hidden by default.
You need to remove the "God" <h:form> and give the fieldset, the datatable and the two dialogs each its own <h:form>. So you should have 4 separate forms, each with its own responsibility. They can however without problems be bound to the one and same bean.
By the way, the <f:view> does not belong in the include files nor the template clients. There should be only one in the master template.