📄 editvoucherbean.java
字号:
package org.operamasks.example.ejb.gl.voucher;import java.util.ArrayList;import java.util.Date;import java.util.List;import java.util.UUID;import javax.faces.context.FacesContext;import javax.faces.model.SelectItem;import org.operamasks.example.ejb.gl.VoucherBean;import org.operamasks.example.ejb.gl.dao.OrmappingDaoBean;import org.operamasks.example.ejb.gl.entity.AccountView;import org.operamasks.example.ejb.gl.entity.Currency;import org.operamasks.example.ejb.gl.entity.Period;import org.operamasks.example.ejb.gl.entity.Person;import org.operamasks.example.ejb.gl.entity.Voucher;import org.operamasks.example.ejb.gl.entity.VoucherEntry;import org.operamasks.example.ejb.gl.entity.VoucherType;import org.operamasks.example.ejb.gl.util.VoucherEntryFactory;import org.operamasks.faces.annotation.Accessible;import org.operamasks.faces.annotation.Action;import org.operamasks.faces.annotation.BeforeRender;import org.operamasks.faces.annotation.Bind;import org.operamasks.faces.annotation.DataModel;import org.operamasks.faces.annotation.Inject;import org.operamasks.faces.annotation.Label;import org.operamasks.faces.annotation.ManagedBean;import org.operamasks.faces.annotation.ManagedBeanScope;import org.operamasks.faces.annotation.ManagedProperty;import org.operamasks.faces.annotation.Required;import org.operamasks.faces.annotation.SaveState;import org.operamasks.faces.annotation.SelectItems;import org.operamasks.faces.component.grid.impl.UIEditDataGrid;/** * * This managed bean is generated automatically */@ManagedBean(name="editVoucherBean", scope=ManagedBeanScope.REQUEST)public class EditVoucherBean extends VoucherDetailResource{ @ManagedProperty("#{ormappingDaoBean}") private OrmappingDaoBean dao; @Inject FacesContext context; @Label(value = "#{this.messages.get('OutputColumn.name.header')}") @Bind(id = "name", attribute = "value") @Required public String name; @Label(value = "#{this.messages.get('OutputColumn.number.header')}") @Bind(id = "number", attribute = "value") @Required public String number; @Label(value = "#{this.messages.get('OutputColumn.isCheck.header')}") @SelectItems(source = "#{this.boolean_items}") @Bind(id = "isCheck", attribute = "value") @Required public String isCheck = "false"; @Bind @SelectItems({ @org.operamasks.faces.annotation.SelectItem(value = "true", label = "#{this.messages.boolean_true}"), @org.operamasks.faces.annotation.SelectItem(value = "false", label = "#{this.messages.boolean_false}") }) public String isCheckEdit; @Accessible @Bind @SaveState public SelectItem[] boolean_items = { new SelectItem("true", "#{this.messages.boolean_true}"), new SelectItem("false", "#{this.messages.boolean_false}") }; @Label(value = "#{this.messages.get('OutputColumn.hasCashAccount.header')}") @SelectItems(source = "#{this.boolean_items}") @Bind(id = "hasCashAccount", attribute = "value") @Required public String hasCashAccount = "false"; @Label(value = "#{this.messages.get('OutputColumn.localDebitAmout.header')}") @Bind(id = "localDebitAmout", attribute = "value") @Required public Double localDebitAmout; @Label(value = "#{this.messages.get('OutputColumn.localCreditAmount.header')}") @Bind(id = "localCreditAmount", attribute = "value") @Required public Double localCreditAmount; @Label(value = "#{this.messages.get('OutputColumn.bookedDate.header')}") @Bind(id = "bookedDate", attribute = "value") @Required public Date bookedDate; @Label(value = "#{this.messages.get('OutputColumn.voucherAbstract.header')}") @Bind(id = "voucherAbstract", attribute = "value") @Required public String voucherAbstract; @Label(value = "#{this.messages.get('OutputColumn.cashierName.header')}") @SelectItems(source="#{this.personNameItems}") @Bind(id = "cashierName", attribute = "value") @Required public String cashierName; @Label(value = "#{this.messages.get('OutputColumn.posterName.header')}") @SelectItems(source="#{this.personNameItems}") @Bind(id = "posterName", attribute = "value") @Required public String posterName; @Label(value = "#{this.messages.get('OutputColumn.periodNumber.header')}") @SelectItems(source="#{this.periodNumberItems}") @Bind(id = "periodNumber", attribute = "value") @Required public String periodNumber; @Accessible @Bind @SaveState private List<SelectItem> periodNumberItems = new ArrayList<SelectItem>(); @Label(value = "#{this.messages.get('OutputColumn.voucherTypeName.header')}") @SelectItems(source="#{this.voucherTypeNameItems}") @Bind(id = "voucherTypeName", attribute = "value") @Required public String voucherTypeName; @Accessible @Bind @SaveState private List<SelectItem> voucherTypeNameItems = new ArrayList<SelectItem>(); @Label(value = "#{this.messages.get('OutputColumn.currencySign.header')}") @SelectItems(source="#{this.currencySignItems}") @Bind(id = "currencySign", attribute = "value") @Required public String currrencySign; @Accessible @Bind @SaveState private List<SelectItem> currencySignItems = new ArrayList<SelectItem>(); @SaveState private String id; @Inject VoucherBean voucherBean; @BeforeRender public void beforeRender(boolean isPostback) { if(!isPostback){ periodNumberItems.clear(); for(Period period : dao.getPeriods()){ periodNumberItems.add(new SelectItem(period.getId(),period.getNumber())); } voucherTypeNameItems.clear(); for(VoucherType voucherType:dao.getVoucherTypes()){ voucherTypeNameItems.add(new SelectItem(voucherType.getId(),voucherType.getName())); } currencySignItems.clear(); for(Currency currency:dao.getCurrencies()){ currencySignItems.add(new SelectItem(currency.getId(), currency.getSign())); } accountViewNameItems.clear(); for(AccountView accountView:dao.getAccounts()){ accountViewNameItems.add(new SelectItem(accountView.getId(),accountView.getName())); } personNameItems.clear(); for(Person person:dao.getPersons()){ personNameItems.add(new SelectItem(person.getId(),person.getName())); } id = voucherBean.getCurrentId(); voucher = dao.getVoucher(id); name = voucher.getName(); number = voucher.getNumber(); isCheck = Boolean.toString(voucher.getIsCheck()); hasCashAccount = Boolean.toString(voucher.getHasCashAccount()); localDebitAmout = Double.valueOf(voucher.getLocalCreditAmount()); localCreditAmount = Double.valueOf(voucher.getLocalCreditAmount()); bookedDate = voucher.getBookedDate(); voucherAbstract = voucher.getVoucherAbstract(); cashierName = voucher.getCashier().getId(); posterName = voucher.getPoster().getId(); periodNumber = voucher.getPeriod().getId(); voucherTypeName = voucher.getVoucherType().getId(); currrencySign = voucher.getCurrency().getId(); entries = voucher.getEntries(); } } @Action(id="save") @Label(value="#{this.messages.get('Button.save.label')}") public void save(){ voucher = dao.getVoucher(id); voucher.setBookedDate(bookedDate); voucher.setLocalCreditAmount(localCreditAmount.doubleValue()); voucher.setLocalDebitAmout(localDebitAmout.doubleValue()); voucher.setHasCashAccount(Boolean.parseBoolean(hasCashAccount)); voucher.setVoucherAbstract(voucherAbstract); voucher.setName(name); voucher.setNumber(number); voucher.setIsCheck(Boolean.parseBoolean(isCheck)); voucher.setCashier(dao.getPerson(cashierName)); voucher.setPoster(dao.getPerson(posterName)); voucher.setPeriod(dao.getPeriod(periodNumber)); voucher.setCurrency(dao.getCurrency(currrencySign)); voucher.setVoucherType(dao.getVoucherType(voucherTypeName)); if (addedData != null) { for (VoucherEntry voucherEntry : addedData) { voucherEntry.setId(UUID.randomUUID().toString()); voucherEntry.setAccountView(dao.getAccountView(voucherEntry.getAccountView().getId())); voucherEntry.setCurrency(dao.getCurrency(voucherEntry.getCurrency().getId())); voucherEntry.setCashier(dao.getPerson(voucherEntry.getCashier().getId())); voucherEntry.setVoucher(voucher); voucher.getEntries().add(voucherEntry); } } if (removedData != null){ List<VoucherEntry> removedEntries = new ArrayList<VoucherEntry>(); for (VoucherEntry entry : voucher.getEntries()) { for (VoucherEntry voucherEntry : removedData) { if (entry.getId().equals(voucherEntry.getId())) { removedEntries.add(entry); break; } } } voucher.getEntries().removeAll(removedEntries); } if(modifiedData != null) { for(VoucherEntry entry:voucher.getEntries()){ for(VoucherEntry voucherEntry:modifiedData){ if(entry.getId().equals(voucherEntry.getId())){ entry.setAccountView(voucherEntry.getAccountView()); entry.setCashier(voucherEntry.getCashier()); entry.setCurrency(voucherEntry.getCurrency()); entry.setDescription(voucherEntry.getDescription()); entry.setIsCheck(voucherEntry.getIsCheck()); entry.setLocalAmount(voucherEntry.getLocalAmount()); entry.setPrice(voucherEntry.getPrice()); entry.setQuantity(voucherEntry.getQuantity()); entry.setSeq(voucherEntry.getSeq()); break; } } } } dao.modifyVoucher(voucher); voucherEntry_grid_binding.commit(); } @Bind @SaveState private Voucher voucher; @Bind(id="voucherEntry_grid", attribute="binding") private UIEditDataGrid voucherEntry_grid_binding; @Bind private List<VoucherEntry> entries = new ArrayList<VoucherEntry>();// private VoucherEntry selectedVoucherEntry; @DataModel(id="voucherEntry_grid") public List<VoucherEntry> getVoucherEntry_gridValues(){ id = voucherBean.getCurrentId(); voucher = dao.getVoucher(id); return voucher.getEntries(); } @Action(id="add") @Label(value="#{this.messages.get('Button.add.label')}") public void add(){ voucherEntry_grid_binding.insertRow(0); } @Action(id="remove") @Label(value="#{this.messages.get('Button.remove.label')}") public void remove(){ voucherEntry_grid_binding.remove(); } // @Action(id="voucherAssistRecord")// @Label(value="#{this.messages.get('Button.voucherAssistRecord.label')}")// public void voucherAssistRecord(){// if(voucherEntry_grid_binding.isRowAvailable()){// selectedVoucherEntry = (VoucherEntry)voucherEntry_grid_binding.getRowData();// voucherAssistRecordWindow_binding.show();// }// // } @Bind @SaveState public List<SelectItem> accountViewNameItems = new ArrayList<SelectItem>(); @Accessible @Bind @SaveState private List<SelectItem> personNameItems = new ArrayList<SelectItem>(); @Bind(id="voucherEntry_grid", attribute="addedData") private VoucherEntry[] addedData; @Bind(id="voucherEntry_grid", attribute="removedData") private VoucherEntry[] removedData; @Bind(id="voucherEntry_grid", attribute="modifiedData") private VoucherEntry[] modifiedData; @Bind(id="voucherEntry_grid", attribute="bindBean") public VoucherEntryFactory bindBeanFactory = new VoucherEntryFactory(); // @Bind(id="voucherAssistRecord_grid", attribute="binding")// public UIEditDataGrid voucherAssistRecord_grid_binding; // @Bind(id="voucherAssistRecordWindow", attribute="binding")// public UIWindow voucherAssistRecordWindow_binding; // @DataModel(id="voucherAssistRecord_grid")// public List<VoucherAssistRecord> getVoucherAssistRecord_gridValues(){// if(selectedVoucherEntry != null){// return selectedVoucherEntry.getVoucherAssistRecords();// } else {// return new ArrayList<VoucherAssistRecord>();// }// } // @Action(id="addAssistRecord")// public void addAssistRecord(){// voucherAssistRecord_grid_binding.insertRow(0);// } // @Action(id="removeAssistRecord")// public void removeAssistRecord(){// voucherAssistRecord_grid_binding.remove();// } // @Bind(id="voucherAssistRecord_grid_binding", attribute="bindBean")// public Class bindBeanClass = VoucherAssistRecord.class; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -