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
ae5c168e
Commit
ae5c168e
authored
Nov 30, 2017
by
Daniel González Peña
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Completes Departments management
parent
911c9d76
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
14 deletions
+90
-14
DepartmentsVM.java
src/main/java/dgpena/siexample/webapp/DepartmentsVM.java
+58
-0
edit_departments.zul
src/main/webapp/edit_departments.zul
+32
-14
No files found.
src/main/java/dgpena/siexample/webapp/DepartmentsVM.java
View file @
ae5c168e
...
...
@@ -4,7 +4,10 @@ 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
;
...
...
@@ -14,6 +17,11 @@ public class DepartmentsVM {
private
EntityManager
em
;
private
Departments
departments
;
private
boolean
isEditing
=
false
;
// department under edition...
private
Department
currentDepartment
;
@Init
public
void
init
()
{
this
.
em
=
DesktopEntityManagerManager
.
getDesktopEntityManager
();
...
...
@@ -23,4 +31,54 @@ public class DepartmentsVM {
public
List
<
Department
>
getDepartments
()
{
return
this
.
departments
.
findAll
();
}
public
Department
getCurrentDepartment
()
{
return
currentDepartment
;
}
public
void
setCurrentDepartment
(
Department
currentDepartment
)
{
this
.
currentDepartment
=
currentDepartment
;
}
@Command
@NotifyChange
(
"currentDepartment"
)
public
void
newDepartment
()
{
this
.
isEditing
=
false
;
this
.
currentDepartment
=
new
Department
();
}
@Command
@NotifyChange
(
"currentDepartment"
)
public
void
resetEditing
()
{
System
.
out
.
println
(
this
.
currentDepartment
.
getName
());
this
.
currentDepartment
=
null
;
}
@Command
@NotifyChange
({
"currentDepartment"
,
"departments"
})
public
void
saveDepartment
()
{
this
.
em
.
getTransaction
().
begin
();
if
(!
isEditing
)
{
this
.
departments
.
addNewDepartment
(
this
.
currentDepartment
);
}
this
.
em
.
getTransaction
().
commit
();
this
.
currentDepartment
=
null
;
}
@Command
@NotifyChange
(
"departments"
)
public
void
delete
(
@BindingParam
(
"d"
)
Department
department
)
{
this
.
em
.
getTransaction
().
begin
();
this
.
departments
.
deleteDepartment
(
department
);
this
.
em
.
getTransaction
().
commit
();
}
@Command
@NotifyChange
(
"currentDepartment"
)
public
void
edit
(
@BindingParam
(
"d"
)
Department
department
)
{
this
.
isEditing
=
true
;
this
.
currentDepartment
=
department
;
}
}
src/main/webapp/edit_departments.zul
View file @
ae5c168e
<zk>
<window title="
Hello World
" border="normal"
<window title="
Departments
" border="normal"
apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('dgpena.siexample.webapp.DepartmentsVM')"
>
<listbox model="@bind(vm.departments)">
<listhead>
<listheader label="name"></listheader>
<listheader label="actions"></listheader>
</listhead>
<template name="model">
<listitem>
<listcell><label value="@bind(each.name)"></label></listcell>
<listcell>work in progress</listcell>
</listitem>
</template>
<window title="Department Editor" mode="modal" visible="@load(vm.currentDepartment ne null)">
Name: <textbox value="@load(vm.currentDepartment.name) @save(vm.currentDepartment.name, before='saveDepartment')"></textbox>
<hbox>
<button label="accept" onClick="@command('saveDepartment')"></button>
<button label="cancel" onClick="@command('resetEditing')"></button>
</hbox>
</listbox>
</window>
<groupbox mold="3d" closable="false">
<caption label="Departments list">
<button label="new" onClick="@command('newDepartment')"></button>
</caption>
<listbox model="@bind(vm.departments)">
<listhead>
<listheader label="name"></listheader>
<listheader label="actions"></listheader>
</listhead>
<template name="model">
<listitem>
<listcell><label value="@bind(each.name)"></label></listcell>
<listcell>
<button label="edit" onClick="@command('edit', d=each)"></button>
<button label="delete" onClick="@command('delete', d=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