Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
si1718-example-project-webapp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Daniel González Peña
si1718-example-project-webapp
Commits
e926d3ad
You need to sign in or sign up before continuing.
Commit
e926d3ad
authored
Nov 30, 2017
by
Daniel González Peña
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds Employees management
parent
ae5c168e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
141 additions
and
0 deletions
+141
-0
EmployeesVM.java
src/main/java/dgpena/siexample/webapp/EmployeesVM.java
+91
-0
edit_employees.zul
src/main/webapp/edit_employees.zul
+50
-0
No files found.
src/main/java/dgpena/siexample/webapp/EmployeesVM.java
0 → 100644
View file @
e926d3ad
package
dgpena
.
siexample
.
webapp
;
import
java.util.List
;
import
javax.persistence.EntityManager
;
import
org.zkoss.bind.annotation.BindingParam
;
import
org.zkoss.bind.annotation.Command
;
import
org.zkoss.bind.annotation.Init
;
import
org.zkoss.bind.annotation.NotifyChange
;
import
dgpena.siexample.persistence.Department
;
import
dgpena.siexample.persistence.Departments
;
import
dgpena.siexample.persistence.Employee
;
import
dgpena.siexample.persistence.Employees
;
public
class
EmployeesVM
{
private
EntityManager
em
;
private
Employees
employees
;
private
Departments
departments
;
private
boolean
isEditing
=
false
;
// Employee under edition...
private
Employee
currentEmployee
;
@Init
public
void
init
()
{
this
.
em
=
DesktopEntityManagerManager
.
getDesktopEntityManager
();
this
.
employees
=
new
Employees
(
em
);
this
.
departments
=
new
Departments
(
em
);
}
public
List
<
Employee
>
getEmployees
()
{
return
this
.
employees
.
findAll
();
}
public
List
<
Department
>
getDepartments
()
{
return
this
.
departments
.
findAll
();
}
public
Employee
getCurrentEmployee
()
{
return
currentEmployee
;
}
public
void
setCurrentEmployee
(
Employee
currentEmployee
)
{
this
.
currentEmployee
=
currentEmployee
;
}
@Command
@NotifyChange
(
"currentEmployee"
)
public
void
newEmployee
()
{
this
.
isEditing
=
false
;
this
.
currentEmployee
=
new
Employee
();
}
@Command
@NotifyChange
(
"currentEmployee"
)
public
void
resetEditing
()
{
this
.
currentEmployee
=
null
;
}
@Command
@NotifyChange
({
"currentEmployee"
,
"employees"
})
public
void
saveEmployee
()
{
this
.
em
.
getTransaction
().
begin
();
if
(!
isEditing
)
{
this
.
employees
.
addNewEmployee
(
this
.
currentEmployee
);
}
this
.
em
.
getTransaction
().
commit
();
this
.
currentEmployee
=
null
;
}
@Command
@NotifyChange
(
"employees"
)
public
void
delete
(
@BindingParam
(
"e"
)
Employee
Employee
)
{
this
.
em
.
getTransaction
().
begin
();
this
.
employees
.
deleteEmployee
(
Employee
);
this
.
em
.
getTransaction
().
commit
();
}
@Command
@NotifyChange
(
"currentEmployee"
)
public
void
edit
(
@BindingParam
(
"e"
)
Employee
Employee
)
{
this
.
isEditing
=
true
;
this
.
currentEmployee
=
Employee
;
}
}
src/main/webapp/edit_employees.zul
0 → 100644
View file @
e926d3ad
<zk>
<window title="Employees" border="normal"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('dgpena.siexample.webapp.EmployeesVM')"
>
<window title="Employee Editor" mode="modal" visible="@load(vm.currentEmployee ne null)">
Name: <textbox value="@load(vm.currentEmployee.name) @save(vm.currentEmployee.name, before='saveEmployee')"></textbox>
Department:
<combobox model="@bind(vm.departments)" selectedItem="@load(vm.currentEmployee.department) @save(vm.currentEmployee.department, before='saveEmployee')">
<template name="model">
<comboitem label="@bind(each.name)"></comboitem>
</template>
</combobox>
<hbox>
<button label="accept" onClick="@command('saveEmployee')"></button>
<button label="cancel" onClick="@command('resetEditing')"></button>
</hbox>
</window>
<groupbox mold="3d" closable="false">
<caption label="Employees list">
<button label="new" onClick="@command('newEmployee')"></button>
</caption>
<listbox model="@bind(vm.employees)">
<listhead>
<listheader label="name"></listheader>
<listheader label="department"></listheader>
<listheader label="actions"></listheader>
</listhead>
<template name="model">
<listitem>
<listcell><label value="@bind(each.name)"></label></listcell>
<listcell><label value="@bind(each.department.name)"></label></listcell>
<listcell>
<button label="edit" onClick="@command('edit', e=each)"></button>
<button label="delete" onClick="@command('delete', e=each)"></button>
</listcell>
</listitem>
</template>
</listbox>
</groupbox>
</window>
</zk>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment