Created
March 25, 2013 10:46
-
-
Save senthilmuthiah/5236317 to your computer and use it in GitHub Desktop.
Address Book Using JPA +ZK + Spring.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package zkoss.vm; | |
import java.util.HashMap; | |
import java.util.Map; | |
import org.zkoss.bind.BindUtils; | |
import org.zkoss.bind.annotation.AfterCompose; | |
import org.zkoss.bind.annotation.Command; | |
import org.zkoss.bind.annotation.ContextParam; | |
import org.zkoss.bind.annotation.ContextType; | |
import org.zkoss.bind.annotation.ExecutionArgParam; | |
import org.zkoss.zk.ui.Component; | |
import org.zkoss.zk.ui.select.Selectors; | |
import org.zkoss.zk.ui.select.annotation.Wire; | |
import org.zkoss.zk.ui.select.annotation.WireVariable; | |
import org.zkoss.zkplus.spring.SpringUtil; | |
import org.zkoss.zul.Window; | |
import addressbook.domain.AddressBook; | |
import addressbook.service.CRUDService; | |
public class AddressListCRUDVM { | |
@Wire("#addressCRUD") | |
private Window win; | |
@WireVariable | |
private CRUDService CRUDService; | |
private AddressBook selectedRecord; | |
private String recordMode; | |
private boolean makeAsReadOnly; | |
public AddressBook getSelectedRecord() { | |
return selectedRecord; | |
} | |
public void setSelectedRecord(AddressBook selectedRecord) { | |
this.selectedRecord = selectedRecord; | |
} | |
public String getRecordMode() { | |
return recordMode; | |
} | |
public void setRecordMode(String recordMode) { | |
this.recordMode = recordMode; | |
} | |
public boolean isMakeAsReadOnly() { | |
return makeAsReadOnly; | |
} | |
public void setMakeAsReadOnly(boolean makeAsReadOnly) { | |
this.makeAsReadOnly = makeAsReadOnly; | |
} | |
@AfterCompose | |
public void initSetup(@ContextParam(ContextType.VIEW) Component view, | |
@ExecutionArgParam("selectedRecord") AddressBook addressBook, | |
@ExecutionArgParam("recordMode") String recordMode) | |
throws CloneNotSupportedException { | |
Selectors.wireComponents(view, this, false); | |
setRecordMode(recordMode); | |
CRUDService = (CRUDService) SpringUtil.getBean("CRUDService"); | |
if (recordMode.equals("NEW")) { | |
this.selectedRecord = new AddressBook(); | |
} | |
if (recordMode.equals("EDIT")) { | |
this.selectedRecord = addressBook; | |
} | |
if (recordMode == "READ") { | |
setMakeAsReadOnly(true); | |
this.selectedRecord = addressBook; | |
win.setTitle(win.getTitle() + " (Readonly)"); | |
} | |
} | |
@Command | |
public void saveThis() { | |
Map<String, Object> args = new HashMap<String, Object>(); | |
CRUDService.save(this.selectedRecord); | |
args.put("selectedRecord", this.selectedRecord); | |
args.put("recordMode", this.recordMode); | |
BindUtils.postGlobalCommand(null, null, "refreshList", args); | |
win.detach(); | |
} | |
@Command | |
public void closeThis() { | |
win.detach(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment