2
0
Fork 0

[svn r388] made very good progress on JSF templated frontend

This commit is contained in:
willemc 2009-11-13 01:40:13 +01:00
parent 9a605f177a
commit c1a8402ae8
57 changed files with 2783 additions and 553 deletions

View file

@ -5,6 +5,11 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.j2eedt.core.WebClasspathBuilder</name>
<arguments>
@ -58,5 +63,6 @@
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>

View file

@ -116,7 +116,7 @@
<optional/>
</dependency>
<!-- SWT depency TODO: linux only, wait for 3.4 !! -->
<!-- SWT depency TODO: linux only, wait for 3.4 !!
<dependency>
<groupId>org.eclipse.swt.gtk.linux</groupId>
<artifactId>x86</artifactId>
@ -131,6 +131,7 @@
<scope>compile</scope>
<optional/>
</dependency>
-->
<!-- EE5 + JSF + etc -->
<dependency>

View file

@ -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();

View file

@ -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();

View file

@ -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);
}
}
}

View file

@ -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();
}
}

View file

@ -37,4 +37,6 @@ import javax.persistence.EntityManager;
public interface EntityManagerProvider {
public EntityManager getEntityManager();
public boolean hasEntityManagerTransaction();
}

View file

@ -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);
}
/**

View file

@ -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<Object> 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();

View file

@ -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

View file

@ -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

View file

@ -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);

View file

@ -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);

View file

@ -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();

View file

@ -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,

View file

@ -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();

View file

@ -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;

View file

@ -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;

View file

@ -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.

View file

@ -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<Object> data = entry.getVascFrontendData().getEntryDataList();
List<Object> result = new ArrayList<Object>(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;
}
}

View file

@ -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<String,Object> 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<String,Object>(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<String,String> 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<SelectItem> getGlobalExportItems() {
List<SelectItem> result = new ArrayList<SelectItem>(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<SelectItem> getDirectPageItems() {
List<SelectItem> result = new ArrayList<SelectItem>(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;i<getTablePagesDataModel().getRowCount();i++) {
getTablePagesDataModel().setRowIndex(i);
VascBackendPageNumber page = (VascBackendPageNumber)getTablePagesDataModel().getRowData();
s = new SelectItem();
s.setLabel("Page: "+page.getPageNumber()+" "+(i*pageSize)+"-"+((i*pageSize)+pageSize));
s.setDescription("Ga naar pagina: "+page.getPageNumber());
s.setValue(page.getPageNumber());
result.add(s);
}
return result;
}
public boolean getHasExtendedPageMode() {
int pages = getTablePagesDataModel().getRowCount();
if (pages>13) {
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<VascBackendPageNumber> getTablePagesExtendedBegin() {
List<VascBackendPageNumber> result = new ArrayList<VascBackendPageNumber>(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<VascBackendPageNumber> getTablePagesExtendedEnd() {
List<VascBackendPageNumber> result = new ArrayList<VascBackendPageNumber>(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<VascBackendPageNumber> getTablePagesExtendedCenter() {
List<VascBackendPageNumber> result = new ArrayList<VascBackendPageNumber>(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<String, Object> getEditSelectItemModels() {
return editSelectItemModels;
}
}
class JSFVascSupportI18nMapController implements Map<String,String> {
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<Map.Entry<String, String>> 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<String> 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<String> values() {
return null;
}
}

View file

@ -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);
}
}
}

View file

@ -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<UIComponent> 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;
}
}
}

View file

@ -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<c.getVascEntryFieldType().getUIComponentCount(c);i++) {
com.idcanet.vasc.core.ui.VascUIComponent label = c.getVascEntryFieldType().provideLabelUIComponent(i,c);
VascValueModel model = new VascValueModel();
model.setValue(i18n(entry,c.getName()));
label.createComponent(entry,c,model,grid);
com.idcanet.vasc.core.ui.VascUIComponent editor = c.getVascEntryFieldType().provideEditorUIComponent(i,c);
model = new VascValueModel(c.getVascEntryFieldType().provideEditorVascValueModel(i,c));
//model.setValue(c.getVascEntryFieldValue().getValue(c, bean));
//model.addListener(new VascColumnValueModelListener(c,bean));
UIInput jsfEdit = (UIInput)editor.createComponent(entry,c,model,grid);
jsfEdit.addValidator(new VascJSFInputValidator2(c.getId()));
int index = VascDataBackendBean.getIndexId(c);
ValueExpression ve7 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".selected.field"+index+"}", Object.class);
jsfEdit.setValueExpression("value", ve7);
ValueExpression ve8 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".selected != null}", Boolean.class);
jsfEdit.setValueExpression("rendered", ve8);
HtmlMessage message = (HtmlMessage)application.createComponent(HtmlMessage.COMPONENT_TYPE);
message.setId(viewRoot.createUniqueId());
message.setFor(jsfEdit.getId());
message.setErrorClass("style_textBlue");
message.setFatalClass("style_textRed");
message.setInfoClass("style_textBlack");
message.setWarnClass("style_textGreen");
grid.getChildren().add(message);
column++;
// i==0 is for multi field editor support... which is still very in progress
if (i==0) {
entry.getVascFrontendData().addFieldVascUIComponents(c, editor,jsfEdit);
}
}
}
}
class VascJSFInputValidator2 implements Validator,Serializable {
private static final long serialVersionUID = -5715250529474737642L;
String fieldId = null;
public VascJSFInputValidator2(String fieldId) {
this.fieldId=fieldId;
}
public void validate(FacesContext context, UIComponent component,Object object) throws ValidatorException {
// always oke, we are runned by phase listener
}
public void validatePhase(FacesContext context, UIComponent component,Object object) throws ValidatorException {
JSFVascUIComponent comp = JSFVascUIComponent.findVascParent(component);
VascEntry entry = comp.getVascEntry();
VascEntryField field = entry.getVascEntryFieldById(fieldId);
String entrySupportVar = (String)comp.getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY);
// note we have to set the value to the vasc backend before we can run validation
int index = VascDataBackendBean.getIndexId(field);
ValueExpression ve7 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".selected.field"+index+"}", Object.class);
ve7.setValue(FacesContext.getCurrentInstance().getELContext(), object);
List<String> 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<option.getVascEntryFieldType().getUIComponentCount(option);i++) {
com.idcanet.vasc.core.ui.VascUIComponent label = option.getVascEntryFieldType().provideLabelUIComponent(i,option);
VascValueModel model = new VascValueModel();
model.setValue(i18n(entry,option.getName()));
label.createComponent(entry,option,model,grid);
com.idcanet.vasc.core.ui.VascUIComponent editor = option.getVascEntryFieldType().provideEditorUIComponent(i,option);
model = new VascValueModel(option.getVascEntryFieldType().provideEditorVascValueModel(i,option));
model.addListener(new VascOptionValueModelListener(option));
model.setValue(null);
UIInput jsfEdit = (UIInput)editor.createComponent(entry,option,model,grid);
//ValueExpression ve7 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+getSelectedRecordName()+"."+option.getBackendName()+"}", Object.class);
//jsfEdit.setValueExpression("value", ve7);
// i==0 is for multi field editor support... which is stell very in progress
if (i==0) {
entry.getVascFrontendData().addFieldVascUIComponents(option, editor,jsfEdit);
}
}
}
entry.getVascFrontendData().getVascFrontendHelper().headerOptionsCreatedFillData(entry);
}
private void addColumns(FacesContext fc,JSFVascUIComponent comp,UIComponent table) {
Application application = fc.getApplication();
UIViewRoot viewRoot = fc.getViewRoot();
VascEntry entry = comp.getVascEntry();
String entrySupportVar = (String)comp.getAttributes().get(JSFVascUIComponent.ENTRY_SUPPORT_VAR_KEY);
String tableRecordVar = (String)comp.getAttributes().get(JSFVascUIComponent.TABLE_RECORD_VAR_KEY);
for (VascEntryField c:entry.getVascEntryFields()) {
if (entry.getVascFrontendData().getVascFrontendHelper().renderList(c)==false) {
continue;
}
UIColumn col = (UIColumn)application.createComponent(UIColumn.COMPONENT_TYPE);
col.setId(viewRoot.createUniqueId());
HtmlCommandLink link = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE);
link.setId(viewRoot.createUniqueId());
link.setType(c.getId());
MethodExpression actionExpression = getMethodExpression("#{"+entrySupportVar+".sortAction}");
MethodExpressionActionListener meActionListener = new MethodExpressionActionListener(actionExpression);
link.addActionListener(meActionListener);
HtmlOutputText out2 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
out2.setId(viewRoot.createUniqueId());
out2.setEscape(false);
out2.setValue(i18n(entry,c.getName())+"&nbsp;");
HtmlOutputText orderUp = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
orderUp.setId(viewRoot.createUniqueId());
orderUp.setEscape(false);
orderUp.setValue("&#x2191;"); //
ValueExpression ren2 = application.getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".sortOrder==true and "+entrySupportVar+".sortField=='"+c.getId()+"'}", Boolean.class);
orderUp.setValueExpression("rendered", ren2);
HtmlOutputText orderDown = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
orderDown.setId(viewRoot.createUniqueId());
orderDown.setEscape(false);
orderDown.setValue("&#x2193;"); //
ValueExpression ren3 = application.getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{"+entrySupportVar+".sortOrder==false and "+entrySupportVar+".sortField=='"+c.getId()+"'}", Boolean.class);
orderDown.setValueExpression("rendered", ren3);
link.getChildren().add(out2);
link.getChildren().add(orderUp);
link.getChildren().add(orderDown);
col.setHeader(link);
HtmlOutputText out = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
out.setId(viewRoot.createUniqueId());
int index = VascDataBackendBean.getIndexId(c);
ValueExpression ve1 = application.getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(),"#{"+tableRecordVar+".field"+index+"}",Object.class);
out.setValueExpression("value", ve1);
col.getChildren().add(out);
table.getChildren().add(col);
}
if (entry.getVascFrontendData().getVascBackend().isRecordMoveable()) {
UIColumn colUp = (UIColumn)application.createComponent(UIColumn.COMPONENT_TYPE);
colUp.setId(viewRoot.createUniqueId());
HtmlCommandLink linkUp = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE);
linkUp.setId(viewRoot.createUniqueId());
linkUp.setType("up");
//linkUp.addActionListener(new MoveActionListener());
HtmlOutputText orderUp = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
orderUp.setId(viewRoot.createUniqueId());
orderUp.setEscape(false);
orderUp.setValue("&#x2191;&nbsp;up"); //
linkUp.getChildren().add(orderUp);
colUp.getChildren().add(linkUp);
table.getChildren().add(colUp);
HtmlCommandLink linkDown = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE);
linkDown.setId(viewRoot.createUniqueId());
linkDown.setType("down");
//linkDown.addActionListener(new MoveActionListener());
UIColumn colDown = (UIColumn)application.createComponent(UIColumn.COMPONENT_TYPE);
colDown.setId(viewRoot.createUniqueId());
HtmlOutputText orderDown = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
orderDown.setId(viewRoot.createUniqueId());
orderDown.setEscape(false);
orderDown.setValue("&#x2193;&nbsp;down"); //
linkDown.getChildren().add(orderDown);
colDown.getChildren().add(linkDown);
table.getChildren().add(colDown);
}
for (VascLinkEntry vascLink:entry.getVascLinkEntries()) {
UIColumn col = (UIColumn)application.createComponent(UIColumn.COMPONENT_TYPE);
col.setId(viewRoot.createUniqueId());
UIOutput colHeader = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE);
colHeader.setId(viewRoot.createUniqueId());
colHeader.setValue("link");
col.setHeader(colHeader);
HtmlCommandLink link = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE);
link.setId(viewRoot.createUniqueId());
link.setType(vascLink.getId());
MethodExpression actionExpression = getMethodExpression("#{"+entrySupportVar+".linkAction}");
MethodExpressionActionListener meActionListener = new MethodExpressionActionListener(actionExpression);
link.addActionListener(meActionListener);
// rm this , bacause of unneeded copy, should add name to link
VascEntry ve = entry.getVascFrontendData().getVascController().getVascEntryControllerResolver().getVascEntryController().getVascEntryById(vascLink.getVascEntryId());
HtmlOutputText out = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
out.setId(viewRoot.createUniqueId());
out.setValue(i18n(entry,ve.getName()));
link.getChildren().add(out);
col.getChildren().add(link);
table.getChildren().add(col);
}
for (RowVascAction action:entry.getRowActions()) {
if (entry.getVascFrontendData().getVascFrontendHelper().renderRowVascAction(action)==false) {
continue;
}
if (AddRowAction.ACTION_ID.equals(action.getId())) {
continue;
}
UIColumn col = (UIColumn)application.createComponent(UIColumn.COMPONENT_TYPE);
col.setId(viewRoot.createUniqueId());
UIOutput colHeader = (UIOutput)application.createComponent(UIOutput.COMPONENT_TYPE);
colHeader.setId(viewRoot.createUniqueId());
colHeader.setValue(i18n(entry,action.getName()));
col.setHeader(colHeader);
HtmlCommandLink link = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE);
link.setId(viewRoot.createUniqueId());
link.setType(action.getId());
//link.setImmediate(true);
MethodExpression actionExpression = getMethodExpression("#{"+entrySupportVar+".rowAction}");
MethodExpressionActionListener meActionListener = new MethodExpressionActionListener(actionExpression);
link.addActionListener(meActionListener);
HtmlOutputText out = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
out.setId(viewRoot.createUniqueId());
out.setValue(i18n(entry,action.getName()));
link.getChildren().add(out);
col.getChildren().add(link);
table.getChildren().add(col);
}
}
private MethodExpression getMethodExpression(String name) {
Class<?>[] 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);
}
}

View file

@ -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;
}
}

View file

@ -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);
}
}
}

View file

@ -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("<h1>"+i18n(entry.getName())+"</h1>");
title.setEscape(false);
panelDelete.getChildren().add(title);
HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
br.setId(viewRoot.createUniqueId());
br.setValue("<br/><br/>");
br.setEscape(false);
panelDelete.getChildren().add(br);
//HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
//br.setId(viewRoot.createUniqueId());
//br.setValue("<br/><br/>");
//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/>");
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("<h1>"+i18n(entry.getName())+"</h1>");
title.setEscape(false);
panelEdit.getChildren().add(title);
HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
br.setId(viewRoot.createUniqueId());
br.setValue("<br/><br/>");
br.setEscape(false);
panelEdit.getChildren().add(br);
//HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
//br.setId(viewRoot.createUniqueId());
//br.setValue("<br/><br/>");
//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/>");
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("<h1>"+i18n(entry.getName())+"</h1>");
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("<h1>"+i18n(entry.getName())+"</h1>");
title.setEscape(false);
panelView.getChildren().add(title);
HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
br.setId(viewRoot.createUniqueId());
br.setValue("<br/><br/>");
br.setEscape(false);
panelView.getChildren().add(br);
//HtmlOutputText br = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
//br.setId(viewRoot.createUniqueId());
//br.setValue("<br/><br/>");
//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/><br/>");
br.setEscape(false);
panelView.getChildren().add(br);
HtmlOutputText tabHeader = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
tabHeader.setId(viewRoot.createUniqueId());
tabHeader.setValue("<ul class=\"actionboxtab\"><li><a class=\"active\">Zoekopties</a></li></ul>");
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<option.getVascEntryFieldType().getUIComponentCount(option);i++) {
HtmlPanelGroup listOptionGroup = (HtmlPanelGroup)application.createComponent(HtmlPanelGroup.COMPONENT_TYPE);
listOptionGroup.setId(viewRoot.createUniqueId());
gridOption.getChildren().add(listOptionGroup);
options.getChildren().add(listOptionGroup);
com.idcanet.vasc.core.ui.VascUIComponent label = option.getVascEntryFieldType().provideLabelUIComponent(i,option);
VascValueModel model = new VascValueModel();
@ -1214,13 +1225,13 @@ public class VascUIComponent extends UIComponentBase {
entry.getVascFrontendData().getVascFrontendHelper().headerOptionsCreatedFillData(entry);
HtmlPanelGroup gridOptionGroup = (HtmlPanelGroup)application.createComponent(HtmlPanelGroup.COMPONENT_TYPE);
gridOptionGroup.setId(viewRoot.createUniqueId());
gridOption.getChildren().add(gridOptionGroup);
HtmlPanelGroup gridOptionGroup = options; //(HtmlPanelGroup)application.createComponent(HtmlPanelGroup.COMPONENT_TYPE);
//gridOptionGroup.setId(viewRoot.createUniqueId());
//gridOption.getChildren().add(gridOptionGroup);
HtmlOutputText searchText = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
searchText.setId(viewRoot.createUniqueId());
searchText.setValue("Search: ");
searchText.setValue("Zoek: ");
gridOptionGroup.getChildren().add(searchText);
HtmlInputText searchInput = (HtmlInputText)application.createComponent(HtmlInputText.COMPONENT_TYPE);
@ -1230,10 +1241,17 @@ public class VascUIComponent extends UIComponentBase {
ValueExpression ve3 = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{vascActionBean.searchString}", String.class);
searchInput.setValueExpression("value", ve3);
gridOptionGroup.getChildren().add(searchInput);
HtmlCommandButton search = (HtmlCommandButton)application.createComponent(HtmlCommandButton.COMPONENT_TYPE);
search.setId(viewRoot.createUniqueId());
search.addActionListener(new SearchActionListener());
search.setValue("Zoeken");
gridOptionGroup.getChildren().add(search);
HtmlOutputText gridHeaderText2 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
gridHeaderText2.setId(viewRoot.createUniqueId());
gridHeaderText2.setValue("Results "); // Results 101 - 200 of 217 rows
gridHeaderText2.setValue("Resultaten "); // Results 101 - 200 of 217 rows
panelView.getChildren().add(gridHeaderText2);
HtmlOutputText gridHeaderText3 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
@ -1244,7 +1262,7 @@ public class VascUIComponent extends UIComponentBase {
HtmlOutputText gridHeaderText4 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
gridHeaderText4.setId(viewRoot.createUniqueId());
gridHeaderText4.setValue(" of ");
gridHeaderText4.setValue(" van ");
panelView.getChildren().add(gridHeaderText4);
HtmlOutputText gridHeaderText5 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
@ -1255,7 +1273,7 @@ public class VascUIComponent extends UIComponentBase {
HtmlOutputText gridHeaderText6 = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
gridHeaderText6.setId(viewRoot.createUniqueId());
gridHeaderText6.setValue(" total rows.");
gridHeaderText6.setValue(" rijen.");
panelView.getChildren().add(gridHeaderText6);
if (entryNameOldId!=null) {
@ -1291,7 +1309,7 @@ public class VascUIComponent extends UIComponentBase {
HtmlOutputText gotoText = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE);
gotoText.setId(viewRoot.createUniqueId());
gotoText.setValue("Goto page: ");
gotoText.setValue("Ga naar pagina: ");
gotoGroup.getChildren().add(gotoText);
HtmlDataList table = (HtmlDataList)application.createComponent(HtmlDataList.COMPONENT_TYPE);
@ -1396,9 +1414,10 @@ public class VascUIComponent extends UIComponentBase {
HtmlDataTable table = (HtmlDataTable)application.createComponent(HtmlDataTable.COMPONENT_TYPE);
table.setVar("vascRecord");
table.setId(viewRoot.createUniqueId());
table.setWidth("90%");
table.setRowClasses("style_tableRowType1,style_tableRowType2");
table.setHeaderClass("style_tableHeader1");
//table.setWidth("90%");
table.setStyleClass("utr");
table.setRowClasses("row, row2");
//table.setHeaderClass("style_tableHeader1");
table.setValue(tableDataModel);
panelView.getChildren().add(table);
@ -1588,7 +1607,7 @@ class JSFFrontendRenderer extends AbstractVascFrontend implements Serializable {
*/
public void renderDelete() throws Exception {
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
VascUIComponent comp = VascUIComponent.findVascChild(viewRoot,getVascEntry().getId());
OldVascUIComponent comp = OldVascUIComponent.findVascChild(viewRoot,getVascEntry().getId());
comp.resetViews();
UIPanel panel = comp.getPanel("deleteId");
panel.setRendered(true);
@ -1599,7 +1618,7 @@ class JSFFrontendRenderer extends AbstractVascFrontend implements Serializable {
*/
public void renderEdit() throws Exception {
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
VascUIComponent comp = VascUIComponent.findVascChild(viewRoot,getVascEntry().getId());
OldVascUIComponent comp = OldVascUIComponent.findVascChild(viewRoot,getVascEntry().getId());
comp.resetViews();
UIPanel panel = comp.getPanel("editId");
panel.setRendered(true);
@ -1624,7 +1643,7 @@ class JSFFrontendRenderer extends AbstractVascFrontend implements Serializable {
*/
public void renderExport(VascEntryExporter exporter) throws Exception {
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
VascUIComponent comp = VascUIComponent.findVascChild(viewRoot,getVascEntry().getId());
OldVascUIComponent comp = OldVascUIComponent.findVascChild(viewRoot,getVascEntry().getId());
comp.resetViews();
UIPanel panel = comp.getPanel("exportId");
panel.setRendered(true);
@ -1637,17 +1656,10 @@ class JSFFrontendRenderer extends AbstractVascFrontend implements Serializable {
*/
public void renderView() throws Exception {
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
VascUIComponent comp = VascUIComponent.findVascChild(viewRoot,getVascEntry().getId());
OldVascUIComponent comp = OldVascUIComponent.findVascChild(viewRoot,getVascEntry().getId());
comp.resetViews();
UIPanel panel = comp.getPanel("viewId");
panel.setRendered(true);
// 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());
}
}
@ -1658,7 +1670,7 @@ class VascGlobalActionListener implements ActionListener,Serializable {
this.actionId=actionId;
}
public void processAction(ActionEvent event) {
VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent());
OldVascUIComponent comp = OldVascUIComponent.findVascParent(event.getComponent());
VascEntry entry = comp.getVascEntry();
GlobalVascAction action = entry.getGlobalActionById(actionId);
try {
@ -1676,7 +1688,7 @@ class VascRowActionListener implements ActionListener,Serializable {
this.actionId=actionId;
}
public void processAction(ActionEvent event) {
VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent());
OldVascUIComponent comp = OldVascUIComponent.findVascParent(event.getComponent());
VascEntry entry = comp.getVascEntry();
RowVascAction action = entry.getRowActionById(actionId);
Object selected = null;
@ -1697,7 +1709,7 @@ class VascLinkActionListener implements ActionListener,Serializable {
this.linkId=linkId;
}
public void processAction(ActionEvent event) {
VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent());
OldVascUIComponent comp = OldVascUIComponent.findVascParent(event.getComponent());
VascEntry entry = comp.getVascEntry();
VascLinkEntry l = entry.getVascLinkEntryById(linkId);
comp.initGoto(l);
@ -1706,7 +1718,7 @@ class VascLinkActionListener implements ActionListener,Serializable {
@SuppressWarnings("serial")
class VascLinkBackActionListener implements ActionListener,Serializable {
public void processAction(ActionEvent event) {
VascUIComponent comp = VascUIComponent.findVascParent(event.getComponent());
OldVascUIComponent comp = OldVascUIComponent.findVascParent(event.getComponent());
comp.initGoto(null);
}
}

View file

@ -1,54 +0,0 @@
/**
*
*/
package com.idcanet.vasc.frontends.web.jsf;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* @author willemc
*
*/
public class VascActionBean implements Serializable {
private String searchString = null;
private Map<String,Object> values = new HashMap<String,Object>(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<String, Object> 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;
}
}

View file

@ -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;
}
/**

View file

@ -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;
}
}

View file

@ -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();
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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()) {

View file

@ -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());

View file

@ -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);
}

View file

@ -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);

View file

@ -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<Object> data = null;
private String dataSearchString = null;
private Map<String,Object> dataState = null;
public VascBackendProxyPaged(VascBackend backend,VascEntry entry) {
super(backend);
dataState = new HashMap<String,Object>(10);
}
/**
@ -63,7 +69,34 @@ public class VascBackendProxyPaged extends AbstractVascBackendProxy {
*/
@Override
public List<Object> execute(VascBackendState state) throws VascException {
List<Object> 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<Object> allData = data;
int pageSize = state.getPageSize();
if (pageSize==0) {
records = allData.size();

View file

@ -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;
}
}

View file

@ -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<pages;page++) {
entry.getVascFrontendData().getVascBackendState().setPageIndex(page);
entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry);
for (Object o:entry.getVascFrontendData().getEntryDataList()) {
for (VascEntryField c:entry.getVascEntryFields()) {
p.write(c.getVascEntryFieldValue().getDisplayValue(c, o)+"\t");
}
p.write("\n");
p.flush();
}
p.write("\n");
p.flush();
}
p.write("# end\n");
p.flush();
// restore old page size
entry.getVascFrontendData().getVascBackendState().setPageIndex(oldIndex);
}
public String getMineType() {

View file

@ -58,18 +58,29 @@ public class XMLExportGlobalAction extends AbstractVascAction implements GlobalV
PrintWriter p = new PrintWriter(out);
p.write("<?xml version=\"1.0\"?>\n");
p.write("<data>\n");
for (Object o:entry.getVascFrontendData().getEntryDataList()) {
p.write("\t<row>\n");
for (VascEntryField c:entry.getVascEntryFields()) {
p.write("\t\t<column name=\""+c.getId()+"\"><![CDATA[");
p.write(""+c.getVascEntryFieldValue().getDisplayValue(c, o));
p.write("]]></column>\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<pages;page++) {
entry.getVascFrontendData().getVascBackendState().setPageIndex(page);
entry.getVascFrontendData().getVascFrontendHelper().refreshData(entry);
for (Object o:entry.getVascFrontendData().getEntryDataList()) {
p.write("\t<row>\n");
for (VascEntryField c:entry.getVascEntryFields()) {
p.write("\t\t<column name=\""+c.getId()+"\"><![CDATA[");
p.write(""+c.getVascEntryFieldValue().getDisplayValue(c, o));
p.write("]]></column>\n");
}
p.write("\t</row>\n");
p.flush();
}
p.write("\t</row>\n");
p.flush();
}
p.write("</data>\n");
p.flush();
// restore old page size
entry.getVascFrontendData().getVascBackendState().setPageIndex(oldIndex);
}
public String getMineType() {

View file

@ -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);
}

View file

@ -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) {

View file

@ -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) {

View file

@ -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");

View file

@ -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");

View file

@ -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;

View file

@ -1,17 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<!-- The New -->
<component>
<component-type>com.idcanet.vasc.frontends.web.jsf.VascUIComponent</component-type>
<component-class>com.idcanet.vasc.frontends.web.jsf.VascUIComponent</component-class>
<description><![CDATA[Renders a templated vasc entry]]></description>
<display-name>Vasc JSF Component</display-name>
<component-type>vasc.jsf.component</component-type>
<component-class>com.idcanet.vasc.frontends.web.jsf.JSFVascUIComponent</component-class>
<component-extension>
<renderer-type>vasc.jsf.component.renderer</renderer-type>
</component-extension>
</component>
<managed-bean>
<description>Controls the vasc actions</description>
<managed-bean-name>vascActionBean</managed-bean-name>
<managed-bean-class>com.idcanet.vasc.frontends.web.jsf.VascActionBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<render-kit>
<renderer>
<component-family>vasc.jsf.component.family</component-family>
<renderer-type>vasc.jsf.component.renderer</renderer-type>
<renderer-class>com.idcanet.vasc.frontends.web.jsf.JSFVascUIComponentRenderer</renderer-class>
</renderer>
</render-kit>
<application>
<locale-config/>
<view-handler>com.idcanet.vasc.frontends.web.jsf.VascViewHandler</view-handler>

View file

@ -2,11 +2,11 @@
<eld:root xmlns:eld="http://x4o.idcanet.com/eld/eld-lang.eld">
<eld:elementClass tag="fieldType" objectClassName="com.idcanet.vasc.impl.type.DefaultVascEntryFieldType">
<eld:elementClassParameterConverter parameterName="autoDetectClass" bean.class="com.idcanet.x4o.impl.lang.ClassConverter"/>
<eld:elementClassAttributeConverter attributeName="autoDetectClass" bean.class="com.idcanet.x4o.impl.lang.ClassConverter"/>
</eld:elementClass>
<eld:elementClass tag="multiTextFieldType" objectClassName="com.idcanet.vasc.impl.type.MultiTextVascEntryFieldType">
<eld:elementClassParameterConverter parameterName="autoDetectClass" bean.class="com.idcanet.x4o.impl.lang.ClassConverter"/>
<eld:elementClassAttributeConverter attributeName="autoDetectClass" bean.class="com.idcanet.x4o.impl.lang.ClassConverter"/>
</eld:elementClass>
<eld:elementRefectionBindingHandler parentClass="com.idcanet.vasc.core.VascEntryFieldType"

View file

@ -4,5 +4,5 @@
<comment>
Vasc namespace for the fieldtype language
</comment>
<entry key="eld.http://vasc.idcanet.com/eld/fieldtype-lang.eld">META-INF/fieldtype-lang.eld</entry>
<entry key="eld.http://vasc.idcanet.com/eld/fieldtype-lang.eld">fieldtype-lang.eld</entry>
</properties>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>http://vasc.idcanet.com/vasc.tld</namespace>
<tag>
<tag-name>vascEntry</tag-name>
<component>
<component-type>vasc.jsf.component</component-type>
<renderer-type>vasc.jsf.component.renderer</renderer-type>
</component>
</tag>
</facelet-taglib>

View file

@ -1,44 +1,101 @@
<?xml version="1.0" encoding="UTF-8" ?>
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
<description>JSTL 1.1 core library</description>
<description>Vasc JSF 2.1 library</description>
<display-name>Vasc</display-name>
<tlib-version>1.1</tlib-version>
<tlib-version>2.1</tlib-version>
<short-name>vasc</short-name>
<uri>http://vasc.idcanet.com/vasc.tld</uri>
<tag>
<description>Renders the vasc entry JSF Frontend Renderer</description>
<name>vascEntry</name>
<tag-class>com.idcanet.vasc.frontends.web.jsf.VascUIComponentTag</tag-class>
<body-content>JSP</body-content>
<tag-class>com.idcanet.vasc.frontends.web.jsf.JSFVascUIComponentTag</tag-class>
<body-content>JSP</body-content>
<!-- standard UIComponent attributes -->
<attribute>
<name>id</name>
<required>false</required>
</attribute>
<attribute>
<name>rendered</name>
<required>false</required>
<deferred-value>
<type>boolean</type>
</deferred-value>
</attribute>
<attribute>
<name>binding</name>
<required>false</required>
<deferred-value>
<type>javax.faces.component.UIComponent</type>
</deferred-value>
</attribute>
<!-- custom attributes -->
<attribute>
<name>vascController</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<deferred-value/>
<deferred-value>
<type>com.idcanet.vasc.core.VascController</type>
</deferred-value>
</attribute>
<attribute>
<name>entryName</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<deferred-value/>
<deferred-value>
<type>java.lang.String</type>
</deferred-value>
</attribute>
<attribute>
<name>vascFrontendData</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<deferred-value/>
<deferred-value>
<type>com.idcanet.vasc.core.VascFrontendData</type>
</deferred-value>
</attribute>
<attribute>
<name>entrySupportVar</name>
<required>true</required>
<deferred-value>
<type>java.lang.String</type>
</deferred-value>
</attribute>
<attribute>
<name>tableRecordVar</name>
<required>true</required>
<deferred-value>
<type>java.lang.String</type>
</deferred-value>
</attribute>
<attribute>
<name>injectEditFieldsId</name>
<required>true</required>
<deferred-value>
<type>java.lang.String</type>
</deferred-value>
</attribute>
<attribute>
<name>injectTableOptionsId</name>
<required>true</required>
<deferred-value>
<type>java.lang.String</type>
</deferred-value>
</attribute>
<attribute>
<name>injectTableColumnsId</name>
<required>true</required>
<deferred-value>
<type>java.lang.String</type>
</deferred-value>
</attribute>
<attribute>
<name>bundleName</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
<deferred-value/>
</attribute>
<attribute>
<name>locale</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
<deferred-value/>
</attribute>
</tag>
</taglib>

View file

@ -19,7 +19,7 @@
<eld:elementConfigurator bean.class="com.idcanet.vasc.impl.x4o.VascEntryElementConfigurator" configAction="true"/>
</eld:elementClass>
<eld:elementClass tag="field" objectClassName="com.idcanet.vasc.impl.DefaultVascEntryField" elementClassName="com.idcanet.vasc.impl.x4o.VascEntryFieldElement">
<eld:elementClassParameterConverter parameterName="vascEntryFieldType" bean.class="com.idcanet.vasc.impl.x4o.VascEntryFieldTypeParameterConverter"/>
<eld:elementClassAttributeConverter attributeName="vascEntryFieldType" bean.class="com.idcanet.vasc.impl.x4o.VascEntryFieldTypeAttributeConverter"/>
</eld:elementClass>
<eld:elementClass tag="vascEntryFieldType" elementClassName="com.idcanet.vasc.impl.x4o.VascEntryFieldTypeElement"/>
@ -27,7 +27,7 @@
<eld:elementClass tag="fieldSet" objectClassName="com.idcanet.vasc.impl.DefaultVascEntryFieldSet">
<eld:elementClassParameterConverter parameterName="vascEntryFieldIds" bean.class="com.idcanet.vasc.impl.x4o.VascEntryFieldSetParameterConverter"/>
<eld:elementClassAttributeConverter attributeName="vascEntryFieldIds" bean.class="com.idcanet.vasc.impl.x4o.VascEntryFieldSetAttributeConverter"/>
</eld:elementClass>
<eld:elementClass tag="link" objectClassName="com.idcanet.vasc.impl.DefaultVascLinkEntry"/>
@ -35,7 +35,7 @@
<eld:elementClass tag="linkEntryCreateFieldValue" elementClassName="com.idcanet.vasc.impl.x4o.VascLinkEntryParameterElement"/>
<eld:elementClass tag="listOption" objectClassName="com.idcanet.vasc.impl.DefaultVascEntryField" elementClassName="com.idcanet.vasc.impl.x4o.VascEntryFieldElement">
<eld:elementClassParameterConverter parameterName="vascEntryFieldType" bean.class="com.idcanet.vasc.impl.x4o.VascEntryFieldTypeParameterConverter"/>
<eld:elementClassAttributeConverter attributeName="vascEntryFieldType" bean.class="com.idcanet.vasc.impl.x4o.VascEntryFieldTypeAttributeConverter"/>
</eld:elementClass>
@ -58,12 +58,12 @@
<eld:elementClass tag="xpqlPersistanceBackend" objectClassName="com.idcanet.vasc.backends.jpa.XpqlPersistanceVascBackend">
<eld:elementConfigurator bean.class="com.idcanet.vasc.impl.x4o.VascBackendElementConfigurator" configAction="true"/>
<eld:elementClassParameterConverter parameterName="resultClass" bean.class="com.idcanet.x4o.impl.lang.ClassConverter"/>
<eld:elementClassAttributeConverter attributeName="resultClass" bean.class="com.idcanet.x4o.impl.lang.ClassConverter"/>
</eld:elementClass>
<eld:elementClass tag="xpqlHibernateBackend" objectClassName="com.idcanet.vasc.backends.jpa.XpqlHibernateVascBackend">
<eld:elementConfigurator bean.class="com.idcanet.vasc.impl.x4o.VascBackendElementConfigurator" configAction="true"/>
<eld:elementClassParameterConverter parameterName="resultClass" bean.class="com.idcanet.x4o.impl.lang.ClassConverter"/>
<eld:elementClassAttributeConverter attributeName="resultClass" bean.class="com.idcanet.x4o.impl.lang.ClassConverter"/>
</eld:elementClass>

View file

@ -4,5 +4,5 @@
<comment>
Vasc namespace for the fieldtype language
</comment>
<entry key="eld.http://vasc.idcanet.com/eld/vasc-lang.eld">META-INF/vasc-lang.eld</entry>
<entry key="eld.http://vasc.idcanet.com/eld/vasc-lang.eld">vasc-lang.eld</entry>
</properties>

View file

@ -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;
}
}