From cd2e3eaf50ba30c64a1392c2d0631f49443914f5 Mon Sep 17 00:00:00 2001 From: willemc Date: Thu, 6 May 2010 18:34:30 +0200 Subject: [PATCH] fix annotion parser bug and made some logger changes and added max page size support --- .../annotations/VascAnnotationParser.java | 75 ++++++++++++------- .../vasc/core/AbstractVascBackendState.java | 15 ++++ .../idcanet/vasc/core/VascBackendState.java | 3 + .../web/jsf/JSFVascEntrySupportBean.java | 37 +++++++-- .../web/jsf/JSFVascUIComponentRenderer.java | 19 ++++- .../web/jsf/JSFVascValidatePhaseListener.java | 3 + .../idcanet/vasc/impl/DefaultVascFactory.java | 1 + .../vasc/impl/DefaultVascFrontendHelper.java | 5 ++ .../vasc/impl/DefaultVascSelectItemModel.java | 14 +++- 9 files changed, 134 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/idcanet/vasc/annotations/VascAnnotationParser.java b/src/main/java/com/idcanet/vasc/annotations/VascAnnotationParser.java index f4f36ce..e4f07c7 100644 --- a/src/main/java/com/idcanet/vasc/annotations/VascAnnotationParser.java +++ b/src/main/java/com/idcanet/vasc/annotations/VascAnnotationParser.java @@ -179,37 +179,47 @@ public class VascAnnotationParser { public String getVascDisplayName(Class beanClass) { //System.out.println("========== GetDisPlayName: "+beanClass); + + // first search in class for display name for (Method method:beanClass.getMethods()) { if (method.getName().startsWith("get")==false) { //a bit durty continue; } - VascFieldTemplate template = method.getAnnotation(VascFieldTemplate.class); - if (template!=null) { - //System.out.println("Search template for: "+method.getName()); - String tempProp = method.getName().substring(3); - if ("".equals(template.template())==false) { - tempProp = template.template(); - } - for (Method method2:template.templateClass().getMethods()) { - if (method2.getName().equalsIgnoreCase("get"+tempProp)==false) { //a bit durty - continue; - } - Annotation anno = method2.getAnnotation(VascDisplayName.class); - //System.out.println("Template annot: "+anno+" prop: "+tempProp); - if (anno==null) { - break; - } - //System.out.println("Found template"); - return method.getName().substring(3,4).toLowerCase()+method.getName().substring(4); // field name without get - } - } Annotation anno = method.getAnnotation(VascDisplayName.class); if (anno==null) { continue; } - //System.out.println("Found normal"); return method.getName().substring(3,4).toLowerCase()+method.getName().substring(4); // field name without get } + + // then search in class for display name on templated fields. + for (Method method:beanClass.getMethods()) { + if (method.getName().startsWith("get")==false) { //a bit durty + continue; + } + VascFieldTemplate template = method.getAnnotation(VascFieldTemplate.class); + if (template==null) { + continue; // no template anno + } + //System.out.println("Search template for: "+method.getName()); + String tempProp = method.getName().substring(3); + if ("".equals(template.template())==false) { + tempProp = template.template(); + } + for (Method method2:template.templateClass().getMethods()) { + if (method2.getName().equalsIgnoreCase("get"+tempProp)==false) { //a bit durty + continue; + } + Annotation anno = method2.getAnnotation(VascDisplayName.class); + //System.out.println("Template annot: "+anno+" prop: "+tempProp); + if (anno==null) { + break; + } + //System.out.println("Found template"); + return method.getName().substring(3,4).toLowerCase()+method.getName().substring(4); // field name without get + } + } + //System.out.println("Defraulting to key"); return getVascPrimaryKey(beanClass); // fall back on primary key } @@ -245,23 +255,32 @@ public class VascAnnotationParser { } public String getVascPrimaryKey(Class beanClass) { + + // first search Key anno for (Method method:beanClass.getMethods()) { if(method.getName().startsWith("get")==false) { //a bit durty continue; } - VascFieldTemplate template = method.getAnnotation(VascFieldTemplate.class); - if (template!=null) { - String value = getVascPrimaryKey(template.templateClass()); - if (value!=null) { - return value; - } - } Annotation anno = method.getAnnotation(VascPrimaryKey.class); if (anno==null) { continue; } return method.getName().substring(3,4).toLowerCase()+method.getName().substring(4); // field name without get } + + for (Method method:beanClass.getMethods()) { + if(method.getName().startsWith("get")==false) { //a bit durty + continue; + } + VascFieldTemplate template = method.getAnnotation(VascFieldTemplate.class); + if (template==null) { + continue; // no template + } + String value = getVascPrimaryKey(template.templateClass()); // note templateing the templated class is possible + if (value!=null) { + return value; + } + } return null; // maybe fallback on getId() ? } diff --git a/src/main/java/com/idcanet/vasc/core/AbstractVascBackendState.java b/src/main/java/com/idcanet/vasc/core/AbstractVascBackendState.java index 4d7119b..e4fc903 100644 --- a/src/main/java/com/idcanet/vasc/core/AbstractVascBackendState.java +++ b/src/main/java/com/idcanet/vasc/core/AbstractVascBackendState.java @@ -41,6 +41,7 @@ abstract public class AbstractVascBackendState implements VascBackendState { protected Map parameters = null; private int pageIndex = 0; private int pageSize = 0; + private int pageSizeMax = 0; private String sortField = null; private String searchString = null; private boolean ascending = true; @@ -131,4 +132,18 @@ abstract public class AbstractVascBackendState implements VascBackendState { public void setSortField(String sortField) { this.sortField=sortField; } + + /** + * @return the pageSizeMax + */ + public int getPageSizeMax() { + return pageSizeMax; + } + + /** + * @param pageSizeMax the pageSizeMax to set + */ + public void setPageSizeMax(int pageSizeMax) { + this.pageSizeMax = pageSizeMax; + } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/core/VascBackendState.java b/src/main/java/com/idcanet/vasc/core/VascBackendState.java index d3a32fd..cb48a78 100644 --- a/src/main/java/com/idcanet/vasc/core/VascBackendState.java +++ b/src/main/java/com/idcanet/vasc/core/VascBackendState.java @@ -49,6 +49,9 @@ public interface VascBackendState extends Serializable { public void setPageSize(int size); public int getPageSize(); + public void setPageSizeMax(int size); + public int getPageSizeMax(); + public void setPageIndex(int index); public int getPageIndex(); diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java index d841442..02dfed2 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java @@ -504,6 +504,8 @@ public class JSFVascEntrySupportBean implements Serializable { VascEntryState state = vascEntry.getVascFrontendData().getVascEntryState(); try { + setSelectedMultiRowAction("null"); // reset to selected ... value + for (Integer rowId:state.getMultiActionSelection().keySet()) { Boolean value = state.getMultiActionSelection().get(rowId); logger.fine("multiRow selected: "+rowId+" value: "+value); @@ -511,9 +513,11 @@ public class JSFVascEntrySupportBean implements Serializable { Object row = state.getEntryDataList().get(rowId); logger.finer("row: "+row); action.doRowAction(vascEntry, row); + if (action.getId().equals(DeleteRowAction.ACTION_ID)) { + return; + } } } - setSelectedMultiRowAction("null"); // reset to selected ... value state.getMultiActionSelection().clear(); // after down deselect all options } catch (Exception e) { // TODO Auto-generated catch block @@ -802,7 +806,9 @@ public class JSFVascEntrySupportBean implements Serializable { logger.fine("cancelAction"); JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); VascEntry entry = comp.getVascEntry(); - this.getSelected().setRealValue(false); + if (getSelected()!=null) { + getSelected().setRealValue(false); + } entry.getVascFrontendData().getVascEntryState().setEntryDataObject(null); try { entry.getVascFrontendData().getVascFrontend().renderView(); @@ -844,7 +850,26 @@ public class JSFVascEntrySupportBean implements Serializable { logger.fine("deleteAction"); JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); VascEntry entry = comp.getVascEntry(); - entry.getVascFrontendData().getVascFrontendHelper().deleteObject(entry); + VascEntryState state = entry.getVascFrontendData().getVascEntryState(); + if (state.getMultiActionSelection().isEmpty()==false) { + List sels = new ArrayList(5); + for (Integer rowId:state.getMultiActionSelection().keySet()) { + Boolean value = state.getMultiActionSelection().get(rowId); + logger.fine("multiRow delete: "+rowId+" value: "+value); + if (value!=null && value==true) { + Object row = state.getEntryDataList().get(rowId); + sels.add(row); + } + } + for (Object row:sels) { + entry.getVascFrontendData().getVascEntryState().setEntryDataObject(row); + entry.getVascFrontendData().getVascFrontendHelper().deleteObject(entry); + } + state.getMultiActionSelection().clear(); // after down deselect all options + } else { + entry.getVascFrontendData().getVascFrontendHelper().deleteObject(entry); + } + try { entry.getVascFrontendData().getVascFrontend().renderView(); } catch (Exception e) { @@ -862,7 +887,7 @@ public class JSFVascEntrySupportBean implements Serializable { // TODO: FIX this change listener is called before save action in row EDIT... if (id==null) { - logger.info("FIXME: unexcepted call to direct download"); + logger.finer("FIXME: unexcepted call to direct download"); return; } @@ -920,7 +945,7 @@ public class JSFVascEntrySupportBean implements Serializable { // TODO: FIX this change listener is called before save action in row EDIT... if (id==null) { - logger.info("FIXME: unexcepted call to direct page change"); + logger.finer("FIXME: unexcepted call to direct page change"); return; } @@ -967,7 +992,7 @@ public class JSFVascEntrySupportBean implements Serializable { * @param selected the selected to set */ public void setSelected(VascDataBackendBean selected) { - logger.info("Set selected records: "+selected+" on: "+this); + logger.fine("Set selected records: "+selected+" on: "+this); this.selected = selected; } diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java index a5bc241..c06e9b8 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java @@ -28,6 +28,7 @@ package com.idcanet.vasc.frontends.web.jsf; import java.io.IOException; import java.io.Serializable; +import java.lang.reflect.Constructor; import java.util.List; import java.util.logging.Logger; @@ -291,9 +292,21 @@ public class JSFVascUIComponentRenderer extends Renderer { model.setValue(option.getDefaultValue()); UIInput jsfEdit = (UIInput)editor.createComponent(entry,option,model,grid); jsfEdit.addValueChangeListener(new ModelChangeListener(model)); - - editor.setDisabled(false); // TODO: HACK for JSFLIST for model remove me ! - + Class clazz = option.getVascEntryFieldType().getAutoDetectClass(); + if (clazz!=null && model.getValue()!=null) { + if (clazz.equals(model.getValue().getClass())==false) { + // lets try setting correct default. + try { + Constructor c = clazz.getConstructor(String.class); + Object value = c.newInstance(model.getValue()); + jsfEdit.setValue(value); + } catch (Exception e) { + throw new VascException(e); + } + } else { + jsfEdit.setValue(model.getValue()); // set default value + } + } // i==0 is for multi field editor support... which is stell very in progress aka not working if (i==0) { entry.getVascFrontendData().addFieldVascUIComponents(option, editor,jsfEdit); diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascValidatePhaseListener.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascValidatePhaseListener.java index 823d9f8..215a239 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascValidatePhaseListener.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascValidatePhaseListener.java @@ -51,6 +51,9 @@ public class JSFVascValidatePhaseListener implements PhaseListener { if (comp==null) { return; // non-vasc ui-input } + if (comp.getSupportBean().getSelected()==null) { + return; // no editing + } VascEntry entry = comp.getVascEntry(); if (entry.getVascFrontendData().getVascEntryState().getEntryDataObject()==null) { return; // we are not in edit mode. diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascFactory.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascFactory.java index ea257f6..b04c453 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascFactory.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascFactory.java @@ -82,6 +82,7 @@ public class DefaultVascFactory { vascFrontendData.setVascEntryState(new DefaultVascEntryState()); vascFrontendData.getVascEntryState().setVascBackendState(new DefaultVascBackendState()); vascFrontendData.getVascEntryState().getVascBackendState().setPageSize(100); // default page size is zero aka disabled + vascFrontendData.getVascEntryState().getVascBackendState().setPageSizeMax(1000); // max 1k records on screen. vascFrontendData.setExceptionListener(new VascEntryEventListener() { private static final long serialVersionUID = 1L; public void vascEvent(VascEntry entry, VascEventType type,Object data) { diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java index 68570ef..76d24f7 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java @@ -353,6 +353,11 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { public void refreshData(VascEntry entry) { entry.getVascFrontendData().getVascEntryState().setEntryDataObject(null); try { + // check and correct max page size + if (entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSize()>entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSizeMax()) { + entry.getVascFrontendData().getVascEntryState().getVascBackendState().setPageSize(entry.getVascFrontendData().getVascEntryState().getVascBackendState().getPageSizeMax()); + } + for (String key:entry.getEntryParameterKeys()) { Object value = entry.getEntryParameter(key); entry.getVascFrontendData().getVascEntryState().getVascBackendState().setDataParameter(key, value); diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascSelectItemModel.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascSelectItemModel.java index a780ddd..9784ad8 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascSelectItemModel.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascSelectItemModel.java @@ -95,13 +95,25 @@ public class DefaultVascSelectItemModel implements VascSelectItemModel { result.add(item); } - // set para + // set def para VascBackendState state = new DefaultVascBackendState(); for (String key2:ve.getEntryParameterKeys()) { Object value = ve.getEntryParameter(key2); //System.out.println("Copy paras name: "+key2+" value: "+value+" class: "+value.getClass().getName()); state.setDataParameter(key2, value); } + + // set list para + for (VascEntryField vef:ve.getListOptions()) { + Object def = vef.getDefaultValue(); + if (def==null) { + continue; + } + String backendName = vef.getBackendName(); + state.setDataParameter(backendName, def); + } + + // set para from parent state entry for (String paraName:entryParameterFieldIds.keySet()) { VascEntry fieldEntry = entry;