From c1a8402ae8d53fa7eb98f0484b234d264f627a9e Mon Sep 17 00:00:00 2001 From: willemc Date: Fri, 13 Nov 2009 01:40:13 +0100 Subject: [PATCH] [svn r388] made very good progress on JSF templated frontend --- .project | 6 + pom.xml | 3 +- .../annotations/VascAnnotationParser.java | 1 - .../jpa/AbstractPersistenceVascBackend.java | 30 +- .../backends/jpa/BeanVascEntryFieldValue.java | 67 ++ .../jpa/BeanVascEntryRecordCreator.java | 29 + .../backends/jpa/EntityManagerProvider.java | 2 + .../jpa/XpqlHibernateVascBackend.java | 66 +- .../jpa/XpqlPersistanceVascBackend.java | 100 +- .../java/com/idcanet/vasc/core/VascEntry.java | 3 +- .../com/idcanet/vasc/core/VascEntryField.java | 3 +- .../idcanet/vasc/core/VascEntryFieldType.java | 3 +- .../com/idcanet/vasc/core/VascLinkEntry.java | 3 +- .../idcanet/vasc/core/actions/VascAction.java | 4 +- .../core/entry/VascEntryEventListener.java | 4 +- .../entry/VascEntryFieldEventChannel.java | 4 +- .../vasc/core/entry/VascEntryFieldValue.java | 4 +- .../core/entry/VascEntryRecordCreator.java | 4 +- .../vasc/core/ui/VascSelectItemModel.java | 3 +- .../web/jsf/JSFVascEntryEventListener.java | 62 ++ .../web/jsf/JSFVascEntrySupportBean.java | 851 ++++++++++++++++++ .../web/jsf/JSFVascFrontendRenderer.java | 137 +++ .../frontends/web/jsf/JSFVascUIComponent.java | 378 ++++++++ .../web/jsf/JSFVascUIComponentRenderer.java | 452 ++++++++++ .../web/jsf/JSFVascUIComponentTag.java | 247 +++++ .../web/jsf/JSFVascValidatePhaseListener.java | 78 ++ ...Component.java => OldVascUIComponent.java} | 200 ++-- .../frontends/web/jsf/VascActionBean.java | 54 -- .../web/jsf/VascRequestFacesFilter.java | 5 +- .../frontends/web/jsf/VascUIComponentTag.java | 150 --- .../web/jsf/ui/AbstractJSFBaseComponent.java | 3 +- .../vasc/frontends/web/jsf/ui/JSFBoolean.java | 5 +- .../vasc/frontends/web/jsf/ui/JSFList.java | 16 +- .../vasc/frontends/web/jsf/ui/JSFText.java | 5 +- .../frontends/web/jsf/ui/JSFTextArea.java | 5 +- .../impl/DefaultVascBackedEntryFinalizer.java | 7 + .../vasc/impl/DefaultVascEntryField.java | 3 +- .../vasc/impl/DefaultVascFrontendHelper.java | 32 +- .../vasc/impl/DefaultVascSelectItemModel.java | 21 + .../vasc/impl/VascBackendProxyPaged.java | 35 +- .../vasc/impl/VascBackendProxySort.java | 13 +- .../impl/actions/CSVExportGlobalAction.java | 22 +- .../impl/actions/XMLExportGlobalAction.java | 27 +- .../BeanPropertyVascEntryFieldValue.java | 10 +- .../x4o/SelectItemModelBindingHandler.java | 4 +- .../x4o/VascEntryFieldBindingHandler.java | 4 +- ... VascEntryFieldSetAttributeConverter.java} | 10 +- ...VascEntryFieldTypeAttributeConverter.java} | 10 +- .../vasc/validators/VascValidator.java | 3 +- src/main/resources/META-INF/faces-config.xml | 28 +- .../{ => fieldtype}/fieldtype-lang.eld | 4 +- .../{ => fieldtype}/fieldtype-namespaces.xml | 2 +- src/main/resources/META-INF/vasc.taglib.xml | 12 + src/main/resources/META-INF/vasc.tld | 81 +- .../META-INF/{ => vasc}/vasc-lang.eld | 10 +- .../META-INF/{ => vasc}/vasc-namespaces.xml | 2 +- .../com/idcanet/vasc/VascI18nTextValue.java | 9 +- 57 files changed, 2783 insertions(+), 553 deletions(-) create mode 100644 src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryFieldValue.java create mode 100644 src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryRecordCreator.java create mode 100644 src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntryEventListener.java create mode 100644 src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java create mode 100644 src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascFrontendRenderer.java create mode 100644 src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java create mode 100644 src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java create mode 100644 src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentTag.java create mode 100644 src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascValidatePhaseListener.java rename src/main/java/com/idcanet/vasc/frontends/web/jsf/{VascUIComponent.java => OldVascUIComponent.java} (91%) delete mode 100644 src/main/java/com/idcanet/vasc/frontends/web/jsf/VascActionBean.java delete mode 100644 src/main/java/com/idcanet/vasc/frontends/web/jsf/VascUIComponentTag.java rename src/main/java/com/idcanet/vasc/impl/x4o/{VascEntryFieldSetParameterConverter.java => VascEntryFieldSetAttributeConverter.java} (82%) rename src/main/java/com/idcanet/vasc/impl/x4o/{VascEntryFieldTypeParameterConverter.java => VascEntryFieldTypeAttributeConverter.java} (83%) rename src/main/resources/META-INF/{ => fieldtype}/fieldtype-lang.eld (93%) rename src/main/resources/META-INF/{ => fieldtype}/fieldtype-namespaces.xml (83%) create mode 100644 src/main/resources/META-INF/vasc.taglib.xml rename src/main/resources/META-INF/{ => vasc}/vasc-lang.eld (93%) rename src/main/resources/META-INF/{ => vasc}/vasc-namespaces.xml (64%) diff --git a/.project b/.project index 4848137..6dbf548 100644 --- a/.project +++ b/.project @@ -5,6 +5,11 @@ + + org.eclipse.wst.common.project.facet.core.builder + + + com.genuitec.eclipse.j2eedt.core.WebClasspathBuilder @@ -58,5 +63,6 @@ org.eclipse.jem.workbench.JavaEMFNature org.eclipse.jdt.core.javanature org.eclipse.jem.beaninfo.BeanInfoNature + org.eclipse.wst.common.project.facet.core.nature diff --git a/pom.xml b/pom.xml index ce21f8d..352769a 100644 --- a/pom.xml +++ b/pom.xml @@ -116,7 +116,7 @@ - + diff --git a/src/main/java/com/idcanet/vasc/annotations/VascAnnotationParser.java b/src/main/java/com/idcanet/vasc/annotations/VascAnnotationParser.java index 3bf6e6f..f4f36ce 100644 --- a/src/main/java/com/idcanet/vasc/annotations/VascAnnotationParser.java +++ b/src/main/java/com/idcanet/vasc/annotations/VascAnnotationParser.java @@ -323,7 +323,6 @@ public class VascAnnotationParser { if (method.getName().equalsIgnoreCase("get"+property)==false) { //a bit durty continue; } - //logger.finer("Found property: "+property); VascModelReference mt = method.getAnnotation(VascModelReference.class); if (mt!=null & (annotationType.equals(VascI18n.class) | annotationType.equals(VascField.class) | annotationType.equals(VascStyle.class) )) { Class typeClass = mt.type(); diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/AbstractPersistenceVascBackend.java b/src/main/java/com/idcanet/vasc/backends/jpa/AbstractPersistenceVascBackend.java index d60649f..ac57e7c 100644 --- a/src/main/java/com/idcanet/vasc/backends/jpa/AbstractPersistenceVascBackend.java +++ b/src/main/java/com/idcanet/vasc/backends/jpa/AbstractPersistenceVascBackend.java @@ -26,6 +26,8 @@ package com.idcanet.vasc.backends.jpa; +import java.lang.reflect.Method; + import javax.persistence.EntityManager; import com.idcanet.vasc.core.AbstractVascBackend; @@ -38,14 +40,20 @@ import com.idcanet.vasc.core.VascException; */ abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend { + protected boolean emTransaction = true; + abstract EntityManager getEntityManager(); public void persist(Object object) throws VascException { EntityManager s = getEntityManager(); try { - s.getTransaction().begin(); + if (emTransaction) { + s.getTransaction().begin(); + } s.persist(object); - s.getTransaction().commit(); + if (emTransaction) { + s.getTransaction().commit(); + } } finally { if (s!=null) { //s.close(); @@ -53,12 +61,16 @@ abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend } } - public Object merge(Object object) throws VascException { + public Object merge(Object object) throws VascException { EntityManager s = getEntityManager(); try { - s.getTransaction().begin(); + if (emTransaction) { + s.getTransaction().begin(); + } Object result = s.merge(object); - s.getTransaction().commit(); + if (emTransaction) { + s.getTransaction().commit(); + } return result; } finally { if (s!=null) { @@ -70,10 +82,14 @@ abstract public class AbstractPersistenceVascBackend extends AbstractVascBackend public void delete(Object object) throws VascException { EntityManager s = getEntityManager(); try { - s.getTransaction().begin(); + if (emTransaction) { + s.getTransaction().begin(); + } Object newObject = s.merge(object); s.remove(newObject); - s.getTransaction().commit(); + if (emTransaction) { + s.getTransaction().commit(); + } } finally { if (s!=null) { //s.close(); diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryFieldValue.java b/src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryFieldValue.java new file mode 100644 index 0000000..d63313c --- /dev/null +++ b/src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryFieldValue.java @@ -0,0 +1,67 @@ +/** + * + */ +package com.idcanet.vasc.backends.jpa; + +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.VascException; +import com.idcanet.vasc.core.entry.VascEntryFieldValue; +import com.idcanet.x4o.impl.DefaultElementObjectPropertyValue; + +/** + * @author willemc + * + */ +public class BeanVascEntryFieldValue implements VascEntryFieldValue { + + private static final long serialVersionUID = 1L; + private DefaultElementObjectPropertyValue bean = new DefaultElementObjectPropertyValue(); + + /** + * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object) + */ + public Object getValue(VascEntryField field, Object record) throws VascException { + try { + Object o = bean.getProperty(record,field.getBackendName()); + return o; + } catch (Exception e) { + throw new VascException(e); + } + } + + /** + * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getDisplayValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object) + */ + public String getDisplayValue(VascEntryField field, Object record) throws VascException { + Object value = getValue(field,record); + if (value==null) { + return ""; + } + if (field.getDisplayName()==null) { + if (value instanceof String) { + return (String)value; + } + return ""+value; + } + try { + Object result = bean.getProperty(value, field.getDisplayName()); + if (result instanceof String) { + return (String)result; + } + return ""+result; + } catch (Exception e) { + throw new VascException(e); + } + } + + /** + * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#setValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object, java.lang.Object) + */ + public void setValue(VascEntryField field, Object record,Object value) throws VascException { + try { + bean.setProperty(record, field.getBackendName(), value); + } catch (Exception e) { + throw new VascException(e); + } + } +} diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryRecordCreator.java b/src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryRecordCreator.java new file mode 100644 index 0000000..f77e039 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/backends/jpa/BeanVascEntryRecordCreator.java @@ -0,0 +1,29 @@ +/** + * + */ +package com.idcanet.vasc.backends.jpa; + +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.entry.VascEntryRecordCreator; + +/** + * @author willemc + * + */ +public class BeanVascEntryRecordCreator implements VascEntryRecordCreator { + + private static final long serialVersionUID = 1L; + private Class resultClass = null; + + public BeanVascEntryRecordCreator(Class resultClass) { + this.resultClass=resultClass; + } + + public Class getObjectClass() { + return resultClass; + } + + public Object newRecord(VascEntry entry) throws Exception { + return resultClass.newInstance(); + } +} diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/EntityManagerProvider.java b/src/main/java/com/idcanet/vasc/backends/jpa/EntityManagerProvider.java index ccb5933..16b08b0 100644 --- a/src/main/java/com/idcanet/vasc/backends/jpa/EntityManagerProvider.java +++ b/src/main/java/com/idcanet/vasc/backends/jpa/EntityManagerProvider.java @@ -37,4 +37,6 @@ import javax.persistence.EntityManager; public interface EntityManagerProvider { public EntityManager getEntityManager(); + + public boolean hasEntityManagerTransaction(); } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/XpqlHibernateVascBackend.java b/src/main/java/com/idcanet/vasc/backends/jpa/XpqlHibernateVascBackend.java index b3e48d7..ca6739f 100644 --- a/src/main/java/com/idcanet/vasc/backends/jpa/XpqlHibernateVascBackend.java +++ b/src/main/java/com/idcanet/vasc/backends/jpa/XpqlHibernateVascBackend.java @@ -38,8 +38,6 @@ import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.entry.VascEntryFieldValue; import com.idcanet.vasc.core.entry.VascEntryRecordCreator; -import com.idcanet.x4o.element.ElementParameterHelper; -import com.idcanet.x4o.impl.DefaultElementParameterHelper; import com.idcanet.xtes.xpql.query.QueryParameterValue; /** @@ -122,58 +120,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend { * @see com.idcanet.vasc.core.VascBackend#provideVascEntryFieldValue(com.idcanet.vasc.core.VascEntryField) */ public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { - VascEntryFieldValue result = new VascEntryFieldValue() { - - private ElementParameterHelper bean = new DefaultElementParameterHelper(); - - /** - * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object) - */ - public Object getValue(VascEntryField field, Object record) throws VascException { - try { - Object o = bean.getParameter(record,field.getBackendName()); - return o; - } catch (Exception e) { - throw new VascException(e); - } - } - - /** - * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getDisplayValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object) - */ - public String getDisplayValue(VascEntryField field, Object record) throws VascException { - Object value = getValue(field,record); - if (value==null) { - return ""; - } - if (field.getDisplayName()==null) { - if (value instanceof String) { - return (String)value; - } - return ""+value; - } - try { - Object result = bean.getParameter(value, field.getDisplayName()); - if (result instanceof String) { - return (String)result; - } - return ""+result; - } catch (Exception e) { - throw new VascException(e); - } - } - - /** - * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#setValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object, java.lang.Object) - */ - public void setValue(VascEntryField field, Object record,Object value) throws VascException { - try { - bean.setParameter(record, field.getBackendName(), value); - } catch (Exception e) { - throw new VascException(e); - } - } - }; + BeanVascEntryFieldValue result = new BeanVascEntryFieldValue(); return result; } @@ -181,16 +128,7 @@ public class XpqlHibernateVascBackend extends AbstractHibernateVascBackend { * @see com.idcanet.vasc.core.VascBackend#provideVascEntryRecordCreator(com.idcanet.vasc.core.VascEntry) */ public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { - return new VascEntryRecordCreator() { - - public Class getObjectClass() { - return resultClass; - } - - public Object newRecord(VascEntry entry) throws Exception { - return resultClass.newInstance(); - } - }; + return new BeanVascEntryRecordCreator(resultClass); } /** diff --git a/src/main/java/com/idcanet/vasc/backends/jpa/XpqlPersistanceVascBackend.java b/src/main/java/com/idcanet/vasc/backends/jpa/XpqlPersistanceVascBackend.java index 85fd43e..6937406 100644 --- a/src/main/java/com/idcanet/vasc/backends/jpa/XpqlPersistanceVascBackend.java +++ b/src/main/java/com/idcanet/vasc/backends/jpa/XpqlPersistanceVascBackend.java @@ -37,8 +37,6 @@ import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.entry.VascEntryFieldValue; import com.idcanet.vasc.core.entry.VascEntryRecordCreator; -import com.idcanet.x4o.element.ElementParameterHelper; -import com.idcanet.x4o.impl.DefaultElementParameterHelper; import com.idcanet.xtes.xpql.query.QueryParameterValue; /** @@ -73,6 +71,7 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend */ @Override EntityManager getEntityManager() { + emTransaction=entityManagerProvider.hasEntityManagerTransaction(); return entityManagerProvider.getEntityManager(); } @@ -104,9 +103,13 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend q.setFirstResult(state.getPageIndex()); q.setMaxResults(state.getPageSize()); } - em.getTransaction().begin(); + if (emTransaction) { + em.getTransaction().begin(); + } List data = q.getResultList(); - em.getTransaction().commit(); + if (emTransaction) { + em.getTransaction().commit(); + } return data; } finally { if (em!=null) { @@ -119,58 +122,7 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend * @see com.idcanet.vasc.core.VascBackend#provideVascEntryFieldValue(com.idcanet.vasc.core.VascEntryField) */ public VascEntryFieldValue provideVascEntryFieldValue(VascEntryField field) { - VascEntryFieldValue result = new VascEntryFieldValue() { - - private ElementParameterHelper bean = new DefaultElementParameterHelper(); - - /** - * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object) - */ - public Object getValue(VascEntryField field, Object record) throws VascException { - try { - Object o = bean.getParameter(record,field.getBackendName()); - return o; - } catch (Exception e) { - throw new VascException(e); - } - } - - /** - * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#getDisplayValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object) - */ - public String getDisplayValue(VascEntryField field, Object record) throws VascException { - Object value = getValue(field,record); - if (value==null) { - return ""; - } - if (field.getDisplayName()==null) { - if (value instanceof String) { - return (String)value; - } - return ""+value; - } - try { - Object result = bean.getParameter(value, field.getDisplayName()); - if (result instanceof String) { - return (String)result; - } - return ""+result; - } catch (Exception e) { - throw new VascException(e); - } - } - - /** - * @see com.idcanet.vasc.core.entry.VascEntryFieldValue#setValue(com.idcanet.vasc.core.VascEntryField, java.lang.Object, java.lang.Object) - */ - public void setValue(VascEntryField field, Object record,Object value) throws VascException { - try { - bean.setParameter(record, field.getBackendName(), value); - } catch (Exception e) { - throw new VascException(e); - } - } - }; + VascEntryFieldValue result = new BeanVascEntryFieldValue(); return result; } @@ -178,16 +130,8 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend * @see com.idcanet.vasc.core.VascBackend#provideVascEntryRecordCreator(com.idcanet.vasc.core.VascEntry) */ public VascEntryRecordCreator provideVascEntryRecordCreator(VascEntry vascEntry) { - return new VascEntryRecordCreator() { - - public Class getObjectClass() { - return resultClass; - } - - public Object newRecord(VascEntry entry) throws Exception { - return resultClass.newInstance(); - } - }; + VascEntryRecordCreator result = new BeanVascEntryRecordCreator(resultClass); + return result; } /** @@ -270,9 +214,13 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend q.setParameter(i,value.getValue()); i++; } - em.getTransaction().begin(); + if (emTransaction) { + em.getTransaction().begin(); + } Long resultTotal = (Long)q.getSingleResult(); - em.getTransaction().commit(); + if (emTransaction) { + em.getTransaction().commit(); + } return resultTotal; } finally { if (em!=null) { @@ -291,7 +239,9 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend if (queryMoveDown!=null) { EntityManager em = getEntityManager(); try { - em.getTransaction().begin(); + if (emTransaction) { + em.getTransaction().begin(); + } // Copy parameters for (String key:state.getDataParameterKeys()) { @@ -331,7 +281,9 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend } result+=q.executeUpdate(); - em.getTransaction().commit(); + if (emTransaction) { + em.getTransaction().commit(); + } } finally { if (em!=null) { //em.close(); @@ -350,7 +302,9 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend if (queryMoveUp!=null) { EntityManager em = getEntityManager(); try { - em.getTransaction().begin(); + if (emTransaction) { + em.getTransaction().begin(); + } // Copy parameters for (String key:state.getDataParameterKeys()) { @@ -390,7 +344,9 @@ public class XpqlPersistanceVascBackend extends AbstractPersistenceVascBackend } result+=q.executeUpdate(); - em.getTransaction().commit(); + if (emTransaction) { + em.getTransaction().commit(); + } } finally { if (em!=null) { //em.close(); diff --git a/src/main/java/com/idcanet/vasc/core/VascEntry.java b/src/main/java/com/idcanet/vasc/core/VascEntry.java index 8f5d82a..04f7582 100644 --- a/src/main/java/com/idcanet/vasc/core/VascEntry.java +++ b/src/main/java/com/idcanet/vasc/core/VascEntry.java @@ -26,6 +26,7 @@ package com.idcanet.vasc.core; +import java.io.Serializable; import java.util.List; import com.idcanet.vasc.core.actions.ColumnVascAction; @@ -41,7 +42,7 @@ import com.idcanet.vasc.core.entry.VascEntryFieldEventChannel; * @author Willem Cazander * @version 1.0 Mar 21, 2007 */ -public interface VascEntry extends Cloneable { +public interface VascEntry extends Cloneable,Serializable { /** * @return the id diff --git a/src/main/java/com/idcanet/vasc/core/VascEntryField.java b/src/main/java/com/idcanet/vasc/core/VascEntryField.java index 17840c7..b8e9733 100644 --- a/src/main/java/com/idcanet/vasc/core/VascEntryField.java +++ b/src/main/java/com/idcanet/vasc/core/VascEntryField.java @@ -26,6 +26,7 @@ package com.idcanet.vasc.core; +import java.io.Serializable; import java.util.List; import com.idcanet.vasc.core.entry.VascEntryFieldValue; @@ -39,7 +40,7 @@ import com.idcanet.vasc.validators.VascValidator; * @author Willem Cazander * @version 1.0 Mar 21, 2007 */ -public interface VascEntryField extends Cloneable { +public interface VascEntryField extends Cloneable,Serializable { /** * @return the VascEntry diff --git a/src/main/java/com/idcanet/vasc/core/VascEntryFieldType.java b/src/main/java/com/idcanet/vasc/core/VascEntryFieldType.java index 9ee5814..32698c4 100644 --- a/src/main/java/com/idcanet/vasc/core/VascEntryFieldType.java +++ b/src/main/java/com/idcanet/vasc/core/VascEntryFieldType.java @@ -26,6 +26,7 @@ package com.idcanet.vasc.core; +import java.io.Serializable; import java.util.List; import com.idcanet.vasc.core.ui.VascUIComponent; @@ -38,7 +39,7 @@ import com.idcanet.vasc.validators.VascValidator; * @author Willem Cazander * @version 1.0 Mar 21, 2007 */ -public interface VascEntryFieldType { +public interface VascEntryFieldType extends Serializable { public String getId(); public void setId(String id); diff --git a/src/main/java/com/idcanet/vasc/core/VascLinkEntry.java b/src/main/java/com/idcanet/vasc/core/VascLinkEntry.java index 92ce7c6..556c314 100644 --- a/src/main/java/com/idcanet/vasc/core/VascLinkEntry.java +++ b/src/main/java/com/idcanet/vasc/core/VascLinkEntry.java @@ -26,6 +26,7 @@ package com.idcanet.vasc.core; +import java.io.Serializable; import java.util.List; @@ -34,7 +35,7 @@ import java.util.List; * @author Willem Cazander * @version 1.0 Sep 7, 2008 */ -public interface VascLinkEntry extends Cloneable { +public interface VascLinkEntry extends Cloneable,Serializable { public String getId(); public void setId(String id); diff --git a/src/main/java/com/idcanet/vasc/core/actions/VascAction.java b/src/main/java/com/idcanet/vasc/core/actions/VascAction.java index 2385cc6..4fd08ec 100644 --- a/src/main/java/com/idcanet/vasc/core/actions/VascAction.java +++ b/src/main/java/com/idcanet/vasc/core/actions/VascAction.java @@ -26,12 +26,14 @@ package com.idcanet.vasc.core.actions; +import java.io.Serializable; + /** * * @author Willem Cazander * @version 1.0 Mar 21, 2007 */ -public interface VascAction extends Cloneable { +public interface VascAction extends Cloneable,Serializable { public String getId(); diff --git a/src/main/java/com/idcanet/vasc/core/entry/VascEntryEventListener.java b/src/main/java/com/idcanet/vasc/core/entry/VascEntryEventListener.java index 56584da..7a0c689 100644 --- a/src/main/java/com/idcanet/vasc/core/entry/VascEntryEventListener.java +++ b/src/main/java/com/idcanet/vasc/core/entry/VascEntryEventListener.java @@ -26,6 +26,8 @@ package com.idcanet.vasc.core.entry; +import java.io.Serializable; + import com.idcanet.vasc.core.VascEntry; @@ -34,7 +36,7 @@ import com.idcanet.vasc.core.VascEntry; * @author Willem Cazander * @version 1.0 Aug 02, 2007 */ -public interface VascEntryEventListener extends Cloneable { +public interface VascEntryEventListener extends Cloneable,Serializable { public enum VascEventType { EXCEPTION, diff --git a/src/main/java/com/idcanet/vasc/core/entry/VascEntryFieldEventChannel.java b/src/main/java/com/idcanet/vasc/core/entry/VascEntryFieldEventChannel.java index d1f8a20..840978d 100644 --- a/src/main/java/com/idcanet/vasc/core/entry/VascEntryFieldEventChannel.java +++ b/src/main/java/com/idcanet/vasc/core/entry/VascEntryFieldEventChannel.java @@ -26,13 +26,15 @@ package com.idcanet.vasc.core.entry; +import java.io.Serializable; + /** * * @author Willem Cazander * @version 1.0 Sep 04, 2008 */ -public interface VascEntryFieldEventChannel { +public interface VascEntryFieldEventChannel extends Serializable { public void setChannel(String channel); public String getChannel(); diff --git a/src/main/java/com/idcanet/vasc/core/entry/VascEntryFieldValue.java b/src/main/java/com/idcanet/vasc/core/entry/VascEntryFieldValue.java index 82dc6a5..c595180 100644 --- a/src/main/java/com/idcanet/vasc/core/entry/VascEntryFieldValue.java +++ b/src/main/java/com/idcanet/vasc/core/entry/VascEntryFieldValue.java @@ -26,6 +26,8 @@ package com.idcanet.vasc.core.entry; +import java.io.Serializable; + import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascException; @@ -34,7 +36,7 @@ import com.idcanet.vasc.core.VascException; * @author Willem Cazander * @version 1.0 Mar 21, 2007 */ -public interface VascEntryFieldValue { +public interface VascEntryFieldValue extends Serializable { public Object getValue(VascEntryField field,Object record) throws VascException; diff --git a/src/main/java/com/idcanet/vasc/core/entry/VascEntryRecordCreator.java b/src/main/java/com/idcanet/vasc/core/entry/VascEntryRecordCreator.java index 37565d1..8774718 100644 --- a/src/main/java/com/idcanet/vasc/core/entry/VascEntryRecordCreator.java +++ b/src/main/java/com/idcanet/vasc/core/entry/VascEntryRecordCreator.java @@ -26,6 +26,8 @@ package com.idcanet.vasc.core.entry; +import java.io.Serializable; + import com.idcanet.vasc.core.VascEntry; @@ -34,7 +36,7 @@ import com.idcanet.vasc.core.VascEntry; * @author Willem Cazander * @version 1.0 Mar 21, 2007 */ -public interface VascEntryRecordCreator { +public interface VascEntryRecordCreator extends Serializable { public Object newRecord(VascEntry entry) throws Exception; diff --git a/src/main/java/com/idcanet/vasc/core/ui/VascSelectItemModel.java b/src/main/java/com/idcanet/vasc/core/ui/VascSelectItemModel.java index f48f0e2..2dc52bc 100644 --- a/src/main/java/com/idcanet/vasc/core/ui/VascSelectItemModel.java +++ b/src/main/java/com/idcanet/vasc/core/ui/VascSelectItemModel.java @@ -26,6 +26,7 @@ package com.idcanet.vasc.core.ui; +import java.io.Serializable; import java.util.List; import com.idcanet.vasc.core.VascEntry; @@ -36,7 +37,7 @@ import com.idcanet.vasc.core.VascException; * @author Willem Cazander * @version 1.0 Aug 12, 2007 */ -public interface VascSelectItemModel { +public interface VascSelectItemModel extends Serializable { /** * Creates an SelectItem list. diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntryEventListener.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntryEventListener.java new file mode 100644 index 0000000..ab1a0c7 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntryEventListener.java @@ -0,0 +1,62 @@ +/** + * + */ +package com.idcanet.vasc.frontends.web.jsf; + +import java.util.ArrayList; +import java.util.List; + +import javax.el.ValueExpression; +import javax.faces.context.FacesContext; + +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.entry.VascEntryEventListener; +import com.idcanet.vasc.core.entry.VascEntryFieldValue; + +/** + * @author willemc + * + */ +public class JSFVascEntryEventListener implements VascEntryEventListener { + + private static final long serialVersionUID = 1765054259934158076L; + private String entrySupportVar = null; + + public JSFVascEntryEventListener(String entrySupportVar) { + this.entrySupportVar=entrySupportVar; + } + + public void vascEvent(VascEntry entry, VascEventType type,Object dataNotUsed) { + try { + for (VascEntryField field:entry.getVascEntryFields()) { + if (field.getVascEntryFieldValue()==null) { + // TODO: fix this for better remote support + VascEntryField fieldClone = field.clone(); + fieldClone.getVascValidators().clear(); + + VascEntryFieldValue v = entry.getVascFrontendData().getVascBackend().provideVascEntryFieldValue(fieldClone); + field.setVascEntryFieldValue(v); + } + } + } catch (Exception e) { + throw new RuntimeException(e); + } + List data = entry.getVascFrontendData().getEntryDataList(); + List result = new ArrayList(data.size()); + for (Object o:data) { + VascDataBackendBean b = new VascDataBackendBean(entry,o); + result.add(b); + } + + ValueExpression ve2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".tableDataModel.wrappedData}", Object.class); + ve2.setValue(FacesContext.getCurrentInstance().getELContext(), result); + ValueExpression ve3 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".tablePagesDataModel.wrappedData}", Object.class); + ve3.setValue(FacesContext.getCurrentInstance().getELContext(), entry.getVascFrontendData().getVascFrontendHelper().getVascBackendPageNumbers(entry)); + } + @Override + public VascEntryEventListener clone() throws CloneNotSupportedException { + return this; + } + +} 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 new file mode 100644 index 0000000..7c73492 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascEntrySupportBean.java @@ -0,0 +1,851 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.frontends.web.jsf; + + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.logging.Logger; + +import javax.faces.component.UIComponent; +import javax.faces.component.html.HtmlCommandButton; +import javax.faces.component.html.HtmlCommandLink; +import javax.faces.context.FacesContext; +import javax.faces.event.ActionEvent; +import javax.faces.event.ValueChangeEvent; +import javax.faces.model.DataModel; +import javax.faces.model.ListDataModel; +import javax.faces.model.SelectItem; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; + +import com.idcanet.vasc.core.VascBackendPageNumber; +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.VascLinkEntry; +import com.idcanet.vasc.core.actions.GlobalVascAction; +import com.idcanet.vasc.core.actions.RowVascAction; +import com.idcanet.vasc.core.entry.VascEntryExporter; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Sep 10, 2009 + */ +public class JSFVascEntrySupportBean implements Serializable { + + private static final long serialVersionUID = 1L; + private Logger logger = null; + private VascEntry entry = null; + private JSFVascSupportI18nMapController i18nMap = null; + private VascDataBackendBean selected = null; + private String searchString = null; + private DataModel tableDataModel = null; + private DataModel tablePagesDataModel = null; + private Boolean backendSortable = null; + private Boolean backendMoveable = null; + private Boolean backendSearchable = null; + private Boolean backendPageable = null; + private Boolean sortOrder = null; + private String sortField = null; + private VascEntryExporter selectedExporter = null; + private String selectedExporterAction = "null"; + private String selectedDirectPage = "null"; + private Map editSelectItemModels = null; + + public JSFVascEntrySupportBean(VascEntry entry) { + if (entry==null) { + throw new NullPointerException("Can't support null entry."); + } + this.logger = Logger.getLogger(JSFVascEntrySupportBean.class.getName()); + this.entry=entry; + + // init + tableDataModel = new ListDataModel(); + tablePagesDataModel = new ListDataModel(); + editSelectItemModels = new HashMap(6); + + // cache some values + backendPageable = entry.getVascFrontendData().getVascBackend().isPageable(); + backendMoveable = entry.getVascFrontendData().getVascBackend().isRecordMoveable(); + backendSearchable = entry.getVascFrontendData().getVascBackend().isSearchable(); + backendSortable = entry.getVascFrontendData().getVascBackend().isSortable(); + + + i18nMap = new JSFVascSupportI18nMapController(entry); + + logger.finer("Support Bean created for vascEntry: "+entry.getId()); + } + + public VascEntry getVascEntry() { + return entry; + } + + public Map getI18nMap() { + return i18nMap; + } + + public VascDataBackendBean getSelectedTableRecord() { + Object selected = tableDataModel.getRowData(); + if (selected==null) { + return null; + } + VascDataBackendBean r = (VascDataBackendBean) selected; + return r; + } + + public int getTotalColumnCount() { + int t = 0; + t += getTotalFieldColumnCount(); + t += getTotalActionColumnCount(); + t += getTotalLinkColumnCount(); + return t; + } + + public int getTotalFieldColumnCount() { + int t = 0; + for (VascEntryField c:entry.getVascEntryFields()) { + if (entry.getVascFrontendData().getVascFrontendHelper().renderList(c)==false) { + continue; + } + t++; + } + return t; + } + + public int getTotalActionColumnCount() { + int t = 0; + if (entry.getVascFrontendData().getVascBackend().isRecordMoveable()) { + t++; + t++; + } + for (RowVascAction action:entry.getRowActions()) { + t++; + } + return t; + } + + public int getTotalLinkColumnCount() { + int t = 0; + for (VascLinkEntry vascLink:entry.getVascLinkEntries()) { + t++; + } + return t; + } + + public long getPageTotalRecordCount() { + long result = entry.getVascFrontendData().getTotalBackendRecords(); + return result; + } + + public long getPageStartCount() { + int index = entry.getVascFrontendData().getVascBackendState().getPageIndex(); + int pageSize = entry.getVascFrontendData().getVascBackendState().getPageSize(); + long result = index*pageSize; + return result; + } + public long getPageStopCount() { + int index = entry.getVascFrontendData().getVascBackendState().getPageIndex(); + int pageSize = entry.getVascFrontendData().getVascBackendState().getPageSize(); + long result = (index*pageSize)+pageSize; + + // limit for small result sets. + if (result>entry.getVascFrontendData().getTotalBackendRecords()) { + result = entry.getVascFrontendData().getTotalBackendRecords(); + } + return result; + } + + public List getGlobalExportItems() { + List result = new ArrayList(5); + SelectItem s = new SelectItem(); + s.setLabel("..."); + s.setDescription("Selecteer Export"); + s.setValue("null"); + result.add(s); + + for (GlobalVascAction a:entry.getGlobalActions()) { + if (a.getId().contains("xport")) { + s = new SelectItem(); + s.setLabel(i18nMap.get(a.getName())); + s.setDescription(i18nMap.get(a.getDescription())); + s.setValue(a.getId()); + result.add(s); + } + } + + return result; + } + + public List getDirectPageItems() { + List result = new ArrayList(5); + SelectItem s = new SelectItem(); + s.setLabel("..."); + s.setDescription("Selecteer Page"); + s.setValue("null"); + result.add(s); + + int pageSize = getVascEntry().getVascFrontendData().getVascBackendState().getPageSize(); + for (int i=0;i13) { + return true; + } + return false; + } + + public boolean getHasExtendedPageModeCenter() { + if (getHasExtendedPageMode()==false) { + return false; + } + int page = getVascEntry().getVascFrontendData().getVascBackendState().getPageIndex(); + if (page<5) { + return false; + } + int pages = getTablePagesDataModel().getRowCount(); + if (page>pages-5) { + return false; + } + return true; + } + + public List getTablePagesExtendedBegin() { + List result = new ArrayList(6); + getTablePagesDataModel().setRowIndex(0); + result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); + getTablePagesDataModel().setRowIndex(1); + result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); + getTablePagesDataModel().setRowIndex(2); + result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); + + int page = getVascEntry().getVascFrontendData().getVascBackendState().getPageIndex(); + if (page==2 | page==3 | page==4) { + getTablePagesDataModel().setRowIndex(3); + result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); + } + if (page==3 | page==4) { + getTablePagesDataModel().setRowIndex(4); + result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); + } + if (page==4) { + getTablePagesDataModel().setRowIndex(5); + result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); + } + return result; + } + + public List getTablePagesExtendedEnd() { + List result = new ArrayList(6); + int pages = getTablePagesDataModel().getRowCount(); + int page = getVascEntry().getVascFrontendData().getVascBackendState().getPageIndex(); + int off = pages-page; + + if (off==4) { + getTablePagesDataModel().setRowIndex(pages-6); + result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); + } + if (off==3 | off==4) { + getTablePagesDataModel().setRowIndex(pages-5); + result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); + } + if (off==2 | off==3 | off==4) { + getTablePagesDataModel().setRowIndex(pages-4); + result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); + } + + getTablePagesDataModel().setRowIndex(pages-3); + result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); + getTablePagesDataModel().setRowIndex(pages-2); + result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); + getTablePagesDataModel().setRowIndex(pages-1); + result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); + + + + return result; + } + + public List getTablePagesExtendedCenter() { + List result = new ArrayList(3); + int page = getVascEntry().getVascFrontendData().getVascBackendState().getPageIndex(); + getTablePagesDataModel().setRowIndex(page-1); + result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); + getTablePagesDataModel().setRowIndex(page); + result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); + getTablePagesDataModel().setRowIndex(page+1); + result.add((VascBackendPageNumber)getTablePagesDataModel().getRowData()); + return result; + } + + private String getComponentType(UIComponent comp) { + if (comp instanceof HtmlCommandLink) { + return ((HtmlCommandLink)comp).getType(); + } + if (comp instanceof HtmlCommandButton) { + return ((HtmlCommandButton)comp).getType(); + } + throw new IllegalArgumentException("Component is of link of button type: "+comp); + } + + // All Actions + + public void searchAction(ActionEvent event) { + logger.fine("searchAction"); + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + entry.getVascFrontendData().getVascFrontendHelper().searchAction(entry, searchString); + try { + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + } + + public void sortAction(ActionEvent event) { + logger.fine("sortAction"); + String fieldIdString = ((HtmlCommandLink)event.getComponent()).getType(); + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + VascEntryField field = entry.getVascEntryFieldById(fieldIdString); + + entry.getVascFrontendData().getVascFrontendHelper().sortAction(entry, field); + + sortOrder = entry.getVascFrontendData().getVascBackendState().isSortAscending(); + sortField = field.getId(); + + try { + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + } + + public void pageAction(ActionEvent event) { + logger.fine("pageAction"); + Integer pageIndex = new Integer(getComponentType(event.getComponent())); + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + selectedDirectPage=pageIndex+""; + entry.getVascFrontendData().getVascFrontendHelper().pageAction(entry, pageIndex); + try { + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + } + + public void pageNextAction(ActionEvent event) { + logger.fine("pageNextAction"); + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + + int pageIndex = entry.getVascFrontendData().getVascBackendState().getPageIndex(); + pageIndex++; + selectedDirectPage=pageIndex+""; + entry.getVascFrontendData().getVascFrontendHelper().pageAction(entry, pageIndex); + try { + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + } + + public void pagePreviousAction(ActionEvent event) { + logger.fine("pagePreviousAction"); + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + + int pageIndex = entry.getVascFrontendData().getVascBackendState().getPageIndex(); + pageIndex--; + selectedDirectPage=pageIndex+""; + entry.getVascFrontendData().getVascFrontendHelper().pageAction(entry, pageIndex); + try { + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + } + + public boolean getHasPageNextAction() { + VascEntry entry = getVascEntry(); + int pageIndex = entry.getVascFrontendData().getVascBackendState().getPageIndex(); + pageIndex++; + // copyed from helper + Long total = entry.getVascFrontendData().getTotalBackendRecords(); + logger.finer("Checking has next action for next pageIndex"+pageIndex+" of total: "+total+" and pageSize: "+entry.getVascFrontendData().getVascBackendState().getPageSize()); + if (total!=null && pageIndex>(total/entry.getVascFrontendData().getVascBackendState().getPageSize())) { + return false; + } + return true; + } + + public boolean getHasPagePreviousAction() { + VascEntry entry = getVascEntry(); + int pageIndex = entry.getVascFrontendData().getVascBackendState().getPageIndex(); + if (pageIndex==0) { + return false; + } + return true; + } + + + public void rowAction(ActionEvent event) { + String actionIdString = getComponentType(event.getComponent()); + logger.fine("RowAction: "+actionIdString); + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + RowVascAction action = entry.getRowActionById(actionIdString); + //Object selected = null; + if (actionIdString.contains("add")==false) { + selected = comp.getSupportBean().getSelectedTableRecord(); + } else { + selected = null; + } + logger.fine("RowAction do on: "+action); + try { + if (selected==null) { + action.doRowAction(entry, null); + } else { + action.doRowAction(entry, selected.getRecord()); + } + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + logger.fine("RowAction DONE"); + } + + public void globalAction(ActionEvent event) { + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + String id = getComponentType(event.getComponent()); + logger.fine("globalAction id: "+id); + GlobalVascAction action = entry.getGlobalActionById(id); + try { + action.doGlobalAction(entry); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + } + + + public void addAction(ActionEvent event) { + logger.fine("addAction"); + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + RowVascAction action = entry.getRowActionById("addRowAction"); + try { + action.doRowAction(entry, null); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + } + + public void linkAction(ActionEvent event) { + logger.fine("linkAction"); + String linkId = getComponentType(event.getComponent()); + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); + VascDataBackendBean selected = comp.getSupportBean().getSelectedTableRecord(); + logger.finer("Set selected: "+selected); + VascEntry entry = comp.getVascEntry(); + VascLinkEntry l = entry.getVascLinkEntryById(linkId); + comp.initGoto(l); + try { + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + this.selected=selected; // renderView clears selected ! + } + + public void linkEditAction(ActionEvent event) { + logger.fine("linkEditAction"); + String linkId = getComponentType(event.getComponent()); + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); + VascDataBackendBean selected = this.selected; + logger.fine("Set selected: "+selected); + VascEntry entry = comp.getVascEntry(); + VascLinkEntry l = entry.getVascLinkEntryById(linkId); + comp.initGoto(l); + try { + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + this.selected=selected; // renderView clears selected ! + } + + public void cancelAction(ActionEvent event) { + logger.fine("cancelAction"); + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + entry.getVascFrontendData().setEntryDataObject(null); + try { + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + } + + public void saveAction(ActionEvent event) { + logger.fine("saveAction"); + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + logger.fine("Savng: "+selected.getRecord()); + + /* + try { + for (Method m:selected.getRecord().getClass().getMethods()) { + if (m.getName().startsWith("get")) { + Object value = m.invoke(selected.getRecord(), new Object[0]); + logger.info("property: "+m.getName()+" value: "+value); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + */ + + entry.getVascFrontendData().setEntryDataObject(selected.getRecord()); + entry.getVascFrontendData().getVascFrontendHelper().mergeObject(entry); + + try { + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + } + + public void deleteAction(ActionEvent event) { + logger.fine("deleteAction"); + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + entry.getVascFrontendData().getVascFrontendHelper().deleteObject(entry); + try { + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + } + + public void processDirectDownloadChange(ValueChangeEvent event){ + + // first do normal global selection of action aka: globalAction(event); copyed: + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + + String id = (String)event.getNewValue(); + + // TODO: FIX this change listener is called before save action in row EDIT... + if (id==null) { + logger.info("FIXME: unexcepted call to direct download"); + return; + } + + // Default selection for fancy gui + if ("null".equals(id)) { + return; + } + + logger.fine("exportDownloadAction id: "+id); + + GlobalVascAction action = entry.getGlobalActionById(id); + try { + action.doGlobalAction(entry); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + + // restore normal view for next request. + comp.setRenderFacetState("listView"); + VascEntryExporter ex = getSelectedExporter(); + + if (ex==null) { + logger.fine("No exporter selected for download."); + return; + } + selectedExporterAction = "null"; // reset selection to top one. + + try { + FacesContext fc = FacesContext.getCurrentInstance(); + HttpServletResponse response = (HttpServletResponse)fc.getExternalContext().getResponse(); + String filename = "export-list."+ex.getType(); + response.setHeader("Content-disposition", "attachment; filename=" + filename); + String contentType = ex.getMineType(); + response.setContentType(contentType); + ServletOutputStream out = response.getOutputStream(); + + ex.doExport(out, entry); + out.close(); + + fc.responseComplete(); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + } + + + public void processDirectPageChange(ValueChangeEvent event){ + + // first do normal global selection of action aka: globalAction(event); copyed: + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(event.getComponent()); + VascEntry entry = comp.getVascEntry(); + + String id = (String)event.getNewValue(); + + // 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"); + return; + } + + // Default selection for fancy gui + if ("null".equals(id)) { + return; + } + + logger.fine("directPageChangeAction id: "+id); + //selectedDirectPage = "null"; + + try { + entry.getVascFrontendData().getVascFrontendHelper().pageAction(entry, new Integer(id)); + entry.getVascFrontendData().getVascFrontend().renderView(); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + } + + // Pure get/setters + + /** + * @return the searchString + */ + public String getSearchString() { + return searchString; + } + + /** + * @param searchString the searchString to set + */ + public void setSearchString(String searchString) { + this.searchString = searchString; + } + + /** + * @return the selected + */ + public VascDataBackendBean getSelected() { + return selected; + } + + /** + * @param selected the selected to set + */ + public void setSelected(VascDataBackendBean selected) { + this.selected = selected; + } + + /** + * @return the backendSortable + */ + public Boolean getBackendSortable() { + return backendSortable; + } + + /** + * @return the backendPageable + */ + public Boolean getBackendPageable() { + return backendPageable; + } + + /** + * @return the backendMoveable + */ + public Boolean getBackendMoveable() { + return backendMoveable; + } + + /** + * @return the backendSearchable + */ + public Boolean getBackendSearchable() { + return backendSearchable; + } + + /** + * @return the tableDataModel + */ + public DataModel getTableDataModel() { + return tableDataModel; + } + + /** + * @return the tablePagesDataModel + */ + public DataModel getTablePagesDataModel() { + return tablePagesDataModel; + } + + /** + * @return the sortOrder + */ + public Boolean getSortOrder() { + return sortOrder; + } + + /** + * @return the sortField + */ + public String getSortField() { + return sortField; + } + + /** + * @return the selectedExporter + */ + public VascEntryExporter getSelectedExporter() { + return selectedExporter; + } + + /** + * @param selectedExporter the selectedExporter to set + */ + public void setSelectedExporter(VascEntryExporter selectedExporter) { + this.selectedExporter = selectedExporter; + } + + /** + * @return the selectedExporterAction + */ + public String getSelectedExporterAction() { + return selectedExporterAction; + } + + /** + * @param selectedExporterAction the selectedExporterAction to set + */ + public void setSelectedExporterAction(String selectedExporterAction) { + this.selectedExporterAction = selectedExporterAction; + } + + /** + * @return the selectedDirectPage + */ + public String getSelectedDirectPage() { + return selectedDirectPage; + } + + /** + * @param selectedDirectPage the selectedDirectPage to set + */ + public void setSelectedDirectPage(String selectedDirectPage) { + this.selectedDirectPage = selectedDirectPage; + } + + /** + * @return the editSelectItemModels + */ + public Map getEditSelectItemModels() { + return editSelectItemModels; + } + + +} +class JSFVascSupportI18nMapController implements Map { + private VascEntry entry = null; + public JSFVascSupportI18nMapController(VascEntry entry) { + this.entry=entry; + } + + public void clear() { + } + + public boolean containsKey(Object key) { + return true; + } + + public boolean containsValue(Object value) { + return true; + } + + public Set> entrySet() { + return null; + } + + public String get(Object key) { + String result = entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue((String)key); + return result; + } + + public boolean isEmpty() { + return false; + } + + public Set keySet() { + return null; + } + + public String put(String key, String value) { + return null; + } + + @SuppressWarnings("unchecked") + public void putAll(Map m) { + } + + public String remove(Object key) { + return null; + } + + public int size() { + return 0; + } + + public Collection values() { + return null; + } + +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascFrontendRenderer.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascFrontendRenderer.java new file mode 100644 index 0000000..d711fd0 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascFrontendRenderer.java @@ -0,0 +1,137 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.frontends.web.jsf; + +import java.io.Serializable; +import java.util.logging.Logger; + +import javax.faces.component.UIViewRoot; +import javax.faces.context.FacesContext; + +import com.idcanet.vasc.core.AbstractVascFrontend; +import com.idcanet.vasc.core.VascFrontendData; +import com.idcanet.vasc.core.entry.VascEntryExporter; +import com.idcanet.vasc.frontends.web.jsf.ui.JSFBoolean; +import com.idcanet.vasc.frontends.web.jsf.ui.JSFLabel; +import com.idcanet.vasc.frontends.web.jsf.ui.JSFList; +import com.idcanet.vasc.frontends.web.jsf.ui.JSFText; +import com.idcanet.vasc.frontends.web.jsf.ui.JSFTextArea; + +/** + * Given the jsf vasc renderer its own class + * + * + * @author Willem Cazander + * @version 1.0 Nov 12, 2009 + */ +public class JSFVascFrontendRenderer extends AbstractVascFrontend implements Serializable { + + private static final long serialVersionUID = 1L; + private Logger logger = null; + + public JSFVascFrontendRenderer() { + logger = Logger.getLogger(JSFVascFrontendRenderer.class.getName()); + } + + // Frontend Stuff + + protected void addUiComponents() { + VascFrontendData vfd = getVascEntry().getVascFrontendData(); + + // required UI components + vfd.putVascUIComponent(com.idcanet.vasc.core.ui.VascUIComponent.VASC_LABEL,JSFLabel.class.getName()); + vfd.putVascUIComponent(com.idcanet.vasc.core.ui.VascUIComponent.VASC_TEXT, JSFText.class.getName()); + vfd.putVascUIComponent(com.idcanet.vasc.core.ui.VascUIComponent.VASC_LIST, JSFList.class.getName()); + //vfd.putVascUIComponent(com.idcanet.vasc.core.ui.VascUIComponent.VASC_BUTTON, JSFButton.class.getName()); + + // optional UI components + vfd.putVascUIComponent(com.idcanet.vasc.core.ui.VascUIComponent.VASC_BOOLEAN , JSFBoolean.class.getName()); + //vfd.putVascUIComponent(com.idcanet.vasc.core.ui.VascUIComponent.VASC_DATE , JSFDate.class.getName()); + vfd.putVascUIComponent(com.idcanet.vasc.core.ui.VascUIComponent.VASC_TEXTAREA , JSFTextArea.class.getName()); + //vfd.putVascUIComponent(com.idcanet.vasc.core.ui.VascUIComponent.VASC_COLOR , JSFColorChooser.class.getName()); + + } + + /** + * @see com.idcanet.vasc.core.VascFrontend#renderDelete(java.lang.Object) + */ + public void renderDelete() throws Exception { + logger.finer("renderDelete"); + UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); + JSFVascUIComponent comp = JSFVascUIComponent.findVascChild(viewRoot,getVascEntry().getId()); + comp.setRenderFacetState("deleteView"); + } + + /** + * @see com.idcanet.vasc.core.VascFrontend#renderEdit(java.lang.Object) + */ + public void renderEdit() throws Exception { + logger.finer("renderEdit"); + UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); + JSFVascUIComponent comp = JSFVascUIComponent.findVascChild(viewRoot,getVascEntry().getId()); + comp.setRenderFacetState("editView"); + + entry.getVascFrontendData().getVascFrontendHelper().editReadOnlyUIComponents(entry); + //String entrySupportVar = (String)comp.getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY); + + VascDataBackendBean selBean = null; + if (entry.getVascFrontendData().isEditCreate()) { + selBean = new VascDataBackendBean(entry,entry.getVascFrontendData().getEntryDataObject()); + } else { + selBean = comp.getSupportBean().getSelectedTableRecord(); + } + selBean.setRealValue(true); + + comp.getSupportBean().setSelected(selBean); + } + + /** + * @see com.idcanet.vasc.core.VascFrontend#renderExport(com.idcanet.vasc.core.entry.VascEntryExporter) + */ + public void renderExport(VascEntryExporter exporter) throws Exception { + logger.finer("renderExport"); + UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); + JSFVascUIComponent comp = JSFVascUIComponent.findVascChild(viewRoot,getVascEntry().getId()); + comp.setRenderFacetState("exportView"); + comp.getSupportBean().setSelectedExporter(exporter); + } + + /** + * @see com.idcanet.vasc.core.VascFrontend#renderView() + */ + public void renderView() throws Exception { + logger.finer("renderView"); + UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); + JSFVascUIComponent comp = JSFVascUIComponent.findVascChild(viewRoot,getVascEntry().getId()); + comp.setRenderFacetState("listView"); + + if (comp.getSupportBean().getSelected()!=null) { + comp.getSupportBean().getSelected().setRealValue(false); + comp.getSupportBean().setSelected(null); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java new file mode 100644 index 0000000..048edaf --- /dev/null +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponent.java @@ -0,0 +1,378 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.frontends.web.jsf; + +import java.io.IOException; +import java.io.Serializable; +import java.util.Iterator; +import java.util.List; +import java.util.logging.Logger; + +import javax.el.ELContext; +import javax.el.MethodExpression; +import javax.el.ValueExpression; +import javax.faces.FacesException; +import javax.faces.application.Application; +import javax.faces.application.FacesMessage; +import javax.faces.component.UIColumn; +import javax.faces.component.UIComponent; +import javax.faces.component.UIComponentBase; +import javax.faces.component.UIInput; +import javax.faces.component.UIOutput; +import javax.faces.component.UIViewRoot; +import javax.faces.component.html.HtmlCommandLink; +import javax.faces.component.html.HtmlMessage; +import javax.faces.component.html.HtmlOutputText; +import javax.faces.context.FacesContext; +import javax.faces.event.ActionEvent; +import javax.faces.event.MethodExpressionActionListener; +import javax.faces.validator.Validator; +import javax.faces.validator.ValidatorException; + +import com.idcanet.vasc.core.AbstractVascFrontend; +import com.idcanet.vasc.core.VascBackend; +import com.idcanet.vasc.core.VascBackendFilter; +import com.idcanet.vasc.core.VascController; +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.VascException; +import com.idcanet.vasc.core.VascFrontendData; +import com.idcanet.vasc.core.VascLinkEntry; +import com.idcanet.vasc.core.actions.RowVascAction; +import com.idcanet.vasc.core.entry.VascEntryEventListener; +import com.idcanet.vasc.core.entry.VascEntryExporter; +import com.idcanet.vasc.core.entry.VascEntryEventListener.VascEventType; +import com.idcanet.vasc.core.ui.VascOptionValueModelListener; +import com.idcanet.vasc.core.ui.VascValueModel; +import com.idcanet.vasc.frontends.web.jsf.ui.JSFBoolean; +import com.idcanet.vasc.frontends.web.jsf.ui.JSFLabel; +import com.idcanet.vasc.frontends.web.jsf.ui.JSFList; +import com.idcanet.vasc.frontends.web.jsf.ui.JSFText; +import com.idcanet.vasc.frontends.web.jsf.ui.JSFTextArea; +import com.idcanet.vasc.impl.VascBackendProxyFilter; +import com.idcanet.vasc.impl.VascBackendProxyPaged; +import com.idcanet.vasc.impl.VascBackendProxySearch; +import com.idcanet.vasc.impl.VascBackendProxySort; + +/** + * Renders an JSF vasc entry views. + * + * This is a bit hacky because I'm not a JSF guro. + * + * @author Willem Cazander + * @version 1.0 Nov 16, 2008 + */ +public class JSFVascUIComponent extends UIComponentBase { + + public static final String FAMILY = "vasc.jsf.component.family"; + public static final String VASC_CONTROLLER_KEY = "vascController"; + public static final String VASC_FRONTEND_DATA_KEY = "vascFrontendData"; + public static final String ENTRY_NAME_KEY = "entryName"; + public static final String ENTRY_SUPPORT_VAR_KEY = "entrySupportVar"; + public static final String TABLE_RECORD_VAR_KEY = "tableRecordVar"; + public static final String INJECT_EDIT_FIELDS_ID = "injectEditFieldsId"; + public static final String INJECT_TABLE_OPTIONS_ID = "injectTableOptionsId"; + public static final String INJECT_TABLE_COLUMNS_ID = "injectTableColumnsId"; + + private JSFVascFrontendRenderer renderer = null; + private JSFVascEntrySupportBean supportBean = null; + private String renderFacetState = null; + private VascLinkEntry link = null; + private Logger logger = null; + private Boolean initClear = null; + + public JSFVascUIComponent() { + logger = Logger.getLogger(JSFVascUIComponent.class.getName()); + } + + public String getFamily() { + return FAMILY; + } + + @Override + public Object saveState(FacesContext facesContext) { + logger.fine("Save State"); + Object values[] = new Object[7]; + values[0] = super.saveState(facesContext); + values[1] = this.getAttributes().get(VASC_CONTROLLER_KEY); + values[2] = this.getAttributes().get(VASC_FRONTEND_DATA_KEY); + values[3] = this.getAttributes().get(ENTRY_NAME_KEY); + values[4] = renderer; + values[5] = supportBean; + values[6] = renderFacetState; + return values; + + } + + @Override + public void restoreState(FacesContext facesContext, Object state) { + logger.fine("Resotre State"); + Object values[] = (Object[])state; + super.restoreState(facesContext, values[0]); + this.getAttributes().put(VASC_CONTROLLER_KEY, values[1]); + this.getAttributes().put(VASC_FRONTEND_DATA_KEY, values[2]); + this.getAttributes().put(ENTRY_NAME_KEY, values[3]); + renderer = (JSFVascFrontendRenderer) values[4]; + supportBean = (JSFVascEntrySupportBean) values[5]; + renderFacetState = (String) values[6]; + + // TODO: check if we can move this some day... + String entrySupportVar = (String)getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY); + ValueExpression ve2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+"}", Object.class); + ve2.setValue(FacesContext.getCurrentInstance().getELContext(), getSupportBean()); + } + + static public JSFVascUIComponent findVascParent(UIComponent comp) { + if (comp==null) { + return null; + } + if (comp instanceof JSFVascUIComponent) { + return (JSFVascUIComponent)comp; + } + return findVascParent(comp.getParent()); + } + + static public JSFVascUIComponent findVascChild(UIComponent comp,String entryId) { + if (comp==null) { + return null; + } + if (comp instanceof JSFVascUIComponent) { + JSFVascUIComponent ui = (JSFVascUIComponent)comp; + if (entryId.equals(ui.getVascEntry().getId())) { + return ui; + } + return null; // this is a other entry on this view + } + for (UIComponent c:comp.getChildren()) { + Object res = findVascChild(c,entryId); + if (res!=null) { + return (JSFVascUIComponent)res; // found + } + } + return null; + } + + /** + * Finds component with the given id + */ + static public UIComponent findComponentById(UIComponent c, String id) { + if (id.equals(c.getId())) { + return c; + } + Iterator kids = c.getFacetsAndChildren(); + while (kids.hasNext()) { + UIComponent found = findComponentById(kids.next(), id); + if (found != null) { + return found; + } + } + return null; + } + + public VascEntry getVascEntry() { + return renderer.getVascEntry(); + } + + protected void initGoto(VascLinkEntry link) { + logger.fine("init goto "+link); + this.link=link; + } + + public Boolean getInitClear() { + return initClear; + } + + @Override + public void encodeBegin(FacesContext context) throws IOException { + logger.fine("Comp encodeBegin link: "+link); + boolean init = false; + if (renderer==null | link!=null) { + renderFacetState = "listView"; + VascEntry entry = createClonedVascEntry(); + renderer = new JSFVascFrontendRenderer(); + try { + renderer.initEntry(entry); + } catch (Exception e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + supportBean = new JSFVascEntrySupportBean(entry); + init = true; + + // no need to add multiple + if (link!=null) { + logger.finer("Adding phase listener: JSFVascValidatePhaseListener"); + context.getViewRoot().addPhaseListener(new JSFVascValidatePhaseListener()); + } + + } + + // set the support bean + String entrySupportVar = (String)getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY); + ValueExpression ve2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+"}", Object.class); + ve2.setValue(FacesContext.getCurrentInstance().getELContext(), getSupportBean()); + + // set init for component renderer + if (init) { + initClear = false; + if (link!=null) { + initClear = true; + } + } + super.encodeBegin(context); + } + + public UIComponent getCurrentView() { + UIComponent result = getFacet(renderFacetState); + if (result==null) { + throw new IllegalArgumentException("Could not get facet: "+renderFacetState); + } + return result; + } + + public JSFVascEntrySupportBean getSupportBean() { + return supportBean; + } + + public void setRenderFacetState(String renderFacetState) { + this.renderFacetState=renderFacetState; + } + + public String getRenderFacetState() { + return renderFacetState; + } + + public VascEntry createClonedVascEntry() { + + String entryName = null; + VascController vascController = null; + VascFrontendData frontendData = null; + + if (getAttributes().get(VASC_CONTROLLER_KEY) instanceof String) { + // fix for JSP tag handler + logger.finer("Getting expression: "+getAttributes().get(VASC_CONTROLLER_KEY)); + ValueExpression ve1 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), (String)getAttributes().get(VASC_CONTROLLER_KEY), Object.class); + ValueExpression ve2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), (String)getAttributes().get(VASC_FRONTEND_DATA_KEY), Object.class); + ValueExpression ve3 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), (String)getAttributes().get(ENTRY_NAME_KEY), String.class); + vascController = (VascController)ve1.getValue( FacesContext.getCurrentInstance().getELContext()); + frontendData = (VascFrontendData)ve2.getValue( FacesContext.getCurrentInstance().getELContext()); + entryName = (String)ve3.getValue( FacesContext.getCurrentInstance().getELContext()); + } else { + vascController = (VascController)getAttributes().get(VASC_CONTROLLER_KEY); + frontendData = (VascFrontendData)getAttributes().get(VASC_FRONTEND_DATA_KEY); + entryName = (String)getAttributes().get(ENTRY_NAME_KEY); + } + + if (link!=null) { + entryName = link.getVascEntryId(); + } + + VascEntry entry = vascController.getVascEntryControllerResolver().getVascEntryController().getVascEntryById(entryName); + if (entry==null) { + throw new NullPointerException("Could not locate '"+entryName+"' from : "+vascController); + } + + frontendData.setVascController(vascController); + entry.setVascFrontendData(frontendData); + + VascBackend backend = entry.getVascFrontendData().getVascController().getVascBackendControllerResolver().getVascBackendController().getVascBackendById(entry.getBackendId()); + + for (VascBackendFilter filter:entry.getVascBackendFilters()) { + filter.initFilter(entry); + backend = new VascBackendProxyFilter(backend,entry,filter); + } + if (backend.isSearchable()==false) { + backend = new VascBackendProxySearch(backend,entry); + } + if (backend.isSortable()==false) { + backend = new VascBackendProxySort(backend,entry); + } + if (backend.isPageable()==false) { + backend = new VascBackendProxyPaged(backend,entry); + } + frontendData.setVascBackend(backend); + + if (link!=null) { + try { + Object selected = getSupportBean().getSelected().getRecord(); + for (String parameterName:link.getEntryParameterFieldIdKeys()) { + String fieldId = link.getEntryParameterFieldId(parameterName); + VascEntryField v = getVascEntry().getVascEntryFieldById(fieldId); + Object selectedValue = v.getVascEntryFieldValue().getValue(v, selected); + + // set data parameter on new vasc entry + entry.getVascFrontendData().getVascBackendState().setDataParameter(parameterName, selectedValue); + logger.fine("Setting link parameter: "+parameterName+" with: "+selectedValue); + } + + for (String fieldId:link.getEntryCreateFieldValueKeys()) { + String selectedfieldId = link.getEntryParameterFieldId(fieldId); + Object selectedValue = selected; + if (selectedfieldId!=null) { + VascEntryField v = getVascEntry().getVascEntryFieldById(selectedfieldId); + selectedValue = v.getVascEntryFieldValue().getValue(v, selected); + } + + // create listener for new objects + entry.addVascEntryEventListener(VascEventType.DATA_CREATE, new CreateEntryFieldValuesListener2(fieldId,selectedValue)); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + + String entrySupportVar = (String)getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY); + entry.addVascEntryEventListener(VascEntryEventListener.VascEventType.DATA_LIST_UPDATE, new JSFVascEntryEventListener(entrySupportVar)); + + return entry; + } + + class CreateEntryFieldValuesListener2 implements VascEntryEventListener { + private static final long serialVersionUID = 1L; + private String fieldId = null; + private Object value = null; + public CreateEntryFieldValuesListener2(String fieldId,Object value) { + if (fieldId==null) { + throw new NullPointerException("fieldId may not be null"); + } + this.fieldId=fieldId; + this.value=value; + } + public void vascEvent(VascEntry entry,VascEventType type, Object data) { + VascEntryField field = entry.getVascEntryFieldById(fieldId); + try { + field.getVascEntryFieldValue().setValue(field, data, value); + } catch (VascException e) { + entry.getVascFrontendData().getVascFrontendHelper().handleException(entry, e); + } + } + @Override + public VascEntryEventListener clone() throws CloneNotSupportedException { + return this; + } + } +} \ No newline at end of file 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 new file mode 100644 index 0000000..a0dd9b1 --- /dev/null +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentRenderer.java @@ -0,0 +1,452 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.frontends.web.jsf; + +import java.io.IOException; +import java.io.Serializable; +import java.util.List; +import java.util.logging.Logger; + +import javax.el.ELContext; +import javax.el.MethodExpression; +import javax.el.ValueExpression; +import javax.faces.FacesException; +import javax.faces.application.Application; +import javax.faces.application.FacesMessage; +import javax.faces.component.UIColumn; +import javax.faces.component.UIComponent; +import javax.faces.component.UIInput; +import javax.faces.component.UIOutput; +import javax.faces.component.UIViewRoot; +import javax.faces.component.html.HtmlCommandLink; +import javax.faces.component.html.HtmlDataTable; +import javax.faces.component.html.HtmlMessage; +import javax.faces.component.html.HtmlOutputText; +import javax.faces.context.FacesContext; +import javax.faces.context.ResponseWriter; +import javax.faces.event.ActionEvent; +import javax.faces.event.MethodExpressionActionListener; +import javax.faces.render.Renderer; +import javax.faces.validator.Validator; +import javax.faces.validator.ValidatorException; + +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.core.VascEntryField; +import com.idcanet.vasc.core.VascException; +import com.idcanet.vasc.core.VascLinkEntry; +import com.idcanet.vasc.core.actions.RowVascAction; +import com.idcanet.vasc.core.ui.VascOptionValueModelListener; +import com.idcanet.vasc.core.ui.VascValueModel; +import com.idcanet.vasc.impl.actions.AddRowAction; + +/** + * Renders an JSF vasc entry views. + * + * This is a bit hacky because I'm not a JSF guro. + * + * @author Willem Cazander + * @version 1.0 Nov 16, 2008 + */ +public class JSFVascUIComponentRenderer extends Renderer { + + private Logger logger = null; + + public JSFVascUIComponentRenderer() { + logger = Logger.getLogger(JSFVascUIComponentRenderer.class.getName()); + } + + @Override + public void encodeBegin(FacesContext facesContext,UIComponent component) throws IOException { + super.encodeBegin(facesContext, component); + ResponseWriter writer = facesContext.getResponseWriter(); + JSFVascUIComponent comp = (JSFVascUIComponent)component; + logger.fine("renderen encodeBegin for: "+comp.getRenderFacetState()); + writer.startElement("div", component); + //String styleClass = (String)attributes.get(Shuffler.STYLECLASS_ATTRIBUTE_KEY); + //writer.writeAttribute("class", styleClass, null); + + // check if injection is needed + if (comp.getInitClear()!=null) { + injectAll(facesContext,comp,comp.getInitClear()); + } + + // render the current facet of the vasc component + UIComponent view = comp.getCurrentView(); + view.encodeAll(facesContext); + } + + @Override + public void encodeEnd(FacesContext facesContext,UIComponent component) throws IOException { + ResponseWriter writer = facesContext.getResponseWriter(); + writer.endElement("div"); + } + + + // ========== All private + + + private void injectAll(FacesContext context,JSFVascUIComponent comp,boolean clean) { + + String injectEditFieldsId = (String)comp.getAttributes().get(JSFVascUIComponent.INJECT_EDIT_FIELDS_ID); + String injectTableOptionsId = (String)comp.getAttributes().get(JSFVascUIComponent.INJECT_TABLE_OPTIONS_ID); + String injectTableColumnsId = (String)comp.getAttributes().get(JSFVascUIComponent.INJECT_TABLE_COLUMNS_ID); + + UIComponent injectEditFieldsComponent = JSFVascUIComponent.findComponentById(comp.getFacet("editView"),injectEditFieldsId); + UIComponent injectTableOptionsComponent = JSFVascUIComponent.findComponentById(comp.getCurrentView(),injectTableOptionsId); + UIComponent injectTableColumnsComponent = JSFVascUIComponent.findComponentById(comp.getCurrentView(),injectTableColumnsId); + if (injectEditFieldsComponent==null) { + throw new NullPointerException("Could not find injectEditFieldsId: "+injectEditFieldsId); + } + if (injectTableOptionsComponent==null) { + throw new NullPointerException("Could not find injectTableOptionsId: "+injectTableOptionsId); + } + if (injectTableColumnsComponent==null) { + throw new NullPointerException("Could not find injectTableColumnsId: "+injectTableColumnsId); + } + + if (clean) { + logger.finer("Cleaning of all dynamic JSF components."); + injectEditFieldsComponent.getChildren().clear(); + injectTableOptionsComponent.getChildren().clear(); + injectTableColumnsComponent.getChildren().clear(); + } + logger.finer("Injection of all dynamic JSF components."); + try { + addEditFields(context, injectEditFieldsComponent); + addTableOptions(context, injectTableOptionsComponent); + addColumns(context,comp,injectTableColumnsComponent ); + } catch (Exception e) { + throw new RuntimeException("Error while injecting; "+e.getMessage(),e); + } + } + + private String i18n(VascEntry entry,String key,Object...params) { + return entry.getVascFrontendData().getVascEntryResourceResolver().getTextValue(key,params); + } + + + private void addEditFields(FacesContext fc,UIComponent grid) throws FacesException, VascException { + + Application application = fc.getApplication(); + UIViewRoot viewRoot = fc.getViewRoot(); + + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(grid); + VascEntry entry = comp.getVascEntry(); + String entrySupportVar = (String)comp.getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY); + + int column = 0; + for (VascEntryField c:entry.getVascEntryFields()) { + if (entry.getVascFrontendData().getVascFrontendHelper().renderEdit(c)==false) { + continue; + } + + for (int i=0;i errors = entry.getVascFrontendData().getVascFrontendHelper().validateObjectField(field); + //System.out.println("Validate: "+component+" errors: "+errors.size()+" value: "+object); + if (errors.isEmpty()) { + return; // no errors + } + + StringBuffer buf = new StringBuffer(200); + for (String err:errors) { + buf.append(err); + buf.append('\n'); + } + FacesMessage message = new FacesMessage(buf.toString()); + message.setSeverity(FacesMessage.SEVERITY_ERROR); + throw new ValidatorException(message); + } + } + + + private void addTableOptions(FacesContext fc,UIComponent grid) throws FacesException, VascException { + + //Application application = fc.getApplication(); + //UIViewRoot viewRoot = fc.getViewRoot(); + + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(grid); + VascEntry entry = comp.getVascEntry(); + + for (VascEntryField option:entry.getListOptions()) { + for (int i=0;i[] argtypes = new Class[1]; + argtypes[0] = ActionEvent.class; + FacesContext facesCtx = FacesContext.getCurrentInstance(); + ELContext elContext = facesCtx.getELContext(); + return facesCtx.getApplication().getExpressionFactory().createMethodExpression(elContext, name, null, argtypes); + } + +} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentTag.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentTag.java new file mode 100644 index 0000000..18062cf --- /dev/null +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascUIComponentTag.java @@ -0,0 +1,247 @@ +/* + * Copyright 2004-2007 IDCA. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and + * the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions + * and the following disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the authors and + * should not be interpreted as representing official policies, either expressed or implied, of IDCA. + */ + +package com.idcanet.vasc.frontends.web.jsf; + + +import javax.el.ValueExpression; +import javax.faces.component.UIComponent; +import javax.faces.webapp.UIComponentELTag; + +/** + * + * + * @author Willem Cazander + * @version 1.0 Nov 16, 2008 + */ +public class JSFVascUIComponentTag extends UIComponentELTag { + + public static final String COMPONENT_TYPE = "vasc.jsf.component"; + public static final String RENDERER_TYPE = "vasc.jsf.component.renderer"; + + private ValueExpression vascController = null; + private ValueExpression vascFrontendData = null; + private ValueExpression entryName = null; + private ValueExpression entrySupportVar = null; + private ValueExpression tableRecordVar = null; + private ValueExpression injectEditFieldsId = null; + private ValueExpression injectTableOptionsId = null; + private ValueExpression injectTableColumnsId = null; + + // noty used + private ValueExpression bundleName = null; + private ValueExpression locale = null; + + @Override + public String getComponentType() { + return COMPONENT_TYPE; + } + + @Override + public String getRendererType() { + return RENDERER_TYPE; + } + + /** + * @see javax.faces.webapp.UIComponentELTag#setProperties(javax.faces.component.UIComponent) + */ + @Override + protected void setProperties(UIComponent component) { + super.setProperties(component); + processProperty(component, vascController, JSFVascUIComponent.VASC_CONTROLLER_KEY); + processProperty(component, vascFrontendData, JSFVascUIComponent.VASC_FRONTEND_DATA_KEY); + processProperty(component, entryName, JSFVascUIComponent.ENTRY_NAME_KEY); + processProperty(component, entrySupportVar, JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY); + processProperty(component, tableRecordVar, JSFVascUIComponent.TABLE_RECORD_VAR_KEY); + processProperty(component, injectEditFieldsId, JSFVascUIComponent.INJECT_EDIT_FIELDS_ID); + processProperty(component, injectTableOptionsId,JSFVascUIComponent.INJECT_TABLE_OPTIONS_ID); + processProperty(component, injectTableColumnsId,JSFVascUIComponent.INJECT_TABLE_COLUMNS_ID); + } + + public void release() { + super.release(); + vascController = null; + vascFrontendData = null; + entryName = null; + entrySupportVar = null; + tableRecordVar = null; + injectEditFieldsId = null; + injectTableOptionsId = null; + injectTableColumnsId = null; + } + + protected final void processProperty(final UIComponent component, final ValueExpression property,final String propertyName) { + if (property != null) { + if(property.isLiteralText()) { + component.getAttributes().put(propertyName, property.getExpressionString()); + } else { + component.setValueExpression(propertyName, property); + } + } + } + + // ============= BEAN FIELDS + + /** + * @return the vascController + */ + public ValueExpression getVascController() { + return vascController; + } + + /** + * @param vascController the vascController to set + */ + public void setVascController(ValueExpression vascController) { + this.vascController = vascController; + } + + /** + * @return the entryName + */ + public ValueExpression getEntryName() { + return entryName; + } + + /** + * @param entryName the entryName to set + */ + public void setEntryName(ValueExpression entryName) { + this.entryName = entryName; + } + + /** + * @return the bundleName + */ + public ValueExpression getBundleName() { + return bundleName; + } + + /** + * @param bundleName the bundleName to set + */ + public void setBundleName(ValueExpression bundleName) { + this.bundleName = bundleName; + } + + /** + * @return the locale + */ + public ValueExpression getLocale() { + return locale; + } + + /** + * @param locale the locale to set + */ + public void setLocale(ValueExpression locale) { + this.locale = locale; + } + + /** + * @return the vascFrontendData + */ + public ValueExpression getVascFrontendData() { + return vascFrontendData; + } + + /** + * @param vascFrontendData the vascFrontendData to set + */ + public void setVascFrontendData(ValueExpression vascFrontendData) { + this.vascFrontendData = vascFrontendData; + } + + /** + * @return the entrySupportVar + */ + public ValueExpression getEntrySupportVar() { + return entrySupportVar; + } + + /** + * @param entrySupportVar the entrySupportVar to set + */ + public void setEntrySupportVar(ValueExpression entrySupportVar) { + this.entrySupportVar = entrySupportVar; + } + + /** + * @return the injectEditFieldsId + */ + public ValueExpression getInjectEditFieldsId() { + return injectEditFieldsId; + } + + /** + * @param injectEditFieldsId the injectEditFieldsId to set + */ + public void setInjectEditFieldsId(ValueExpression injectEditFieldsId) { + this.injectEditFieldsId = injectEditFieldsId; + } + + /** + * @return the injectTableOptionsId + */ + public ValueExpression getInjectTableOptionsId() { + return injectTableOptionsId; + } + + /** + * @param injectTableOptionsId the injectTableOptionsId to set + */ + public void setInjectTableOptionsId(ValueExpression injectTableOptionsId) { + this.injectTableOptionsId = injectTableOptionsId; + } + + /** + * @return the injectTableColumnsId + */ + public ValueExpression getInjectTableColumnsId() { + return injectTableColumnsId; + } + + /** + * @param injectTableColumnsId the injectTableColumnsId to set + */ + public void setInjectTableColumnsId(ValueExpression injectTableColumnsId) { + this.injectTableColumnsId = injectTableColumnsId; + } + + /** + * @return the tableRecordVar + */ + public ValueExpression getTableRecordVar() { + return tableRecordVar; + } + + /** + * @param tableRecordVar the tableRecordVar to set + */ + public void setTableRecordVar(ValueExpression tableRecordVar) { + this.tableRecordVar = tableRecordVar; + } +} \ No newline at end of file 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 new file mode 100644 index 0000000..dddfebd --- /dev/null +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/JSFVascValidatePhaseListener.java @@ -0,0 +1,78 @@ +/** + * + */ +package com.idcanet.vasc.frontends.web.jsf; + +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.component.UIInput; +import javax.faces.context.FacesContext; +import javax.faces.event.PhaseEvent; +import javax.faces.event.PhaseId; +import javax.faces.event.PhaseListener; +import javax.faces.validator.Validator; +import javax.faces.validator.ValidatorException; + +import com.idcanet.vasc.core.VascEntry; +import com.idcanet.vasc.frontends.web.jsf.JSFVascUIComponentRenderer.VascJSFInputValidator2; + +/** + * @author willemc + * + */ +public class JSFVascValidatePhaseListener implements PhaseListener { + + private static final long serialVersionUID = 1L; + public void afterPhase(PhaseEvent event) { + FacesContext context = event.getFacesContext(); + validateUIInput(context.getViewRoot(),context); + } + public void beforePhase(PhaseEvent event) { + } + public PhaseId getPhaseId() { + return PhaseId.PROCESS_VALIDATIONS; + } + private void validateUIInput(UIComponent component,FacesContext context) { + if (component instanceof UIInput) { + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(component); + if (comp==null) { + return; // non-vasc ui-input + } + VascEntry entry = comp.getVascEntry(); + if (entry.getVascFrontendData().getEntryDataObject()==null) { + return; // we are not in edit mode. + } + UIInput in = (UIInput)component; + for (Validator v:in.getValidators()) { + if (v instanceof VascJSFInputValidator2) { + VascJSFInputValidator2 validator = (VascJSFInputValidator2)v; + try { + in.setValid(true); + //Object value = in.getValue(); + //System.out.println("Checking value: "+value); + validator.validatePhase(context, in, in.getValue()); + } catch (ValidatorException ve) { + //System.out.println("Error"); + in.setValid(false); + + // note: ve has the message already but this is the UIInput way + FacesMessage message; + String validatorMessageString = in.getValidatorMessage(); + if (null != validatorMessageString) { + message = new FacesMessage(FacesMessage.SEVERITY_ERROR,validatorMessageString,validatorMessageString); + message.setSeverity(FacesMessage.SEVERITY_ERROR); + } else { + message = ve.getFacesMessage(); + } + if (message != null) { + context.addMessage(in.getClientId(context), message); + } + } + } + } + } + for (UIComponent child:component.getChildren()) { + validateUIInput(child,context); + } + } +} diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascUIComponent.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/OldVascUIComponent.java similarity index 91% rename from src/main/java/com/idcanet/vasc/frontends/web/jsf/VascUIComponent.java rename to src/main/java/com/idcanet/vasc/frontends/web/jsf/OldVascUIComponent.java index fcc1f75..85c3245 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascUIComponent.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/OldVascUIComponent.java @@ -93,6 +93,8 @@ import com.idcanet.vasc.impl.VascBackendProxySearch; import com.idcanet.vasc.impl.VascBackendProxySort; /** + * Only here for archive a bit, does not work anymore. + * * Renders an JSF vasc entry views. * * This is a bit hacky because I'm not a JSF guro. @@ -100,7 +102,7 @@ import com.idcanet.vasc.impl.VascBackendProxySort; * @author Willem Cazander * @version 1.0 Nov 16, 2008 */ -public class VascUIComponent extends UIComponentBase { +public class OldVascUIComponent extends UIComponentBase { public static final String COMPONENT_TYPE = "com.idcanet.vasc.frontends.web.jsf.VascUIComponent"; private Object[] state = null; @@ -243,6 +245,12 @@ public class VascUIComponent extends UIComponentBase { } tableDataModel.setWrappedData(result); pagesDataModel.setWrappedData(entry.getVascFrontendData().getVascFrontendHelper().getVascBackendPageNumbers(entry)); + + // ui value + ValueExpression ren3 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.values['totalPageResults']}", Integer.class); + ren3.setValue(FacesContext.getCurrentInstance().getELContext(), getVascEntry().getVascFrontendData().getEntryDataList().size()); + ValueExpression ren4 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.values['totalResults']}", Integer.class); + ren4.setValue(FacesContext.getCurrentInstance().getELContext(), getVascEntry().getVascFrontendData().getTotalBackendRecords()); } @Override public VascEntryEventListener clone() throws CloneNotSupportedException { @@ -253,23 +261,23 @@ public class VascUIComponent extends UIComponentBase { return entry; } - static public VascUIComponent findVascParent(UIComponent comp) { + static public OldVascUIComponent findVascParent(UIComponent comp) { if (comp==null) { return null; } - if (comp instanceof VascUIComponent) { - return (VascUIComponent)comp; + if (comp instanceof OldVascUIComponent) { + return (OldVascUIComponent)comp; } return findVascParent(comp.getParent()); } - static public VascUIComponent findVascChild(UIComponent comp,String entryId) { + static public OldVascUIComponent findVascChild(UIComponent comp,String entryId) { if (comp==null) { return null; } //System.out.println("Checking object: "+comp); - if (comp instanceof VascUIComponent) { - VascUIComponent ui = (VascUIComponent)comp; + if (comp instanceof OldVascUIComponent) { + OldVascUIComponent ui = (OldVascUIComponent)comp; if (entryId.equals(ui.getVascEntry().getId())) { return ui; } @@ -278,7 +286,7 @@ public class VascUIComponent extends UIComponentBase { for (UIComponent c:comp.getChildren()) { Object res = findVascChild(c,entryId); if (res!=null) { - return (VascUIComponent)res; // found + return (OldVascUIComponent)res; // found } } return null; @@ -531,13 +539,18 @@ public class VascUIComponent extends UIComponentBase { */ @Override public void encodeEnd(FacesContext context) throws IOException { + + //UIComponent deleteComponent = getFacet("deleteForm"); + //if (deleteComponent != null) { + // deleteComponent.encodeAll(context); + //} + if (defaultRenderView) { VascEntry entry = getVascEntry(); JSFFrontendRenderer r = (JSFFrontendRenderer)entry.getVascFrontendData().getVascFrontend(); if (r==null) { return; } - //System.out.println("defaultRenderView = true"); try { r.renderView(); } catch (Exception e) { @@ -561,7 +574,7 @@ public class VascUIComponent extends UIComponentBase { } private void validateUIInput(UIComponent component,FacesContext context) { if (component instanceof UIInput) { - VascUIComponent comp = VascUIComponent.findVascParent(component); + OldVascUIComponent comp = OldVascUIComponent.findVascParent(component); if (comp==null) { return; // non-vasc ui-input } @@ -669,17 +682,19 @@ public class VascUIComponent extends UIComponentBase { UIPanel panelDelete = (UIPanel)application.createComponent(UIPanel.COMPONENT_TYPE); panelDelete.setId(viewRoot.createUniqueId()); + this.getFacetsAndChildren(); + HtmlOutputText title = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); title.setId(viewRoot.createUniqueId()); - title.setValue(i18n(entry.getName())); - title.setStyleClass("style_header1"); + title.setValue("

"+i18n(entry.getName())+"

"); + title.setEscape(false); panelDelete.getChildren().add(title); - HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); - br.setId(viewRoot.createUniqueId()); - br.setValue("

"); - br.setEscape(false); - panelDelete.getChildren().add(br); + //HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + //br.setId(viewRoot.createUniqueId()); + //br.setValue("

"); + //br.setEscape(false); + //panelDelete.getChildren().add(br); HtmlOutputText header = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); header.setId(viewRoot.createUniqueId()); @@ -699,7 +714,7 @@ public class VascUIComponent extends UIComponentBase { ValueExpression ve7 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.selected.field"+index+"}", Object.class); text.setValueExpression("value", ve7); - br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); br.setId(viewRoot.createUniqueId()); br.setValue("
"); br.setEscape(false); @@ -738,15 +753,15 @@ public class VascUIComponent extends UIComponentBase { HtmlOutputText title = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); title.setId(viewRoot.createUniqueId()); - title.setValue(i18n(entry.getName())); - title.setStyleClass("style_header1"); + title.setValue("

"+i18n(entry.getName())+"

"); + title.setEscape(false); panelEdit.getChildren().add(title); - HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); - br.setId(viewRoot.createUniqueId()); - br.setValue("

"); - br.setEscape(false); - panelEdit.getChildren().add(br); + //HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + //br.setId(viewRoot.createUniqueId()); + //br.setValue("

"); + //br.setEscape(false); + //panelEdit.getChildren().add(br); /* String displayFieldId = entry.getDisplayNameFieldId(); @@ -777,8 +792,9 @@ public class VascUIComponent extends UIComponentBase { HtmlPanelGrid grid = (HtmlPanelGrid)application.createComponent(HtmlPanelGrid.COMPONENT_TYPE); grid.setId(viewRoot.createUniqueId()); grid.setColumns(3); - grid.setHeaderClass("style_tableHeader1"); - grid.setColumnClasses("style_tableDarkGray_dub, style_tableLightGray_dub, style_tableLightGray_dub"); + grid.setStyleClass("form"); + //grid.setHeaderClass("style_tableHeader1"); + //grid.setColumnClasses("style_tableDarkGray_dub, style_tableLightGray_dub, style_tableLightGray_dub"); panelEdit.getChildren().add(grid); HtmlOutputText gridHeaderText = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); @@ -830,7 +846,7 @@ public class VascUIComponent extends UIComponentBase { } } - br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); br.setId(viewRoot.createUniqueId()); br.setValue("
"); br.setEscape(false); @@ -868,7 +884,7 @@ public class VascUIComponent extends UIComponentBase { // always oke, we are runned by phase listener } public void validatePhase(FacesContext context, UIComponent component,Object object) throws ValidatorException { - VascUIComponent comp = VascUIComponent.findVascParent(component); + OldVascUIComponent comp = OldVascUIComponent.findVascParent(component); VascEntry entry = comp.getVascEntry(); VascEntryField field = entry.getVascEntryFieldById(fieldId); @@ -903,8 +919,8 @@ public class VascUIComponent extends UIComponentBase { HtmlOutputText title = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); title.setId(viewRoot.createUniqueId()); - title.setValue(i18n(entry.getName())); - title.setStyleClass("style_header1"); + title.setValue("

"+i18n(entry.getName())+"

"); + title.setEscape(false); panelExport.getChildren().add(title); HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); @@ -960,7 +976,7 @@ public class VascUIComponent extends UIComponentBase { @SuppressWarnings("serial") class ExportActionListener implements ActionListener,Serializable { public void processAction(ActionEvent event) { - VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + OldVascUIComponent comp = OldVascUIComponent.findVascParent(event.getComponent()); VascEntry entry = comp.getVascEntry(); try { VascEntryExporter ex = comp.exporter; @@ -995,7 +1011,7 @@ public class VascUIComponent extends UIComponentBase { @SuppressWarnings("serial") class BackActionListener implements ActionListener,Serializable { public void processAction(ActionEvent event) { - VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + OldVascUIComponent comp = OldVascUIComponent.findVascParent(event.getComponent()); VascEntry entry = comp.getVascEntry(); entry.getVascFrontendData().setEntryDataObject(null); ValueExpression ve2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.selected}", Object.class); @@ -1014,7 +1030,7 @@ public class VascUIComponent extends UIComponentBase { @SuppressWarnings("serial") class DeleteActionListener implements ActionListener,Serializable { public void processAction(ActionEvent event) { - VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + OldVascUIComponent comp = OldVascUIComponent.findVascParent(event.getComponent()); VascEntry entry = comp.getVascEntry(); entry.getVascFrontendData().getVascFrontendHelper().deleteObject(entry); try { @@ -1027,7 +1043,7 @@ public class VascUIComponent extends UIComponentBase { @SuppressWarnings("serial") class SaveActionListener implements ActionListener,Serializable { public void processAction(ActionEvent event) { - VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + OldVascUIComponent comp = OldVascUIComponent.findVascParent(event.getComponent()); VascEntry entry = comp.getVascEntry(); ValueExpression ve2 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.selected}", Object.class); @@ -1047,7 +1063,7 @@ public class VascUIComponent extends UIComponentBase { class PageLinkActionListener implements ActionListener,Serializable { public void processAction(ActionEvent event) { Integer pageIndex = (Integer)((HtmlCommandLink)event.getComponent()).getValue(); - VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + OldVascUIComponent comp = OldVascUIComponent.findVascParent(event.getComponent()); VascEntry entry = comp.getVascEntry(); entry.getVascFrontendData().getVascFrontendHelper().pageAction(entry, pageIndex); @@ -1062,7 +1078,7 @@ public class VascUIComponent extends UIComponentBase { class SortActionListener implements ActionListener,Serializable { public void processAction(ActionEvent event) { String fieldIdString = ((HtmlCommandLink)event.getComponent()).getType(); - VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + OldVascUIComponent comp = OldVascUIComponent.findVascParent(event.getComponent()); VascEntry entry = comp.getVascEntry(); VascEntryField field = entry.getVascEntryFieldById(fieldIdString); @@ -1083,7 +1099,7 @@ public class VascUIComponent extends UIComponentBase { @SuppressWarnings("serial") class SearchActionListener implements ActionListener,Serializable { public void processAction(ActionEvent event) { - VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + OldVascUIComponent comp = OldVascUIComponent.findVascParent(event.getComponent()); VascEntry entry = comp.getVascEntry(); ValueExpression ve3 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.searchString}", String.class); @@ -1101,7 +1117,7 @@ public class VascUIComponent extends UIComponentBase { class MoveActionListener implements ActionListener,Serializable { public void processAction(ActionEvent event) { String to = (String)((HtmlCommandLink)event.getComponent()).getType(); - VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent()); + OldVascUIComponent comp = OldVascUIComponent.findVascParent(event.getComponent()); VascEntry entry = comp.getVascEntry(); Object selected = comp.getSelectedTableObject(); if ("up".equals(to)) { @@ -1128,15 +1144,15 @@ public class VascUIComponent extends UIComponentBase { HtmlOutputText title = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); title.setId(viewRoot.createUniqueId()); - title.setValue(i18n(entry.getName())); - title.setStyleClass("style_header1"); + title.setValue("

"+i18n(entry.getName())+"

"); + title.setEscape(false); panelView.getChildren().add(title); - HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); - br.setId(viewRoot.createUniqueId()); - br.setValue("

"); - br.setEscape(false); - panelView.getChildren().add(br); + //HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + //br.setId(viewRoot.createUniqueId()); + //br.setValue("

"); + //br.setEscape(false); + //panelView.getChildren().add(br); HtmlOutputText header = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); header.setEscape(false); @@ -1144,46 +1160,41 @@ public class VascUIComponent extends UIComponentBase { header.setValue(i18n(entry.getListDescription())); panelView.getChildren().add(header); - br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); br.setId(viewRoot.createUniqueId()); br.setValue("

"); br.setEscape(false); panelView.getChildren().add(br); + HtmlOutputText tabHeader = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); + tabHeader.setId(viewRoot.createUniqueId()); + tabHeader.setValue(""); + tabHeader.setEscape(false); + panelView.getChildren().add(tabHeader); + HtmlPanelGrid grid = (HtmlPanelGrid)application.createComponent(HtmlPanelGrid.COMPONENT_TYPE); grid.setId(viewRoot.createUniqueId()); - grid.setColumns(2); - grid.setHeaderClass("style_tableHeader1"); - grid.setColumnClasses(", style_tableDarkGray_dub"); + grid.setColumns(1); + grid.setStyleClass("form"); + grid.setWidth("100%"); panelView.getChildren().add(grid); - - HtmlOutputText gridHeaderText = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); - gridHeaderText.setId(viewRoot.createUniqueId()); - gridHeaderText.setValue("Options"); - grid.getFacets().put("header", gridHeaderText); - + HtmlPanelGroup options = (HtmlPanelGroup)application.createComponent(HtmlPanelGroup.COMPONENT_TYPE); options.setId(viewRoot.createUniqueId()); grid.getChildren().add(options); - HtmlCommandButton search = (HtmlCommandButton)application.createComponent(HtmlCommandButton.COMPONENT_TYPE); - search.setId(viewRoot.createUniqueId()); - search.addActionListener(new SearchActionListener()); - search.setValue("Search"); - grid.getChildren().add(search); - - HtmlPanelGrid gridOption = (HtmlPanelGrid)application.createComponent(HtmlPanelGrid.COMPONENT_TYPE); - gridOption.setId(viewRoot.createUniqueId()); - gridOption.setColumns(1); - gridOption.setColumnClasses("style_tableDarkGray_dub"); - options.getChildren().add(gridOption); + //HtmlPanelGroup gridOption = (HtmlPanelGrid)application.createComponent(HtmlPanelGrid.COMPONENT_TYPE); + //gridOption.setId(viewRoot.createUniqueId()); + //gridOption.setColumns(1); + //gridOption.setColumnClasses("style_tableDarkGray_dub"); + //options.getChildren().add(gridOption); for (VascEntryField option:entry.getListOptions()) { for (int i=0;i values = new HashMap(10); - private VascDataBackendBean selected = null; - - /** - * @return the searchString - */ - public String getSearchString() { - return searchString; - } - - /** - * @param searchString the searchString to set - */ - public void setSearchString(String searchString) { - this.searchString = searchString; - } - - /** - * @return the values - */ - public Map getValues() { - return values; - } - - /** - * @return the selected - */ - public VascDataBackendBean getSelected() { - return selected; - } - - /** - * @param selected the selected to set - */ - public void setSelected(VascDataBackendBean selected) { - this.selected = selected; - } -} diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascRequestFacesFilter.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascRequestFacesFilter.java index 6df39aa..a26d26b 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascRequestFacesFilter.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascRequestFacesFilter.java @@ -63,7 +63,10 @@ public class VascRequestFacesFilter implements Filter { /** * @see javax.servlet.Filter#destroy() */ - public void destroy() { + public void destroy() { + servletContext = null; + templateFile = null; + logger = null; } /** diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascUIComponentTag.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascUIComponentTag.java deleted file mode 100644 index 85320d5..0000000 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/VascUIComponentTag.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright 2004-2007 IDCA. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the - * following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and - * the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions - * and the following disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the authors and - * should not be interpreted as representing official policies, either expressed or implied, of IDCA. - */ - -package com.idcanet.vasc.frontends.web.jsf; - - -import javax.el.ValueExpression; -import javax.faces.component.UIComponent; -import javax.faces.webapp.UIComponentELTag; -import javax.servlet.jsp.JspException; - -/** - * - * - * @author Willem Cazander - * @version 1.0 Nov 16, 2008 - */ -public class VascUIComponentTag extends UIComponentELTag { - - private ValueExpression vascController = null; - private ValueExpression vascFrontendData = null; - private ValueExpression entryName = null; - private ValueExpression bundleName = null; - private ValueExpression locale = null; - - /** - * @see javax.faces.webapp.UIComponentELTag#setProperties(javax.faces.component.UIComponent) - */ - @Override - protected void setProperties(UIComponent comp) { - super.setProperties(comp); - VascUIComponent component = (VascUIComponent)comp; - component.setVascController(vascController); - component.setEntryName(entryName); - component.setVascFrontendData(vascFrontendData); - component.init(); - } - - /** - * @see javax.faces.webapp.UIComponentClassicTagBase#doStartTag() - */ - @Override - public int doStartTag() throws JspException { - int result = super.doStartTag(); - return result; - } - - @Override - public String getComponentType() { - return VascUIComponent.COMPONENT_TYPE; - } - - @Override - public String getRendererType() { - return null; - } - - /** - * @return the vascController - */ - public ValueExpression getVascController() { - return vascController; - } - - /** - * @param vascController the vascController to set - */ - public void setVascController(ValueExpression vascController) { - this.vascController = vascController; - } - - /** - * @return the entryName - */ - public ValueExpression getEntryName() { - return entryName; - } - - /** - * @param entryName the entryName to set - */ - public void setEntryName(ValueExpression entryName) { - this.entryName = entryName; - } - - /** - * @return the bundleName - */ - public ValueExpression getBundleName() { - return bundleName; - } - - /** - * @param bundleName the bundleName to set - */ - public void setBundleName(ValueExpression bundleName) { - this.bundleName = bundleName; - } - - /** - * @return the locale - */ - public ValueExpression getLocale() { - return locale; - } - - /** - * @param locale the locale to set - */ - public void setLocale(ValueExpression locale) { - this.locale = locale; - } - - /** - * @return the vascFrontendData - */ - public ValueExpression getVascFrontendData() { - return vascFrontendData; - } - - /** - * @param vascFrontendData the vascFrontendData to set - */ - public void setVascFrontendData(ValueExpression vascFrontendData) { - this.vascFrontendData = vascFrontendData; - } -} \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/AbstractJSFBaseComponent.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/AbstractJSFBaseComponent.java index ac97ce6..3b85f67 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/AbstractJSFBaseComponent.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/AbstractJSFBaseComponent.java @@ -30,6 +30,7 @@ import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import com.idcanet.vasc.core.ui.VascUIComponent; +import com.idcanet.vasc.frontends.web.jsf.JSFVascUIComponent; /** @@ -59,7 +60,7 @@ abstract public class AbstractJSFBaseComponent implements VascUIComponent { * @see com.idcanet.vasc.core.ui.VascUIComponent#isRendered() */ public boolean isRendered() { - UIComponent component = (UIComponent)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); + UIComponent component = (UIComponent)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); return component.isRendered(); } diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFBoolean.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFBoolean.java index ed67d0a..4388f01 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFBoolean.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFBoolean.java @@ -36,6 +36,7 @@ import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.ui.VascValueModel; +import com.idcanet.vasc.frontends.web.jsf.JSFVascUIComponent; /** @@ -62,7 +63,7 @@ public class JSFBoolean extends AbstractJSFBaseComponent { * @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled() */ public boolean isDisabled() { - HtmlSelectBooleanCheckbox component = (HtmlSelectBooleanCheckbox)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); + HtmlSelectBooleanCheckbox component = (HtmlSelectBooleanCheckbox)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); return component.isDisabled(); } @@ -70,7 +71,7 @@ public class JSFBoolean extends AbstractJSFBaseComponent { * @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean) */ public void setDisabled(boolean disabled) { - HtmlSelectBooleanCheckbox component = (HtmlSelectBooleanCheckbox)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); + HtmlSelectBooleanCheckbox component = (HtmlSelectBooleanCheckbox)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); component.setDisabled(disabled); } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFList.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFList.java index 3356dca..b44b51c 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFList.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFList.java @@ -48,6 +48,7 @@ import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.ui.VascSelectItem; import com.idcanet.vasc.core.ui.VascSelectItemModel; import com.idcanet.vasc.core.ui.VascValueModel; +import com.idcanet.vasc.frontends.web.jsf.JSFVascUIComponent; /** @@ -65,12 +66,15 @@ public class JSFList extends AbstractJSFBaseComponent { HtmlSelectOneMenu component = (HtmlSelectOneMenu)application.createComponent(HtmlSelectOneMenu.COMPONENT_TYPE); component.setId(viewRoot.createUniqueId()); componentId = component.getId(); + + JSFVascUIComponent comp = JSFVascUIComponent.findVascParent((UIComponent)gui); + String entrySupportVar = (String)comp.getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY); String id = component.getId(); - ValueExpression itemsTestVE = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.values['jsfListItems_"+id+"']}", TestModel.class); + ValueExpression itemsTestVE = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".editSelectItemModels['jsfListItems_"+id+"']}", TestModel.class); - ValueExpression itemsDisVE = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.values['jsfListItemDis_"+id+"']}", Boolean.class); - itemsDisVE.setValue(FacesContext.getCurrentInstance().getELContext(), false); + //ValueExpression itemsDisVE = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.values['jsfListItemDis_"+id+"']}", Boolean.class); + //itemsDisVE.setValue(FacesContext.getCurrentInstance().getELContext(), false); TestModel t = new TestModel(); t.entryField=entryField; @@ -80,7 +84,7 @@ public class JSFList extends AbstractJSFBaseComponent { UISelectItems item = (UISelectItems)application.createComponent(UISelectItems.COMPONENT_TYPE); item.setId(viewRoot.createUniqueId()); - ValueExpression itemsVE = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.values['jsfListItems_"+id+"']}", List.class); + ValueExpression itemsVE = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".editSelectItemModels['jsfListItems_"+id+"']}", List.class); item.setValueExpression("value", itemsVE); component.getChildren().add(item); @@ -92,7 +96,7 @@ public class JSFList extends AbstractJSFBaseComponent { * @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled() */ public boolean isDisabled() { - HtmlSelectOneMenu component = (HtmlSelectOneMenu)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); + HtmlSelectOneMenu component = (HtmlSelectOneMenu)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); return component.isDisabled(); } @@ -100,7 +104,7 @@ public class JSFList extends AbstractJSFBaseComponent { * @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean) */ public void setDisabled(boolean disabled) { - HtmlSelectOneMenu component = (HtmlSelectOneMenu)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); + HtmlSelectOneMenu component = (HtmlSelectOneMenu)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); component.setDisabled(disabled); } } diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFText.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFText.java index b460b4f..1752fab 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFText.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFText.java @@ -40,6 +40,7 @@ import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.ui.VascValueModel; +import com.idcanet.vasc.frontends.web.jsf.JSFVascUIComponent; /** @@ -71,7 +72,7 @@ public class JSFText extends AbstractJSFBaseComponent { * @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled() */ public boolean isDisabled() { - HtmlInputText component = (HtmlInputText)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); + HtmlInputText component = (HtmlInputText)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); return component.isDisabled(); } @@ -79,7 +80,7 @@ public class JSFText extends AbstractJSFBaseComponent { * @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean) */ public void setDisabled(boolean disabled) { - HtmlInputText component = (HtmlInputText)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); + HtmlInputText component = (HtmlInputText)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); component.setDisabled(disabled); } } diff --git a/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFTextArea.java b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFTextArea.java index 3823ffd..79b1fb4 100644 --- a/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFTextArea.java +++ b/src/main/java/com/idcanet/vasc/frontends/web/jsf/ui/JSFTextArea.java @@ -36,6 +36,7 @@ import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.ui.VascValueModel; +import com.idcanet.vasc.frontends.web.jsf.JSFVascUIComponent; /** @@ -70,7 +71,7 @@ public class JSFTextArea extends AbstractJSFBaseComponent { * @see com.idcanet.vasc.core.ui.VascUIComponent#isDisabled() */ public boolean isDisabled() { - HtmlInputTextarea component = (HtmlInputTextarea)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); + HtmlInputTextarea component = (HtmlInputTextarea)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); return component.isDisabled(); } @@ -78,7 +79,7 @@ public class JSFTextArea extends AbstractJSFBaseComponent { * @see com.idcanet.vasc.core.ui.VascUIComponent#setDisabled(boolean) */ public void setDisabled(boolean disabled) { - HtmlInputTextarea component = (HtmlInputTextarea)com.idcanet.vasc.frontends.web.jsf.VascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); + HtmlInputTextarea component = (HtmlInputTextarea)JSFVascUIComponent.findComponentById(FacesContext.getCurrentInstance().getViewRoot(),componentId); component.setDisabled(disabled); } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascBackedEntryFinalizer.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascBackedEntryFinalizer.java index 99f8672..a0f12b1 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascBackedEntryFinalizer.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascBackedEntryFinalizer.java @@ -122,6 +122,13 @@ public class DefaultVascBackedEntryFinalizer implements VascEntryFinalizer { entry.setCreateImage("vasc.entry."+id+".createImage"); } + // boolean view helper + if (entry.isVascDisplayOnly()) { + entry.setVascAdminCreate(false); + entry.setVascAdminDelete(false); + entry.setVascAdminEdit(false); + } + // optional field sets for (VascEntryFieldSet s:entry.getVascEntryFieldSets()) { diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascEntryField.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascEntryField.java index 1f526a1..f6e25f5 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascEntryField.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascEntryField.java @@ -137,7 +137,8 @@ public class DefaultVascEntryField implements VascEntryField { result.sumable=sumable; result.graphable=graphable; - result.vascEntryFieldValue=vascEntryFieldValue; + // this polls full backend.. + //result.vascEntryFieldValue=vascEntryFieldValue; for (VascValidator val:vascValidators) { result.vascValidators.add(val.clone()); diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java index f2db105..adb5c0c 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascFrontendHelper.java @@ -27,6 +27,7 @@ package com.idcanet.vasc.impl; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -191,18 +192,12 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { return result; // no pages } int pages = new Long(total/state.getPageSize()).intValue(); - int counter = 0; for (int i=0;i<=pages;i++) { VascBackendPageNumber pn = new VascBackendPageNumber(i); if (state.getPageIndex()==i) { pn.setSelected(true); } result.add(pn); - - counter++; - if (counter>45) { - break; - } } return result; } @@ -227,12 +222,20 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { */ public Object createObject(VascEntry entry) { try { - Object object = entry.getVascFrontendData().getVascBackend().provideVascEntryRecordCreator(entry).newRecord(entry); + Object object = entry.getVascFrontendData().getVascBackend().provideVascEntryRecordCreator(entry.clone()).newRecord(entry); for (VascEntryField field:entry.getVascEntryFields()) { Object value = field.getVascEntryFieldValue().getValue(field, object); if (value==null & field.getDefaultValue()!=null) { - logger.finer("Setting default value for: "+field.getName()+" def: "+field.getDefaultValue()); - field.getVascEntryFieldValue().setValue(field, object, field.getDefaultValue()); + + Object defaultValue = field.getDefaultValue(); + if (defaultValue instanceof String) { + String def = (String)defaultValue; + if (def.equals("now()")) { // TODO: add default string parsers + defaultValue = new Date(); + } + } + logger.finer("Setting default value for: "+field.getName()+" def: "+defaultValue); + field.getVascEntryFieldValue().setValue(field, object, defaultValue); } } fireVascEvent(entry,VascEventType.DATA_CREATE, object); @@ -290,7 +293,7 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { entry.getVascFrontendData().getEntryDataList().add(index, result); entry.getVascFrontendData().setEntryDataObject(null); fireVascEvent(entry,VascEventType.DATA_POST_UPDATE,result); - fireVascEvent(entry,VascEventType.DATA_LIST_UPDATE, object); + fireVascEvent(entry,VascEventType.DATA_LIST_UPDATE,result); } catch (Exception e) { handleException(entry,e); } @@ -327,12 +330,9 @@ public class DefaultVascFrontendHelper implements VascFrontendHelper { } entry.getVascFrontendData().setEntryDataList(entry.getVascFrontendData().getVascBackend().execute(entry.getVascFrontendData().getVascBackendState())); - Long total = entry.getVascFrontendData().getTotalBackendRecords(); - if (total==null) { - // fetch on first time. - total = entry.getVascFrontendData().getVascBackend().fetchTotalExecuteSize(entry.getVascFrontendData().getVascBackendState()); - entry.getVascFrontendData().setTotalBackendRecords(total); - } + // also update total every time + Long total = entry.getVascFrontendData().getVascBackend().fetchTotalExecuteSize(entry.getVascFrontendData().getVascBackendState()); + entry.getVascFrontendData().setTotalBackendRecords(total); } catch (Exception e) { handleException(entry, e); } diff --git a/src/main/java/com/idcanet/vasc/impl/DefaultVascSelectItemModel.java b/src/main/java/com/idcanet/vasc/impl/DefaultVascSelectItemModel.java index 3aee91f..b731c3a 100644 --- a/src/main/java/com/idcanet/vasc/impl/DefaultVascSelectItemModel.java +++ b/src/main/java/com/idcanet/vasc/impl/DefaultVascSelectItemModel.java @@ -34,6 +34,7 @@ import com.idcanet.vasc.core.VascBackendState; import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascException; +import com.idcanet.vasc.core.entry.VascEntryFieldValue; import com.idcanet.vasc.core.ui.VascSelectItem; import com.idcanet.vasc.core.ui.VascSelectItemModel; @@ -46,6 +47,7 @@ import com.idcanet.vasc.core.ui.VascSelectItemModel; */ public class DefaultVascSelectItemModel implements VascSelectItemModel { + private static final long serialVersionUID = 1L; private String entryId = null; private String keyFieldId = null; private String displayFieldId = null; @@ -94,6 +96,25 @@ public class DefaultVascSelectItemModel implements VascSelectItemModel { state.setDataParameter(key2, value); } + // TODO: FIX >>>>>>>>>>>>>>>>>> + if (key.getVascEntryFieldValue()==null) { + // TODO: fix this for better remote support + VascEntryField fieldClone = key.clone(); + fieldClone.getVascValidators().clear(); + + VascEntryFieldValue v = entry.getVascFrontendData().getVascBackend().provideVascEntryFieldValue(fieldClone); + key.setVascEntryFieldValue(v); + } + if (dis.getVascEntryFieldValue()==null) { + // TODO: fix this for better remote support + VascEntryField fieldClone = dis.clone(); + fieldClone.getVascValidators().clear(); + + VascEntryFieldValue v = entry.getVascFrontendData().getVascBackend().provideVascEntryFieldValue(fieldClone); + dis.setVascEntryFieldValue(v); + } + + // execute for (Object o:back.execute(state)) { Object keyId = key.getVascEntryFieldValue().getValue(key, o); diff --git a/src/main/java/com/idcanet/vasc/impl/VascBackendProxyPaged.java b/src/main/java/com/idcanet/vasc/impl/VascBackendProxyPaged.java index e08dd78..be46e4b 100644 --- a/src/main/java/com/idcanet/vasc/impl/VascBackendProxyPaged.java +++ b/src/main/java/com/idcanet/vasc/impl/VascBackendProxyPaged.java @@ -27,7 +27,9 @@ package com.idcanet.vasc.impl; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import com.idcanet.vasc.core.AbstractVascBackendProxy; import com.idcanet.vasc.core.VascBackend; @@ -45,9 +47,13 @@ import com.idcanet.vasc.core.VascException; public class VascBackendProxyPaged extends AbstractVascBackendProxy { private long records = 0; + private List data = null; + private String dataSearchString = null; + private Map dataState = null; public VascBackendProxyPaged(VascBackend backend,VascEntry entry) { super(backend); + dataState = new HashMap(10); } /** @@ -63,7 +69,34 @@ public class VascBackendProxyPaged extends AbstractVascBackendProxy { */ @Override public List execute(VascBackendState state) throws VascException { - List allData = backend.execute(state); + boolean changed = false; + for (String key:state.getDataParameterKeys()) { + Object value = state.getDataParameter(key); + Object valueLast = dataState.get(key); + dataState.put(key, value); + if (value==null & valueLast==null) { + continue; + } + if (value==null & valueLast!=null) { + changed = true; + break; + } + if (value.equals(valueLast)==false) { + changed = true; + break; + } + } + + if (state.getSearchString()!=null && state.getSearchString().equals(dataSearchString)==false) { + changed = true; + } + dataSearchString = state.getSearchString(); + + + if (data==null | changed) { + data = backend.execute(state); + } + List allData = data; int pageSize = state.getPageSize(); if (pageSize==0) { records = allData.size(); diff --git a/src/main/java/com/idcanet/vasc/impl/VascBackendProxySort.java b/src/main/java/com/idcanet/vasc/impl/VascBackendProxySort.java index e66a43f..76df4d2 100644 --- a/src/main/java/com/idcanet/vasc/impl/VascBackendProxySort.java +++ b/src/main/java/com/idcanet/vasc/impl/VascBackendProxySort.java @@ -66,8 +66,9 @@ public class VascBackendProxySort extends AbstractVascBackendProxy { if (state.getSortField()==null) { return result; } - final VascEntryField field = entry.getVascEntryFieldById(state.getSortField()); - final VascEntryFieldValue fieldValue = backend.provideVascEntryFieldValue(field); + try { + final VascEntryField field = entry.getVascEntryFieldById(state.getSortField()); + final VascEntryFieldValue fieldValue = backend.provideVascEntryFieldValue(field.clone()); Collections.sort(result, new Comparator() { public int compare(Object o1, Object o2) { try { @@ -112,7 +113,15 @@ public class VascBackendProxySort extends AbstractVascBackendProxy { return 0; } } + + + }); + + } catch (CloneNotSupportedException e1) { + throw new VascException(e1); + } // TODO: check serialable stuff again + return result; } } \ No newline at end of file diff --git a/src/main/java/com/idcanet/vasc/impl/actions/CSVExportGlobalAction.java b/src/main/java/com/idcanet/vasc/impl/actions/CSVExportGlobalAction.java index 1d2d570..aefd7d1 100644 --- a/src/main/java/com/idcanet/vasc/impl/actions/CSVExportGlobalAction.java +++ b/src/main/java/com/idcanet/vasc/impl/actions/CSVExportGlobalAction.java @@ -61,15 +61,27 @@ public class CSVExportGlobalAction extends AbstractVascAction implements GlobalV p.write(c.getId()+"\t"); } p.write("\n"); - for (Object o:entry.getVascFrontendData().getEntryDataList()) { - for (VascEntryField c:entry.getVascEntryFields()) { - p.write(c.getVascEntryFieldValue().getDisplayValue(c, o)+"\t"); + + int oldIndex = entry.getVascFrontendData().getVascBackendState().getPageIndex(); + Long total = entry.getVascFrontendData().getTotalBackendRecords(); + int pages = total.intValue()/entry.getVascFrontendData().getVascBackendState().getPageSize(); + for (int page=0;page\n"); p.write("\n"); - for (Object o:entry.getVascFrontendData().getEntryDataList()) { - p.write("\t\n"); - for (VascEntryField c:entry.getVascEntryFields()) { - p.write("\t\t\n"); + + int oldIndex = entry.getVascFrontendData().getVascBackendState().getPageIndex(); + Long total = entry.getVascFrontendData().getTotalBackendRecords(); + int pages = total.intValue()/entry.getVascFrontendData().getVascBackendState().getPageSize(); + for (int page=0;page\n"); + for (VascEntryField c:entry.getVascEntryFields()) { + p.write("\t\t\n"); + } + p.write("\t\n"); + p.flush(); } - p.write("\t\n"); - p.flush(); } p.write("\n"); p.flush(); + + // restore old page size + entry.getVascFrontendData().getVascBackendState().setPageIndex(oldIndex); } public String getMineType() { diff --git a/src/main/java/com/idcanet/vasc/impl/entry/BeanPropertyVascEntryFieldValue.java b/src/main/java/com/idcanet/vasc/impl/entry/BeanPropertyVascEntryFieldValue.java index 2dbe2fb..d985df7 100644 --- a/src/main/java/com/idcanet/vasc/impl/entry/BeanPropertyVascEntryFieldValue.java +++ b/src/main/java/com/idcanet/vasc/impl/entry/BeanPropertyVascEntryFieldValue.java @@ -29,7 +29,7 @@ package com.idcanet.vasc.impl.entry; import com.idcanet.vasc.core.VascEntryField; import com.idcanet.vasc.core.VascException; import com.idcanet.vasc.core.entry.VascEntryFieldValue; -import com.idcanet.x4o.impl.DefaultElementParameterHelper; +import com.idcanet.x4o.impl.DefaultElementObjectPropertyValue; /** * @@ -40,10 +40,10 @@ public class BeanPropertyVascEntryFieldValue implements VascEntryFieldValue { private String property = null; - private DefaultElementParameterHelper helper = null; + private DefaultElementObjectPropertyValue helper = null; public BeanPropertyVascEntryFieldValue() { - helper = new DefaultElementParameterHelper(); + helper = new DefaultElementObjectPropertyValue(); } public BeanPropertyVascEntryFieldValue(String property) { this(); @@ -61,7 +61,7 @@ public class BeanPropertyVascEntryFieldValue implements VascEntryFieldValue { return ""; } try { - return helper.getParameter(record, getProperty()); + return helper.getProperty(record, getProperty()); } catch (Exception e) { throw new VascException(e); } @@ -85,7 +85,7 @@ public class BeanPropertyVascEntryFieldValue implements VascEntryFieldValue { return; } try { - helper.setParameter(record, getProperty(),value); + helper.setProperty(record, getProperty(),value); } catch (Exception e) { throw new VascException(e); } diff --git a/src/main/java/com/idcanet/vasc/impl/x4o/SelectItemModelBindingHandler.java b/src/main/java/com/idcanet/vasc/impl/x4o/SelectItemModelBindingHandler.java index 143f39f..0d69411 100644 --- a/src/main/java/com/idcanet/vasc/impl/x4o/SelectItemModelBindingHandler.java +++ b/src/main/java/com/idcanet/vasc/impl/x4o/SelectItemModelBindingHandler.java @@ -31,7 +31,7 @@ import com.idcanet.vasc.core.VascEntryFieldType; import com.idcanet.vasc.core.ui.VascSelectItemModel; import com.idcanet.x4o.element.AbstractElementBindingHandler; import com.idcanet.x4o.element.Element; -import com.idcanet.x4o.element.ElementBindingException; +import com.idcanet.x4o.element.ElementBindingHandlerException; /** * Binds SelectItems @@ -61,7 +61,7 @@ public class SelectItemModelBindingHandler extends AbstractElementBindingHandler /** * @see com.idcanet.x4o.element.ElementBindingHandler#doBind(com.idcanet.x4o.element.Element) */ - public void doBind(Element element) throws ElementBindingException { + public void doBind(Element element) throws ElementBindingHandlerException { Object child = element.getElementObject(); Object parentObject = element.getParent().getElementObject(); if (parentObject instanceof VascEntryField) { diff --git a/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldBindingHandler.java b/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldBindingHandler.java index 2d71d57..7446704 100644 --- a/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldBindingHandler.java +++ b/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldBindingHandler.java @@ -30,7 +30,7 @@ import com.idcanet.vasc.core.VascEntry; import com.idcanet.vasc.core.VascEntryField; import com.idcanet.x4o.element.AbstractElementBindingHandler; import com.idcanet.x4o.element.Element; -import com.idcanet.x4o.element.ElementBindingException; +import com.idcanet.x4o.element.ElementBindingHandlerException; /** * Binds fields @@ -60,7 +60,7 @@ public class VascEntryFieldBindingHandler extends AbstractElementBindingHandler /** * @see com.idcanet.x4o.element.ElementBindingHandler#doBind(com.idcanet.x4o.element.Element) */ - public void doBind(Element element) throws ElementBindingException { + public void doBind(Element element) throws ElementBindingHandlerException { Object childObject = element.getElementObject(); Object parentObject = element.getParent().getElementObject(); if (parentObject instanceof VascEntry) { diff --git a/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldSetParameterConverter.java b/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldSetAttributeConverter.java similarity index 82% rename from src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldSetParameterConverter.java rename to src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldSetAttributeConverter.java index f840c8a..40f9d07 100644 --- a/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldSetParameterConverter.java +++ b/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldSetAttributeConverter.java @@ -27,9 +27,9 @@ package com.idcanet.vasc.impl.x4o; import com.idcanet.vasc.core.VascEntryFieldSet; -import com.idcanet.x4o.element.AbstractElementParameterConverter; +import com.idcanet.x4o.element.AbstractElementAttributeConverter; import com.idcanet.x4o.element.Element; -import com.idcanet.x4o.element.ElementParameterConverterException; +import com.idcanet.x4o.element.ElementAttributeConverterException; /** @@ -38,12 +38,12 @@ import com.idcanet.x4o.element.ElementParameterConverterException; * @author Willem Cazander * @version 1.0 Nov 17, 2008 */ -public class VascEntryFieldSetParameterConverter extends AbstractElementParameterConverter { +public class VascEntryFieldSetAttributeConverter extends AbstractElementAttributeConverter { /** - * @see com.idcanet.x4o.element.AbstractElementParameterConverter#doConvertParameter(com.idcanet.x4o.element.Element, java.lang.Object) + * @see com.idcanet.x4o.element.AbstractElementAttributeConverter#doConvertAttribute(com.idcanet.x4o.element.Element, java.lang.Object) */ - public Object doConvertParameter(Element element, Object parameterValue) throws ElementParameterConverterException { + public Object doConvertAttribute(Element element, Object parameterValue) throws ElementAttributeConverterException { if (parameterValue==null) { throw new NullPointerException("can't convert null parameter"); diff --git a/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldTypeParameterConverter.java b/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldTypeAttributeConverter.java similarity index 83% rename from src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldTypeParameterConverter.java rename to src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldTypeAttributeConverter.java index f495b4f..f318dd0 100644 --- a/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldTypeParameterConverter.java +++ b/src/main/java/com/idcanet/vasc/impl/x4o/VascEntryFieldTypeAttributeConverter.java @@ -27,9 +27,9 @@ package com.idcanet.vasc.impl.x4o; import com.idcanet.vasc.core.VascController; -import com.idcanet.x4o.element.AbstractElementParameterConverter; +import com.idcanet.x4o.element.AbstractElementAttributeConverter; import com.idcanet.x4o.element.Element; -import com.idcanet.x4o.element.ElementParameterConverterException; +import com.idcanet.x4o.element.ElementAttributeConverterException; /** @@ -38,12 +38,12 @@ import com.idcanet.x4o.element.ElementParameterConverterException; * @author Willem Cazander * @version 1.0 Nov 16, 2008 */ -public class VascEntryFieldTypeParameterConverter extends AbstractElementParameterConverter { +public class VascEntryFieldTypeAttributeConverter extends AbstractElementAttributeConverter { /** - * @see com.idcanet.x4o.element.AbstractElementParameterConverter#doConvertParameter(com.idcanet.x4o.element.Element, java.lang.Object) + * @see com.idcanet.x4o.element.AbstractElementAttributeConverter#doConvertAttribute(com.idcanet.x4o.element.Element, java.lang.Object) */ - public Object doConvertParameter(Element element, Object parameterValue) throws ElementParameterConverterException { + public Object doConvertAttribute(Element element, Object parameterValue) throws ElementAttributeConverterException { if (parameterValue==null) { throw new NullPointerException("can't convert null parameter"); diff --git a/src/main/java/com/idcanet/vasc/validators/VascValidator.java b/src/main/java/com/idcanet/vasc/validators/VascValidator.java index ac74fb9..de9f24f 100644 --- a/src/main/java/com/idcanet/vasc/validators/VascValidator.java +++ b/src/main/java/com/idcanet/vasc/validators/VascValidator.java @@ -26,6 +26,7 @@ package com.idcanet.vasc.validators; +import java.io.Serializable; import java.lang.annotation.Annotation; /** @@ -34,7 +35,7 @@ import java.lang.annotation.Annotation; * @author Willem Cazander * @version 1.0 Sep 5, 2008 */ -public interface VascValidator { +public interface VascValidator extends Cloneable,Serializable { public boolean isObjectValid(Object object) throws VascValidatorException; diff --git a/src/main/resources/META-INF/faces-config.xml b/src/main/resources/META-INF/faces-config.xml index adc02ce..1b2b7dc 100644 --- a/src/main/resources/META-INF/faces-config.xml +++ b/src/main/resources/META-INF/faces-config.xml @@ -1,17 +1,25 @@ - + + + - com.idcanet.vasc.frontends.web.jsf.VascUIComponent - com.idcanet.vasc.frontends.web.jsf.VascUIComponent + + Vasc JSF Component + vasc.jsf.component + com.idcanet.vasc.frontends.web.jsf.JSFVascUIComponent + + vasc.jsf.component.renderer + - - Controls the vasc actions - vascActionBean - com.idcanet.vasc.frontends.web.jsf.VascActionBean - session - - + + + vasc.jsf.component.family + vasc.jsf.component.renderer + com.idcanet.vasc.frontends.web.jsf.JSFVascUIComponentRenderer + + + com.idcanet.vasc.frontends.web.jsf.VascViewHandler diff --git a/src/main/resources/META-INF/fieldtype-lang.eld b/src/main/resources/META-INF/fieldtype/fieldtype-lang.eld similarity index 93% rename from src/main/resources/META-INF/fieldtype-lang.eld rename to src/main/resources/META-INF/fieldtype/fieldtype-lang.eld index 3deb1b7..9775506 100644 --- a/src/main/resources/META-INF/fieldtype-lang.eld +++ b/src/main/resources/META-INF/fieldtype/fieldtype-lang.eld @@ -2,11 +2,11 @@ - + - + Vasc namespace for the fieldtype language - META-INF/fieldtype-lang.eld + fieldtype-lang.eld \ No newline at end of file diff --git a/src/main/resources/META-INF/vasc.taglib.xml b/src/main/resources/META-INF/vasc.taglib.xml new file mode 100644 index 0000000..2ddc81c --- /dev/null +++ b/src/main/resources/META-INF/vasc.taglib.xml @@ -0,0 +1,12 @@ + + + + http://vasc.idcanet.com/vasc.tld + + vascEntry + + vasc.jsf.component + vasc.jsf.component.renderer + + + diff --git a/src/main/resources/META-INF/vasc.tld b/src/main/resources/META-INF/vasc.tld index 8ca190e..5a0ce55 100644 --- a/src/main/resources/META-INF/vasc.tld +++ b/src/main/resources/META-INF/vasc.tld @@ -1,44 +1,101 @@ - JSTL 1.1 core library + Vasc JSF 2.1 library Vasc - 1.1 + 2.1 vasc http://vasc.idcanet.com/vasc.tld Renders the vasc entry JSF Frontend Renderer vascEntry - com.idcanet.vasc.frontends.web.jsf.VascUIComponentTag - JSP + com.idcanet.vasc.frontends.web.jsf.JSFVascUIComponentTag + JSP + + + id + false + + + rendered + false + + boolean + + + + binding + false + + javax.faces.component.UIComponent + + + vascController true - true - + + com.idcanet.vasc.core.VascController + entryName false - true - + + java.lang.String + vascFrontendData true - true - + + com.idcanet.vasc.core.VascFrontendData + + + + entrySupportVar + true + + java.lang.String + + + + tableRecordVar + true + + java.lang.String + + + + injectEditFieldsId + true + + java.lang.String + + + + injectTableOptionsId + true + + java.lang.String + + + + injectTableColumnsId + true + + java.lang.String + bundleName false - false locale false - false + diff --git a/src/main/resources/META-INF/vasc-lang.eld b/src/main/resources/META-INF/vasc/vasc-lang.eld similarity index 93% rename from src/main/resources/META-INF/vasc-lang.eld rename to src/main/resources/META-INF/vasc/vasc-lang.eld index 7a054de..08f825c 100644 --- a/src/main/resources/META-INF/vasc-lang.eld +++ b/src/main/resources/META-INF/vasc/vasc-lang.eld @@ -19,7 +19,7 @@ - + @@ -27,7 +27,7 @@ - + @@ -35,7 +35,7 @@ - + @@ -58,12 +58,12 @@ - + - + diff --git a/src/main/resources/META-INF/vasc-namespaces.xml b/src/main/resources/META-INF/vasc/vasc-namespaces.xml similarity index 64% rename from src/main/resources/META-INF/vasc-namespaces.xml rename to src/main/resources/META-INF/vasc/vasc-namespaces.xml index ac27382..a52db5a 100644 --- a/src/main/resources/META-INF/vasc-namespaces.xml +++ b/src/main/resources/META-INF/vasc/vasc-namespaces.xml @@ -4,5 +4,5 @@ Vasc namespace for the fieldtype language - META-INF/vasc-lang.eld + vasc-lang.eld \ No newline at end of file diff --git a/src/test/java/com/idcanet/vasc/VascI18nTextValue.java b/src/test/java/com/idcanet/vasc/VascI18nTextValue.java index a796a7c..e13636c 100644 --- a/src/test/java/com/idcanet/vasc/VascI18nTextValue.java +++ b/src/test/java/com/idcanet/vasc/VascI18nTextValue.java @@ -41,6 +41,11 @@ import com.idcanet.vasc.core.entry.VascEntryResourceResolver; */ public class VascI18nTextValue implements VascEntryResourceResolver { + private Logger logger = null; + + public VascI18nTextValue() { + logger = Logger.getLogger(VascI18nTextValue.class.getName()); + } private String getKeyMapping(String key) { return key; @@ -50,7 +55,7 @@ public class VascI18nTextValue implements VascEntryResourceResolver { return i18n(getKeyMapping(key),params); } - static private String i18n(String key,Object...params) { + private String i18n(String key,Object...params) { if (key==null) { throw new NullPointerException("key may not be null"); } try { String text = ResourceBundle.getBundle("resources.i18n.vasc").getString(key); @@ -60,7 +65,7 @@ public class VascI18nTextValue implements VascEntryResourceResolver { } return text; } catch(MissingResourceException e){ - Logger.getAnonymousLogger().finer("Missing i18n or non i18n key: "+key); + logger.finer("Missing i18n or non i18n key: "+key); return key; } }