You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2012/04/14 16:57:30 UTC
svn commit: r1326123 [3/4] - in /empire-db/trunk/empire-db-jsf2/src: ./
main/ main/java/ main/java/org/ main/java/org/apache/
main/java/org/apache/empire/ main/java/org/apache/empire/jsf2/
main/java/org/apache/empire/jsf2/app/ main/java/org/apache/empi...
Added: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java?rev=1326123&view=auto
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java (added)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java Sat Apr 14 14:57:28 2012
@@ -0,0 +1,591 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.pageelements;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.faces.event.ValueChangeEvent;
+
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.empire.commons.ObjectUtils;
+import org.apache.empire.commons.StringUtils;
+import org.apache.empire.data.Column;
+import org.apache.empire.data.DataType;
+import org.apache.empire.db.DBColumn;
+import org.apache.empire.db.DBColumnExpr;
+import org.apache.empire.db.DBCommand;
+import org.apache.empire.db.DBReader;
+import org.apache.empire.db.DBRecordData;
+import org.apache.empire.db.DBRowSet;
+import org.apache.empire.db.expr.order.DBOrderByExpr;
+import org.apache.empire.exceptions.InvalidArgumentException;
+import org.apache.empire.exceptions.NotSupportedException;
+import org.apache.empire.exceptions.ObjectNotValidException;
+import org.apache.empire.exceptions.UnexpectedReturnValueException;
+import org.apache.empire.jsf2.app.FacesUtils;
+import org.apache.empire.jsf2.pages.Page;
+import org.apache.empire.jsf2.utils.ListColumnFinder;
+import org.apache.empire.jsf2.utils.ListItemSelection;
+import org.apache.empire.jsf2.utils.ParameterMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BeanListPageElement<T> extends ListPageElement<T> implements ListItemSelection
+{
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger log = LoggerFactory.getLogger(BeanListPageElement.class);
+
+ public static final String IDPARAM_PROPERTY = "idParam";
+
+ public static final String NO_RESULT_ATTRIBUTE = "noQueryResult";
+
+ private ListTableInfo listTableInfo = null;
+
+ protected DBRowSet rowset;
+
+ protected Column defaultSortColumn;
+
+ protected boolean defaultSortAscending = true;
+
+ protected DBOrderByExpr secondarySortOrder = null;
+
+ /**
+ * Extended ListTableInfo
+ */
+ public static class BeanListTableInfo extends ListTableInfo
+ {
+ private static final long serialVersionUID = 1L;
+
+ private DBCommand queryCmd = null;
+
+ public DBCommand getQueryCmd()
+ {
+ return queryCmd;
+ }
+
+ public void setQueryCmd(DBCommand queryCmd)
+ {
+ this.queryCmd = queryCmd;
+ }
+ }
+
+ public BeanListPageElement(Page page, Class<T> beanClass, DBColumn defaultSortColumn, String propertyName, boolean test)
+ {
+ super(page, beanClass, propertyName);
+ // Check
+ if (defaultSortColumn == null)
+ throw new InvalidArgumentException("defaultSortColumn", defaultSortColumn);
+ // Set Bean Class and more
+ this.rowset = defaultSortColumn.getRowSet();
+ this.defaultSortColumn = defaultSortColumn;
+ // Default Sort Order
+ if (defaultSortColumn.getDataType() == DataType.DATE || defaultSortColumn.getDataType() == DataType.DATETIME)
+ { // Date sort order is descending by default
+ defaultSortAscending = false;
+ }
+ }
+
+ @Override
+ protected void onInitPage()
+ {
+ ListTableInfo lti = getTableInfo();
+ if (lti.isValid() && items == null)
+ { // loadBookings
+ loadItems(true);
+ }
+ }
+
+ @Override
+ protected void onRefreshPage()
+ {
+ ListTableInfo lti = getTableInfo();
+ if (lti.isValid() && lti.isModified())
+ { // load
+ loadItems(false);
+ }
+ else
+ { // hide the loading indicator on client (JavaScript call)
+ if (lti.isAllowPagination())
+ updateScrollbar();
+ }
+ }
+
+ @Override
+ public int getItemCount()
+ {
+ return getTableInfo().getItemCount();
+ }
+
+ public Column getDefaultSortColumn()
+ {
+ return defaultSortColumn;
+ }
+
+ public boolean isDefaultSortAscending()
+ {
+ return defaultSortAscending;
+ }
+
+ public void setDefaultSortAscending(boolean defaultSortAscending)
+ {
+ this.defaultSortAscending = defaultSortAscending;
+ }
+
+ public DBOrderByExpr getSecondarySortOrder()
+ {
+ return secondarySortOrder;
+ }
+
+ public void setSecondarySortOrder(DBOrderByExpr secondarySortOrder)
+ {
+ this.secondarySortOrder = secondarySortOrder;
+ }
+
+ /** session scoped properties **/
+ @Override
+ public ListTableInfo getTableInfo()
+ {
+ // Lazy initialization
+ if ((listTableInfo == null) && (listTableInfo = getSessionObject(ListTableInfo.class)) == null)
+ { // Create and put on session
+ listTableInfo = new BeanListTableInfo();
+ listTableInfo.setSortColumnName(defaultSortColumn.getName());
+ listTableInfo.setSortAscending(defaultSortAscending);
+ setSessionObject(ListTableInfo.class, listTableInfo);
+ }
+ return listTableInfo;
+ }
+
+ @Override
+ public void clearItems()
+ { // clear Items
+ super.clearItems();
+ setSessionObject(ListTableInfo.class, null);
+ listTableInfo = null;
+ // Clear parameters
+ getParameterMap().clear(rowset);
+ }
+
+ protected ParameterMap getParameterMap()
+ {
+ return FacesUtils.getParameterMap(FacesUtils.getContext());
+ }
+
+ /**
+ * Init list items with pagination
+ *
+ * @param queryCmd
+ * @param pageSize
+ */
+ public void initItems(DBCommand queryCmd, DBCommand countCmd, int pageSize)
+ {
+ clearItems();
+ // Init List Table Info
+ BeanListTableInfo lti = (BeanListTableInfo) getTableInfo();
+ lti.setQueryCmd(queryCmd);
+ if (pageSize > 0)
+ { // Negative count means: loadItems should load all items.
+ countCmd.clearSelect();
+ countCmd.select(rowset.count());
+ int count = rowset.getDatabase().querySingleInt(countCmd.getSelect(), countCmd.getParamValues(), 0, getConnection(rowset));
+ lti.init(count, pageSize);
+ }
+ else
+ { // 0 or more items available
+ lti.init(-1, 0);
+ }
+ // Init List table Info
+ lti.setSortOrderChanged(true);
+ loadItems(true);
+ // log
+ int count = getTableInfo().getItemCount();
+ if (count==0)
+ FacesUtils.setRequestAttribute(FacesUtils.getContext(), NO_RESULT_ATTRIBUTE, true);
+ // log
+ log.info("ItemList initialized for {} item count is {}.", getPropertyName(), count);
+ }
+
+ /**
+ * Init list items without pagination
+ *
+ * @param queryCmd
+ */
+ public final void initItems(DBCommand queryCmd, int pageSize)
+ {
+ DBCommand countCmd = queryCmd.clone();
+ initItems(queryCmd, countCmd, 0);
+ }
+
+ /**
+ * Init list items without pagination
+ *
+ * @param queryCmd
+ */
+ public final void initItems(DBCommand queryCmd)
+ {
+ initItems(queryCmd, 0);
+ }
+
+ /**
+ * Returns true if (and only if) items are valid but empty
+ * @return
+ */
+ public boolean isResultEmpty()
+ {
+ Object noQueryResult = FacesUtils.getRequestAttribute(FacesUtils.getContext(), NO_RESULT_ATTRIBUTE);
+ return (noQueryResult!=null) ? ObjectUtils.getBoolean( noQueryResult ) : false;
+ }
+
+ private void loadItems(boolean initScrollbar)
+ {
+ // DBReader
+ BeanListTableInfo lti = (BeanListTableInfo) getTableInfo();
+ DBReader r = new DBReader();
+ try
+ { // Check command
+ DBCommand queryCmd = lti.getQueryCmd();
+ if (queryCmd == null)
+ throw new ObjectNotValidException(this);
+
+ boolean loadPageFromPosition = lti.isValid() && lti.isAllowPagination();
+ lti.setValid(false);
+
+ if (lti.isSortOrderChanged())
+ { // Set Sort order
+ setOrderBy(queryCmd);
+ lti.setSortOrderChanged(false);
+ }
+
+ // DBReader.open immer nur innerhalb eines try {} finally {} blocks!
+ r.open(queryCmd, getConnection(queryCmd));
+
+ // get position from the session
+ int position = 0;
+ int maxItems = 1000;
+ if (loadPageFromPosition)
+ {
+ position = lti.getPosition();
+ if (position < 0)
+ { // position < 0 is not possible, set to 0
+ position = 0;
+ }
+ if (position > lti.getItemCount() - lti.getPageSize())
+ { // position > count of entries is not possible, set to max
+ position = lti.getItemCount() - lti.getPageSize();
+ }
+ if (position > 0)
+ { // we are not at position 0, "skipping" entries
+ r.skipRows(position);
+ }
+ else
+ position = 0;
+ // maxItems
+ maxItems = lti.getPageSize();
+ }
+
+ // Read all Items
+ items = r.getBeanList(beanClass, maxItems);
+ if (items == null)
+ throw new UnexpectedReturnValueException(items, "DBReader.getBeanList");
+ generateIdParams(rowset, items);
+ assignSelectionMap(items);
+
+ // set position at session object
+ if (loadPageFromPosition)
+ { // set valid
+ if (position + items.size() > lti.getItemCount())
+ { // Oops: More items than expected.
+ log.warn("Item count of {} has changed. Adjusting item count.", getPropertyName());
+ lti.init(position + items.size(), lti.getPageSize());
+ }
+ lti.setPosition(position);
+ lti.setModified(false);
+ lti.setValid(true);
+ }
+ else
+ { // Init the list
+ lti.init(items.size(), 0);
+ }
+ }
+ catch (RuntimeException e)
+ {
+ log.error("Error loading bean list " + e.getMessage(), e);
+ throw e;
+ }
+ finally
+ {
+ r.close();
+ // Pagination
+ if (lti.isAllowPagination())
+ { // Scrollbar
+ if (initScrollbar)
+ initScrollbar();
+ else
+ updateScrollbar();
+ }
+ }
+ }
+
+ /**
+ * set order by for db queries
+ *
+ * @param cmd
+ */
+ protected void setOrderBy(DBCommand cmd)
+ {
+ cmd.clearOrderBy();
+ String sortColumnName = getTableInfo().getSortColumnName();
+ boolean sortAscending = getTableInfo().getSortAscending();
+
+ // Find Column
+ DBColumnExpr sortColumn = rowset.getColumn(sortColumnName);
+ if (sortColumn == null && (getPage() instanceof ListColumnFinder))
+ { // Ask Page
+ sortColumn = ((ListColumnFinder)getPage()).findColumn(sortColumnName);
+ }
+ if (sortColumn == null)
+ {
+ log.error("Invalid Sort Column {}. Using Default!", sortColumnName);
+ sortColumn = (DBColumn) getDefaultSortColumn();
+ getTableInfo().setSortColumnName(sortColumn.getName());
+ }
+ // set Order
+ setOrderBy(cmd, sortColumn, sortAscending);
+ }
+
+ protected void setOrderBy(DBCommand cmd, DBColumnExpr sortColumn, boolean sortAscending)
+ {
+ // Sort now
+ if (sortAscending)
+ {
+ cmd.orderBy(sortColumn);
+ }
+ else
+ {
+ cmd.orderBy(sortColumn.desc());
+ }
+ // Secondary sort
+ if (this.secondarySortOrder != null && !secondarySortOrder.getColumn().equals(sortColumn))
+ {
+ cmd.orderBy(secondarySortOrder);
+ }
+ }
+
+ /* Scrollbar relacted functions */
+
+ /**
+ * addJavascriptCall to initScrollbar
+ */
+ public void initScrollbar()
+ {
+ ListTableInfo lti = getTableInfo();
+ // init Scrollbar on page
+ int max = lti.getItemCount() - lti.getPageSize();
+ if (max < 0)
+ max = 0;
+ int pos = max;
+ if (max > lti.getPosition())
+ pos = max - lti.getPosition();
+ // init now
+ StringBuilder b = new StringBuilder();
+ b.append("initScrollbar('");
+ b.append(String.valueOf(getPropertyName()));
+ b.append("',");
+ b.append(String.valueOf(max));
+ b.append(",");
+ b.append(String.valueOf(pos));
+ b.append(",");
+ b.append(String.valueOf(lti.getPageSize()));
+ b.append(");");
+ getPage().addJavascriptCall(b.toString());
+ }
+
+ /**
+ * addJavascriptCall to updateScrollbar
+ */
+ public void updateScrollbar()
+ {
+ int pos = getScrollbarPosition();
+ StringBuilder b = new StringBuilder();
+ b.append("updateScrollbar('");
+ b.append(String.valueOf(getPropertyName()));
+ b.append("',");
+ b.append(String.valueOf(pos));
+ b.append(");");
+ getPage().addJavascriptCall(b.toString());
+ }
+
+ public int getScrollbarPosition()
+ {
+ ListTableInfo lti = getTableInfo();
+ if (!lti.isValid())
+ return 0;
+ if (lti.getItemCount() <= lti.getPageSize())
+ return 0;
+ int pos = lti.getItemCount() - lti.getPageSize() - lti.getPosition();
+ return (pos >= 0 ? pos : 0);
+ }
+
+ public void setScrollbarPosition(int value)
+ {
+ // should never come here!
+ }
+
+ public void positionValueChanged(ValueChangeEvent ve)
+ {
+ ListTableInfo lti = getTableInfo();
+ int val = ObjectUtils.getInteger(ve.getNewValue());
+ int pos = lti.getItemCount() - lti.getPageSize() - val;
+ lti.setPosition((pos > 0 ? pos : 0));
+ }
+
+ @Override
+ public Set<Object[]> getSelectedItems()
+ {
+ if (selectedItems == null)
+ return null;
+ // Get the set
+ Set<Object[]> items = new HashSet<Object[]>(selectedItems.size());
+ for (String idParam : selectedItems)
+ {
+ Object[] key = getParameterMap().get(rowset, idParam);
+ if (key == null)
+ {
+ log.warn("Object does not exist in ParameterMap!");
+ continue;
+ }
+ items.add(key);
+ }
+ return items;
+ }
+
+ public void setSelectedItems(Set<Object[]> items)
+ {
+ if (selectedItems == null)
+ throw new NotSupportedException(this, "setSelectedItems");
+ // Get the set
+ selectedItems = new SelectionSet(items.size());
+ for (Object[] key : items)
+ {
+ if (key == null || key.length == 0)
+ {
+ log.warn("Cannot select Null-Object.");
+ continue;
+ }
+ String idParam = getParameterMap().put(rowset, key);
+ selectedItems.add(idParam);
+ }
+ }
+
+ protected void generateIdParams(DBRowSet rowset, List<?> items)
+ {
+ DBColumn[] keyCols = rowset.getKeyColumns();
+ if (keyCols == null)
+ throw new RuntimeException("No Primary Key");
+ // generate all
+ for (Object item : items)
+ {
+ Object[] key = getItemKey(keyCols, item);
+ String idparam = getParameterMap().put(rowset, key);
+ try
+ {
+ BeanUtils.setProperty(item, IDPARAM_PROPERTY, idparam);
+ }
+ catch (Exception e)
+ {
+ String msg = "Error setting property idparam on bean.";
+ log.error(msg, e);
+ throw new RuntimeException(msg, e);
+ }
+ }
+ }
+
+ protected Object[] getItemKey(DBColumn[] cols, Object item)
+ {
+ Object[] key = new Object[cols.length];
+ for (int i = 0; i < cols.length; i++)
+ {
+ if (item instanceof DBRecordData)
+ {
+ key[i] = ((DBRecordData) item).getValue(cols[i]);
+ }
+ else
+ { // Bean Property Name
+ String propName = cols[i].getBeanPropertyName();
+ if (propName == null || propName.length() == 0)
+ throw new RuntimeException("Invalid Bean Property Name");
+ // Get Property value
+ try
+ {
+ key[i] = BeanUtils.getSimpleProperty(item, propName);
+ }
+ catch (Exception e)
+ {
+ String msg = "Error getting property '" + propName + "' from bean.";
+ log.error(msg, e);
+ throw new RuntimeException(msg, e);
+ }
+ }
+ }
+ return key;
+ }
+
+ @Override
+ public DBCommand getItemQueryCmd()
+ {
+ BeanListTableInfo lti = (BeanListTableInfo) getTableInfo();
+ DBCommand cmd = lti.getQueryCmd().clone();
+
+
+
+ Set<Object[]> items = getSelectedItems();
+
+ if (items.size()>0)
+ {
+ DBColumn[] pk = rowset.getKeyColumns();
+ DBColumnExpr keyExpr = pk[0];
+
+ for (int i=1; i<pk.length; i++)
+ {
+ keyExpr = keyExpr.append(pk[i]);
+ }
+
+ String[] keys = new String[items.size()];
+ int i = 0;
+
+ for (Object[] item : items)
+ {
+ keys[i++] = StringUtils.arrayToString(item, "");
+ }
+ if (isInvertSelection())
+ cmd.where(keyExpr.notIn(keys));
+ else
+ cmd.where(keyExpr.in(keys));
+ }
+ // clear previous settings without the where causes
+ cmd.clearSelect();
+ cmd.clearGroupBy();
+ cmd.clearOrderBy();
+ return cmd;
+ }
+
+}
Propchange: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/ListPageElement.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/ListPageElement.java?rev=1326123&view=auto
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/ListPageElement.java (added)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/ListPageElement.java Sat Apr 14 14:57:28 2012
@@ -0,0 +1,471 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.pageelements;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.faces.event.ActionEvent;
+
+import org.apache.empire.commons.ObjectUtils;
+import org.apache.empire.exceptions.NotSupportedException;
+import org.apache.empire.exceptions.ObjectNotValidException;
+import org.apache.empire.jsf2.pages.Page;
+import org.apache.empire.jsf2.pages.PageElement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class ListPageElement<T> extends PageElement
+{
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger log = LoggerFactory.getLogger(ListPageElement.class);
+
+ protected Class<T> beanClass;
+
+ protected List<T> items = null;
+
+ protected SelectionSet selectedItems = null;
+
+ public static class SelectionSet extends HashSet<String>
+ {
+ private static final long serialVersionUID = 1L;
+
+ private boolean invertSelection = false;
+
+ public SelectionSet()
+ {
+ super();
+ }
+
+ public SelectionSet(int size)
+ {
+ super(size);
+ }
+
+ public boolean isInvertSelection()
+ {
+ return invertSelection;
+ }
+
+ public void setInvertSelection(boolean invertSelection)
+ {
+ if (this.invertSelection==invertSelection)
+ return; // no change
+ // invert
+ this.invertSelection = invertSelection;
+ this.clear();
+ }
+
+ @Override
+ public boolean contains(Object item)
+ {
+ boolean exists = super.contains(item);
+ return (invertSelection ? !exists : exists);
+ }
+ }
+
+ public static abstract class SelectableItem implements Serializable
+ {
+ private static final long serialVersionUID = 1L;
+
+ private SelectionSet selectSet = null;
+
+ protected void setSelectMap(SelectionSet selectSet)
+ {
+ this.selectSet = selectSet;
+ }
+
+ public boolean isSelected()
+ {
+ String id = getIdParam();
+ return this.selectSet.contains(id);
+ }
+
+ public void setSelected(boolean selected)
+ {
+ String id = getIdParam();
+ if (selected != this.selectSet.isInvertSelection())
+ {
+ this.selectSet.add(id);
+ }
+ else
+ {
+ this.selectSet.remove(id);
+ }
+ }
+
+ public abstract String getIdParam();
+
+ }
+
+ public static class ListTableInfo implements Serializable
+ {
+ private static final long serialVersionUID = 1L;
+
+ /** Pagination **/
+ /**
+ * position, starts with 0
+ */
+ private int itemCount = -1;
+ private boolean valid = false;
+ private boolean modified = false;
+
+ /** Sorting **/
+ private String sortColumnName;
+ private boolean sortAscending = true;
+ private boolean sortOrderChanged = false;
+
+ /** Pagination **/
+ private int position = 0;
+ private int pageSize = 0;
+
+ public void init(int itemCount, int pageSize)
+ {
+ if (pageSize < 0)
+ { // pageSize must not be negative!
+ throw new ObjectNotValidException(this);
+ }
+ this.itemCount = itemCount;
+ this.pageSize = pageSize;
+ this.position = 0;
+ this.valid = (itemCount >= 0);
+ this.modified = false;
+ }
+
+ public boolean isValid()
+ {
+ return this.valid;
+ }
+
+ public void setValid(boolean valid)
+ {
+ if (valid && (this.itemCount < 0))
+ { // itemCount and position must not be negative!
+ throw new ObjectNotValidException(this);
+ }
+ this.valid = valid;
+ }
+
+ public boolean isModified()
+ {
+ return (this.valid && this.modified);
+ }
+
+ public void setModified(boolean modified)
+ {
+ this.modified = modified;
+ }
+
+ public int getItemCount()
+ {
+ return this.itemCount;
+ }
+
+ public int getPageSize()
+ {
+ return this.pageSize;
+ }
+
+ /*** sorting ***/
+
+ public String getSortColumnName()
+ {
+ return this.sortColumnName;
+ }
+
+ public void setSortColumnName(String column)
+ {
+ if (ObjectUtils.compareEqual(column, this.sortColumnName))
+ {
+ return;
+ }
+ // change value
+ this.sortColumnName = column;
+ this.position = 0;
+ this.modified = true;
+ this.sortOrderChanged = true;
+ }
+
+ public boolean getSortAscending()
+ {
+ return this.sortAscending;
+ }
+
+ public void setSortAscending(boolean sortAscending)
+ {
+ if (this.sortAscending == sortAscending)
+ {
+ return;
+ }
+ // change value
+ this.sortAscending = sortAscending;
+ this.modified = true;
+ this.sortOrderChanged = true;
+ }
+
+ public boolean isSortOrderChanged()
+ {
+ return this.sortOrderChanged;
+ }
+
+ public void setSortOrderChanged(boolean sortOrderChanged)
+ {
+ this.sortOrderChanged = sortOrderChanged;
+ }
+
+ /*** pagination ***/
+
+ public int getPosition()
+ {
+ return this.position;
+ }
+
+ public void setPosition(int position)
+ {
+ if (this.pageSize == 0)
+ {
+ throw new NotSupportedException(this, "setPosition");
+ }
+ if (position < 0)
+ {
+ position = 0;
+ }
+ if (position >= this.itemCount)
+ {
+ position = this.itemCount - 1;
+ }
+ if (this.position == position)
+ {
+ return;
+ }
+ // change value
+ this.position = position;
+ this.modified = true;
+ }
+
+ public boolean isAllowPagination()
+ {
+ return (this.pageSize > 0);
+ }
+
+ public boolean isHasNextPage()
+ {
+ if (isValid() && isAllowPagination())
+ {
+ return ((this.itemCount - (this.position + this.pageSize)) > 0);
+ }
+ return false;
+ }
+
+ public boolean isHasPrevPage()
+ {
+ return (isValid() && isAllowPagination() && this.position > 0);
+ }
+
+ /**
+ * set the next x entries
+ */
+ public void nextPage(ActionEvent e)
+ {
+ if (!isAllowPagination())
+ {
+ throw new NotSupportedException(this, "nextPage");
+ }
+ // Check
+ if ((this.position + this.pageSize) > this.itemCount)
+ {
+ return; // Already on last page
+ }
+ // One page forward
+ this.position += this.pageSize;
+ this.modified = true;
+ }
+
+ /**
+ * set the prev x entries
+ */
+ public void prevPage(ActionEvent e)
+ {
+ if (!isAllowPagination())
+ {
+ throw new NotSupportedException(this, "prevPage");
+ }
+ // Check
+ if (this.position == 0)
+ {
+ return; // Already on first page
+ }
+ // one page back
+ if (this.position > this.pageSize)
+ {
+ this.position -= this.pageSize;
+ }
+ else
+ {
+ this.position = 0;
+ }
+ // modified
+ this.modified = true;
+ }
+
+ public int getPageNumber()
+ {
+ if (!isAllowPagination())
+ {
+ return 1; // always first page
+ }
+ // Calc Page num
+ int pageNumber = new Double(Math.ceil(((double) this.position / this.pageSize))).intValue() + 1;
+ return pageNumber;
+ }
+
+ public int getPageCount()
+ {
+ if (!isAllowPagination())
+ {
+ return 1; // only one page
+ }
+ // Calc Page count
+ int pageCount = new Double(Math.ceil(((double) this.itemCount / this.pageSize))).intValue();
+ return pageCount;
+ }
+
+ }
+
+ public ListPageElement(Page page, Class<T> beanClass, String propertyName)
+ {
+ super(page, propertyName);
+ // set bean Class
+ this.beanClass = beanClass;
+ // selectable
+ if (ListPageElement.isSelectableItem(beanClass))
+ {
+ this.selectedItems = new SelectionSet();
+ }
+ }
+
+ private static <T> boolean isSelectableItem(Class<T> beanClass)
+ {
+ Class<?> superClass = beanClass.getSuperclass();
+ while (superClass != null)
+ { // Check Superclass
+ if (superClass.equals(SelectableItem.class))
+ {
+ return true;
+ }
+ superClass = superClass.getSuperclass();
+ }
+ return false;
+ }
+
+ /** session scoped properties **/
+ public abstract ListTableInfo getTableInfo();
+
+ public List<T> getItems()
+ {
+ if (this.items == null)
+ {
+ ListPageElement.log.warn("Bean List has not been initialized!");
+ }
+ return this.items;
+ }
+
+ // DS only valid if there are items in the list
+ public final boolean isValid()
+ {
+ return (this.items == null) ? false : this.items.size() > 0;
+ }
+
+ public int getItemCount()
+ {
+ return getTableInfo().getItemCount();
+ }
+
+ public void clearItems()
+ {
+ clearSelection();
+ this.items = null;
+ }
+
+ /*** Selection ***/
+
+ public void clearSelection()
+ {
+ if (this.selectedItems != null)
+ {
+ this.selectedItems.clear();
+ }
+ }
+
+ public boolean isHasSelection()
+ {
+ if (this.selectedItems==null)
+ return false;
+ // Has selected Items
+ return (selectedItems.size()>0 || selectedItems.isInvertSelection());
+ }
+
+ public int getSelectedItemCount()
+ {
+ if (this.selectedItems==null)
+ return 0;
+ // Item count
+ return this.selectedItems.size();
+ }
+
+ public Set<Object[]> getSelectedItems()
+ {
+ // if (this.selectedItems==null)
+ throw new NotSupportedException(this, "getSelectedItems");
+ }
+
+ public boolean isInvertSelection()
+ {
+ if (this.selectedItems==null)
+ return false;
+ // Invert selection
+ return this.selectedItems.isInvertSelection();
+ }
+
+ public void setInvertSelection(boolean invertSelection)
+ {
+ if (this.selectedItems==null)
+ throw new NotSupportedException(this, "setInvertSelection");
+ // Invert
+ this.selectedItems.setInvertSelection(invertSelection);
+ }
+
+ protected void assignSelectionMap(List<?> items)
+ {
+ // Check selectable
+ if (this.selectedItems == null)
+ return;
+ // generate all
+ for (Object item : items)
+ {
+ if (item instanceof SelectableItem)
+ {
+ ((SelectableItem) item).setSelectMap(this.selectedItems);
+ }
+ }
+ }
+}
Propchange: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/ListPageElement.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/RecordPageElement.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/RecordPageElement.java?rev=1326123&view=auto
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/RecordPageElement.java (added)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/RecordPageElement.java Sat Apr 14 14:57:28 2012
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.pageelements;
+
+import java.sql.Connection;
+
+import org.apache.empire.db.DBRecord;
+import org.apache.empire.db.DBRowSet;
+import org.apache.empire.exceptions.InvalidArgumentException;
+import org.apache.empire.exceptions.ObjectNotValidException;
+import org.apache.empire.jsf2.pages.Page;
+import org.apache.empire.jsf2.pages.PageElement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RecordPageElement<T extends DBRecord> extends PageElement
+{
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger log = LoggerFactory.getLogger(RecordPageElement.class);
+
+ protected DBRowSet rowset;
+
+ protected T record;
+
+ public RecordPageElement(Page page, DBRowSet rowset, T record, String propertyName)
+ {
+ super(page, propertyName);
+ // Set Rowset and Record
+ this.rowset = rowset;
+ this.record = record;
+
+ log.debug("RecordPageSupport for {} created.", rowset.getName());
+ }
+
+ public T getRecord()
+ {
+ return record;
+ }
+
+ public DBRowSet getRowSet()
+ {
+ return record.getRowSet();
+ }
+
+ @Override
+ protected void onInitPage()
+ {
+ // Chance to init the page
+ if (record.isValid()==false)
+ reloadRecord();
+ }
+
+ /**
+ * loads the record identified by the supplied key from the database<BR/>
+ * @return true if the record has been successfully reloaded or false otherwise
+ */
+ public void reloadRecord()
+ {
+ Object[] recKey = getSessionObject(Object[].class);
+ // Check Key
+ if (recKey==null || recKey.length==0)
+ { // Invalid Record key
+ throw new ObjectNotValidException(this);
+ }
+ // Record laden
+ Connection conn = getPage().getConnection(rowset.getDatabase());
+ record.read(rowset, recKey, conn);
+ }
+
+ /**
+ * loads the record identified by the supplied key from the database<BR/>
+ * @return true if the record has been successfully reloaded or false otherwise
+ */
+ public void loadRecord(Object[] recKey)
+ {
+ // Check Key
+ if (recKey==null || recKey.length==0)
+ { // Invalid Record key
+ throw new InvalidArgumentException("recKey", recKey);
+ }
+ // Put key on Session
+ this.setSessionObject(Object[].class, recKey);
+ // Record laden
+ Connection conn = getPage().getConnection(rowset.getDatabase());
+ record.read(rowset, recKey, conn);
+ }
+
+ /**
+ * creates a new record
+ */
+ public void createRecord()
+ {
+ record.create(rowset);
+ }
+
+ /**
+ * loads an existing record
+ * @param idParam
+ */
+ public void loadRecord(String idParam)
+ {
+ Object[] key = getPage().getKeyFromParam(rowset, idParam);
+
+ loadRecord(key);
+ }
+
+ public String getRecordIdParam()
+ {
+ if (!record.isValid())
+ return null;
+ // idParam
+ Object[] key = record.getKeyValues();
+ return getPage().getIdParamForKey(rowset, key);
+ }
+
+}
Propchange: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/RecordPageElement.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/StaticListPageElement.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/StaticListPageElement.java?rev=1326123&view=auto
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/StaticListPageElement.java (added)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/StaticListPageElement.java Sat Apr 14 14:57:28 2012
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.pageelements;
+
+import java.util.List;
+
+import org.apache.empire.exceptions.ObjectNotValidException;
+import org.apache.empire.jsf2.pages.Page;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class StaticListPageElement<T> extends ListPageElement<T>
+{
+ private static final Logger log = LoggerFactory.getLogger(BeanListPageElement.class);
+
+ private static final long serialVersionUID = 1L;
+
+ private ListTableInfo listTableInfo = new ListTableInfo();
+
+ public StaticListPageElement(Page page, Class<T> beanClass, String propertyName)
+ {
+ super(page, beanClass, propertyName);
+ }
+
+ @Override
+ protected void onInitPage()
+ {
+ if (items == null)
+ { // loadBookings
+ log.error("StaticListPageElement has not been intialized! Please initialize in doInit() before calling super.doInit()!");
+ throw new ObjectNotValidException(this);
+ }
+ }
+
+ @Override
+ public ListTableInfo getTableInfo()
+ {
+ return listTableInfo;
+ }
+
+ public void setItems(List<T> items)
+ {
+ clearItems();
+ this.items = items;
+ getTableInfo().init(items.size(), 0);
+ }
+
+}
Propchange: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/StaticListPageElement.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java?rev=1326123&view=auto
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java (added)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java Sat Apr 14 14:57:28 2012
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.pages;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.application.NavigationHandler;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
+import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.DBRowSet;
+import org.apache.empire.jsf2.app.FacesApplication;
+import org.apache.empire.jsf2.app.FacesUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class Page implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private static final String SESSION_MESSAGE = "PAGE_SESSION_MESSAGE";
+
+ private static final String INVALID_ACTION = "XXXXXXXXXXXX";
+
+ private static final Logger log = LoggerFactory.getLogger(Page.class);
+
+ private String action = null;
+ private boolean initialized = false;
+ private PageDefinition pageDefinition = null;
+ private List<PageElement> pageElements = null;
+
+ protected Page()
+ {
+ String name = this.getClass().getSimpleName();
+ Page.log.info("PageBean {} created.", name);
+ }
+
+ public String getPageName()
+ {
+ return (pageDefinition != null ? pageDefinition.getPageBeanName() : "{" + getClass().getSimpleName() + "}");
+ }
+
+ public String getName()
+ {
+ String className = pageDefinition.getPageBeanClass().getName();
+ int lastDot = className.lastIndexOf(".");
+ String name = className.substring(lastDot + 1);
+ return name;
+ }
+
+ public boolean isInitialized()
+ {
+ return initialized;
+ }
+
+ public String getAction()
+ {
+ return this.action;
+ }
+
+ public void setAction(String action)
+ {
+ if (!initialized)
+ Page.log.info("Setting PageBean action {} for bean {}.", action, getPageName());
+ else
+ Page.log.trace("Re-setting PageBeanAction {} for bean {}.", action, getPageName());
+ this.action = action;
+ }
+
+ public PageDefinition getPageDefinition()
+ {
+ return pageDefinition;
+ }
+
+ public void setPageDefinition(PageDefinition pageDefinition)
+ {
+ this.pageDefinition = pageDefinition;
+ }
+
+ public PageDefinition getParentPage()
+ {
+ return pageDefinition.getParent();
+ }
+
+ public void preRenderPage(FacesContext context)
+ {
+ if (this.initialized)
+ {
+ // PageBean.log.error("PageBean {} is already initialized.", name());
+ try
+ {
+ Page.log.debug("PageBean {} is already initialized. Calling doRefresh().", getPageName());
+ doRefresh();
+ }
+ catch (Throwable e)
+ {
+ logAndHandleActionException("doRefresh", e);
+ }
+ return; // already Initialized
+ }
+
+ // Check access
+ try
+ {
+ checkPageAccess();
+ }
+ catch (Throwable e)
+ {
+ logAndHandleActionException("checkAccess", e);
+ // redirected?
+ if (context.getResponseComplete())
+ return;
+ // Oops, not redirected yet?
+ redirectTo(getParentOutcome(true));
+ return;
+ }
+
+ // Initialize
+ this.initialized = true;
+
+ // Execute Action
+ if (this.action != null)
+ {
+ if (this.action.equals(Page.INVALID_ACTION))
+ {
+ Page.log.error("Action probably executed twice. Ignoring action.");
+ return;
+ }
+ try
+ {
+ Page.log.debug("Executing action {} on {}.", String.valueOf(this.action), getPageName());
+ Method method = getClass().getMethod(this.action);
+ Object result = method.invoke(this);
+ if (result != null)
+ {
+ String outcome = result.toString();
+ // Retrieve the NavigationHandler instance..
+ NavigationHandler navHandler = context.getApplication().getNavigationHandler();
+ // Invoke nav handling..
+ navHandler.handleNavigation(context, action, outcome);
+ // Trigger a switch to Render Response if needed
+ context.renderResponse();
+ return;
+ }
+ restoreSessionMessage();
+ }
+ catch (NoSuchMethodException nsme)
+ {
+ logAndHandleActionException(action, nsme);
+ }
+ catch (Exception e)
+ {
+ logAndHandleActionException(action, e.getCause());
+ }
+ finally
+ {
+ // Clear action
+ this.action = Page.INVALID_ACTION;
+ }
+ }
+ else
+ { // call default Action
+ try
+ {
+ Page.log.debug("Initializing PageBean {}. Calling doInit()", getPageName());
+ doInit();
+ restoreSessionMessage();
+ }
+ catch (Throwable e)
+ {
+ logAndHandleActionException("doInit", e);
+ }
+ }
+ }
+
+ protected void checkPageAccess()
+ {
+ /* Throw exception if User has no Access */
+ }
+
+ private void restoreSessionMessage()
+ {
+ // Restore Session Error Message
+ ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
+ Map<String, Object> map = ec.getSessionMap();
+ if (map.containsKey(SESSION_MESSAGE))
+ {
+ FacesMessage errorMsg = (FacesMessage) map.get(SESSION_MESSAGE);
+ FacesContext.getCurrentInstance().addMessage(getPageName(), errorMsg);
+ map.remove(SESSION_MESSAGE);
+ }
+ }
+
+ private void logAndHandleActionException(String action, Throwable e)
+ {
+ String msg = "Failed to perform action " + action + " on " + getPageName();
+ // Message
+ Page.log.error(msg, e);
+ if (!handleActionError(action, e))
+ throw new RuntimeException(msg, e);
+ }
+
+ protected void setSessionMessage(FacesMessage facesMsg)
+ {
+ // Set Session Message
+ ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
+ ec.getSessionMap().put(SESSION_MESSAGE, facesMsg);
+ }
+
+ protected boolean handleActionError(String action, Throwable e)
+ {
+ // Set Faces Message
+ String msg = e.getLocalizedMessage();
+ String detail = extractErrorMessageDetail(action, e, 1);
+ log.error(msg + "\r\n" + detail);
+ FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, detail);
+ setSessionMessage(facesMsg);
+ // Return to parent page
+ PageDefinition parentPage = getParentPage();
+ if (parentPage == null)
+ return false;
+ // redirect
+ redirectTo(parentPage.getRedirect());
+ return true;
+ }
+
+ protected String extractErrorMessageDetail(String action, Throwable e, int stackTraceElements)
+ {
+ StringBuilder b = new StringBuilder();
+ b.append("Error performing action '");
+ b.append(action);
+ b.append("' on page ");
+ b.append(getPageName());
+ b.append(": ");
+ b.append(e.toString());
+ b.append("\r\nat:");
+ StackTraceElement[] stack = e.getStackTrace();
+ int len = (stack.length>stackTraceElements) ? stackTraceElements : stack.length;
+ for (int i=0; i<len; i++)
+ {
+ b.append(stack[i].toString());
+ b.append("\r\n");
+ }
+ return b.toString();
+ }
+
+ protected void redirectTo(PageOutcome outcome)
+ {
+ log.error("Redirecting from page {} to page {}.", getPageName(), outcome.toString());
+ // Return to Parent
+ FacesContext context = FacesContext.getCurrentInstance();
+ // Retrieve the NavigationHandler instance..
+ NavigationHandler navHandler = context.getApplication().getNavigationHandler();
+ // Invoke nav handling..
+ navHandler.handleNavigation(context, action, outcome.toString());
+ // Trigger a switch to Render Response if needed
+ context.renderResponse();
+ }
+
+ /**
+ * adds a page element to this page
+ * DO NOT CALL yourself, this method is called from the PageElement constructor!
+ *
+ * @param element
+ */
+ protected void registerPageElement(PageElement element)
+ {
+ if (pageElements == null)
+ pageElements = new ArrayList<PageElement>(1);
+ // register now
+ if (pageElements.contains(element) == false)
+ pageElements.add(element);
+ else
+ log.warn("PageElement {} was registered twice!", element.getPropertyName());
+ }
+
+ /**
+ * Helper methods for parent outcome
+ *
+ * @param action
+ * @param redirect
+ * @return the parent outcome string
+ */
+ protected PageOutcome getParentOutcome(String action, boolean redirect)
+ {
+ PageDefinition parentPage = getParentPage();
+ if (parentPage == null)
+ throw new RuntimeException("No Parent Page defined for " + getPageName());
+ if (redirect)
+ return parentPage.getRedirect(action);
+ else
+ return parentPage.getOutcome(action);
+ }
+
+ protected PageOutcome getParentOutcome(boolean redirect)
+ {
+ return getParentOutcome(null, redirect);
+ }
+
+ /**
+ * return a connection for a particular database
+ * @param db the database for which to obtain a connection
+ * @return the connection for the given database
+ */
+ public Connection getConnection(DBDatabase db)
+ {
+ FacesApplication app = FacesUtils.getFacesApplication();
+ return app.getConnectionForRequest(FacesUtils.getContext(), db);
+ }
+
+ public Object[] getKeyFromParam(DBRowSet rowset, String idParam)
+ {
+ FacesContext fc = FacesUtils.getContext();
+ return FacesUtils.getParameterMap(fc).get(rowset, idParam);
+ }
+
+ public String getIdParamForKey(DBRowSet rowset, Object[] key)
+ {
+ FacesContext fc = FacesUtils.getContext();
+ return FacesUtils.getParameterMap(fc).put(rowset, key);
+ }
+
+ public void addJavascriptCall(String function)
+ {
+ if (!function.endsWith(";"))
+ { // Add a semicolon (important!)
+ function += ";";
+ }
+ // Add Call
+ FacesContext fc = FacesUtils.getContext();
+ FacesApplication app = FacesUtils.getFacesApplication();
+ app.addJavascriptCall(fc, function);
+ }
+
+ /* Default Init Method */
+ public void doInit()
+ {
+ if (pageElements != null)
+ { // Init Page Elements
+ for (PageElement pe : pageElements)
+ pe.onInitPage();
+ }
+ }
+
+ public void doRefresh()
+ {
+ if (pageElements != null)
+ { // Init Page Elements
+ for (PageElement pe : pageElements)
+ pe.onRefreshPage();
+ }
+ }
+}
Propchange: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinition.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinition.java?rev=1326123&view=auto
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinition.java (added)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinition.java Sat Apr 14 14:57:28 2012
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.pages;
+
+import org.apache.empire.commons.StringUtils;
+
+
+public class PageDefinition
+{
+ private String path;
+ private String pageBeanName;
+ private Class<? extends Page> pageBeanClass;
+ private PageDefinition parent = null;
+
+ public PageDefinition(String path, Class<? extends Page> pageBeanClass)
+ {
+ this.path = path;
+ this.pageBeanClass = pageBeanClass;
+ // beanName
+ int lastSlash = path.lastIndexOf("/");
+ String name = path.substring(lastSlash + 1);
+ this.pageBeanName = name.replace(".xhtml", "Page");
+ // add this view
+ PageDefinitions.registerPage(this);
+ }
+
+ public PageDefinition(String path, Class<? extends Page> pageClass, PageDefinition parent)
+ {
+ this(path, pageClass);
+ this.parent = parent;
+ }
+
+ public String getPath()
+ {
+ return path;
+ }
+
+ public String getPageBeanName()
+ {
+ return pageBeanName;
+ }
+
+ public Class<? extends Page> getPageBeanClass()
+ {
+ return pageBeanClass;
+ }
+
+ public PageDefinition getParent()
+ {
+ return parent;
+ }
+
+ /* Outcome generator */
+
+ public PageOutcome getOutcome()
+ {
+ return new PageOutcome(path);
+ }
+
+ public PageOutcome getOutcome(String action)
+ {
+ PageOutcome outcome = getOutcome();
+ if (StringUtils.isNotEmpty(action))
+ outcome = outcome.addParam("action", action);
+ return outcome;
+ }
+
+ public PageOutcome getRedirect()
+ {
+ PageOutcome outcome = getOutcome();
+ outcome = outcome.addParamWithValue("faces-redirect=true");
+ return outcome;
+ }
+
+ public PageOutcome getRedirect(String action)
+ {
+ PageOutcome outcome = getRedirect();
+ if (StringUtils.isNotEmpty(action))
+ outcome = outcome.addParam("action", action);
+ return outcome;
+ }
+
+ public PageOutcome getRedirectWithViewParams()
+ {
+ PageOutcome outcome = getRedirect();
+ outcome = outcome.addParamWithValue("includeViewParams=true");
+ return outcome;
+ }
+
+ public PageOutcome getRedirectWithViewParams(String action)
+ {
+ PageOutcome outcome = getRedirectWithViewParams();
+ if (StringUtils.isNotEmpty(action))
+ outcome = outcome.addParam("action", action);
+ return outcome;
+ }
+
+ @Override
+ public String toString()
+ {
+ return getOutcome().toString();
+ }
+}
Propchange: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinitions.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinitions.java?rev=1326123&view=auto
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinitions.java (added)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinitions.java Sat Apr 14 14:57:28 2012
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.pages;
+
+import java.util.HashMap;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.sun.faces.mgbean.BeanManager;
+import com.sun.faces.mgbean.ManagedBeanInfo;
+
+
+public abstract class PageDefinitions
+{
+ private static final Logger log = LoggerFactory.getLogger(PageDefinitions.class);
+
+ private static HashMap<String,PageDefinition> pageMap = new HashMap<String,PageDefinition>();
+
+ private static PageDefinitions instance = null;
+
+ public static PageDefinitions getInstance()
+ {
+ return instance;
+ }
+
+ protected PageDefinitions()
+ {
+ if (instance!=null)
+ {
+ throw new RuntimeException("PageDefintions alreday defined. Only one Instance allowed!");
+ }
+ // init
+ instance = this;
+ log.info("PageDefintions class created");
+ }
+
+ /**
+ * Register page beans with the BeanManager
+ * @param bm
+ */
+ public void registerPageBeans(BeanManager bm)
+ {
+ for (PageDefinition v : pageMap.values())
+ {
+ String beanName = v.getPageBeanName();
+ String beanClass = v.getPageBeanClass().getName();
+ // check
+ if (bm.getRegisteredBeans().containsKey(beanName))
+ {
+ throw new RuntimeException("Bean of name "+beanName+" already defined!");
+ }
+ log.info("Registering managed bean '{}' of class '{}' for page '{}'.", new Object[] { beanName, beanClass, v.getPath() });
+ /*
+ ManagedBeanInfo(String name,
+ String className,
+ String beanScope,
+ ManagedBeanInfo.MapEntry mapEntry,
+ ManagedBeanInfo.ListEntry listEntry,
+ List<ManagedBeanInfo.ManagedProperty> managedProperties,
+ Map<String,String> descriptions) {
+ */
+ ManagedBeanInfo mbi = new ManagedBeanInfo(beanName, beanClass, "view", null, null, null, null);
+ bm.register(mbi);
+ }
+ }
+
+ /**
+ * returns a page definition for a given viewId
+ * @param viewId
+ * @return the page definition
+ */
+ public static PageDefinition getPageFromViewId(String viewId)
+ {
+ viewId = viewId.replace(".iface", ".xhtml");
+ PageDefinition view = pageMap.get(viewId);
+ if (view==null)
+ log.error("No page defintion for viewId {}", viewId);
+ return view;
+ }
+
+ /**
+ * register a page. Called internally from PageDefinition constructor!
+ * Do not call yourself.
+ * @param pageDef
+ */
+ protected static void registerPage(PageDefinition pageDef)
+ {
+ String name = pageDef.getPath();
+ if (pageMap.containsKey(name))
+ {
+ throw new RuntimeException("Page of name "+name+" already defined!");
+ }
+ log.info("Registering view '{}'.", name);
+ pageMap.put(name, pageDef);
+ }
+}
Propchange: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageDefinitions.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageELResolver.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageELResolver.java?rev=1326123&view=auto
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageELResolver.java (added)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageELResolver.java Sat Apr 14 14:57:28 2012
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.pages;
+
+import java.beans.FeatureDescriptor;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+
+import org.apache.empire.jsf2.app.FacesUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PageELResolver extends ELResolver
+{
+ private static final Logger log = LoggerFactory.getLogger(PageELResolver.class);
+
+ @Override
+ public Class<?> getCommonPropertyType(ELContext context, Object base)
+ {
+ if (base==null)
+ log.warn("PageELResolver:getCommonPropertyType is not implemented!");
+ return null;
+ }
+
+ @Override
+ public Class<?> getType(ELContext context, Object base, Object property)
+ {
+ if (base==null && property.equals("page"))
+ { // Page
+ // context.setPropertyResolved(true);
+ return Page.class;
+ }
+ return null;
+ }
+
+ @Override
+ public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext arg0, Object arg1)
+ {
+ log.warn("PageELResolver:getFeatureDescriptors is not implemented!");
+ return null;
+ }
+
+ @Override
+ public Object getValue(ELContext context, Object base, Object property)
+ {
+ if (base==null && property.equals("page"))
+ {
+ UIViewRoot vr = FacesContext.getCurrentInstance().getViewRoot();
+ if (vr==null)
+ { // Error: No view root
+ RuntimeException e = new RuntimeException("ViewRoot not available. Unable to get Page Bean.");
+ log.error(e.getMessage());
+ throw e;
+ }
+ Map<String,Object> vmap = vr.getViewMap(false);
+ Page page = (vmap!=null ? (Page)vmap.get("page") : null);
+ if (page==null)
+ { // Error: No page bean
+ RuntimeException e = new RuntimeException("Page bean not available for current view.");
+ log.error(e.getMessage());
+ throw e;
+ }
+ context.setPropertyResolved(true);
+ return page;
+ }
+ return null;
+ }
+
+ @Override
+ public boolean isReadOnly(ELContext context, Object base, Object property)
+ {
+ if (base==null && property.equals("page"))
+ {
+ context.setPropertyResolved(true);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void setValue(ELContext context, Object base, Object property, Object value)
+ {
+ if (base==null && property.equals("page"))
+ { // done
+ String pageAsString = String.valueOf(FacesUtils.getPage(FacesContext.getCurrentInstance()));
+ if (!pageAsString.equals(value))
+ log.warn("Page instances don't match");
+ // done
+ context.setPropertyResolved(true);
+ }
+ }
+
+}
Propchange: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageELResolver.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageElement.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageElement.java?rev=1326123&view=auto
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageElement.java (added)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageElement.java Sat Apr 14 14:57:28 2012
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.pages;
+
+import java.io.Serializable;
+import java.sql.Connection;
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+
+import org.apache.empire.commons.StringUtils;
+import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.DBObject;
+import org.apache.empire.exceptions.InvalidArgumentException;
+
+
+public class PageElement implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private final Page page;
+
+ private final String propertyName;
+
+ protected PageElement(Page page, String propertyName)
+ {
+ if (page==null)
+ throw new InvalidArgumentException("page", page);
+ if (StringUtils.isEmpty(propertyName))
+ throw new InvalidArgumentException("propertyName", propertyName);
+ // set params
+ this.page = page;
+ this.propertyName = propertyName;
+ // register with page
+ page.registerPageElement(this);
+ }
+
+ public String getPropertyName()
+ {
+ return propertyName;
+ }
+
+ public Page getPage()
+ {
+ return page;
+ }
+
+ protected void onInitPage()
+ {
+ // Chance to init the page
+ }
+
+ protected void onRefreshPage()
+ {
+ // Chance to init the page
+ }
+
+ /**
+ * Session Object handling
+ *
+ * @param type
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ protected <T> T getSessionObject(Class<T> type)
+ {
+ String beanName = page.getPageName() + "." + propertyName + "." + type.getSimpleName();
+ Map<String, Object> map = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
+ return (T) map.get(beanName);
+ }
+
+ protected <T> void setSessionObject(Class<T> type, T object)
+ {
+ String beanName = page.getPageName() + "." + propertyName + "." + type.getSimpleName();
+ Map<String, Object> map = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
+ if (object != null)
+ map.put(beanName, object);
+ else
+ map.remove(beanName);
+ }
+
+ protected <T> void removeSessionObject(Class<T> type)
+ {
+ setSessionObject(type, null);
+ }
+
+ public Connection getConnection(DBDatabase db)
+ {
+ return page.getConnection(db);
+ }
+
+ public Connection getConnection(DBObject dbo)
+ {
+ if (dbo==null)
+ throw new InvalidArgumentException("dbo", dbo);
+ return page.getConnection(dbo.getDatabase());
+ }
+
+ /**
+ * Javascript Call
+ *
+ * @param function
+ protected void addJavascriptCall(String function)
+ {
+ page.addJavascriptCall(function);
+ }
+ */
+}
Propchange: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageElement.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageNavigationHandler.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageNavigationHandler.java?rev=1326123&view=auto
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageNavigationHandler.java (added)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageNavigationHandler.java Sat Apr 14 14:57:28 2012
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.pages;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.faces.application.ConfigurableNavigationHandler;
+import javax.faces.application.NavigationCase;
+import javax.faces.application.NavigationHandler;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PageNavigationHandler extends ConfigurableNavigationHandler
+{
+ private static final Logger log = LoggerFactory.getLogger(PageNavigationHandler.class);
+
+ private static boolean initialized = false;
+
+ public static boolean isInitialized()
+ {
+ return initialized;
+ }
+
+ private NavigationHandler parent;
+
+ public PageNavigationHandler(NavigationHandler parent)
+ {
+ this.parent = parent;
+ initialized = true;
+ // Log
+ log.info("PageNavigatonHandler sucessfully established.");
+ }
+
+ @Override
+ public void handleNavigation(FacesContext context, String from, String outcome)
+ {
+ // boolean redirect = (outcome.indexOf("faces-redirect=true")>=0);
+
+ parent.handleNavigation(context, from, outcome);
+
+ // Check outcome
+ if (outcome==null)
+ return;
+
+ NavigationCase navigationCase = getNavigationCase(context, from, outcome);
+ boolean redirect = (navigationCase != null ?
+ navigationCase.isRedirect() :
+ (outcome.indexOf("faces-redirect=true") >= 0));
+ // Check for forward (not redirect)
+ if (!redirect)
+ {
+ log.debug("Handling forward navigation.");
+ /*
+ NavigationCase navigationCase = getNavigationCase(context, fromAction, outcome);
+ if (navigationCase == null || navigationCase.isRedirect()) {
+ handler.handleNavigation(context, fromAction, outcome);
+ } else {
+ UIViewRoot viewRoot = context.getViewRoot();
+ Collection<UIForm> forms = findUIForms(viewRoot);
+ Map<String, Object> viewAttributes = viewRoot.getViewMap();
+ HashMap idToPreviousParametersMapping = (HashMap) viewAttributes.get(DeltaSubmitPhaseListener.PreviousParameters);
+ if (idToPreviousParametersMapping == null) {
+ idToPreviousParametersMapping = new HashMap();
+ viewAttributes.put(DeltaSubmitPhaseListener.PreviousParameters, idToPreviousParametersMapping);
+ }
+ for (UIForm form : forms) {
+ Map previousParameters = (Map) form.getAttributes().get(DeltaSubmitPhaseListener.PreviousParameters);
+ if (previousParameters != null) {
+ idToPreviousParametersMapping.put(form.getId(), new HashMap(previousParameters));
+ }
+ }
+ handler.handleNavigation(context, fromAction, outcome);
+ //propagate previously calculated submit parameters
+ context.getViewRoot().getViewMap().put(DeltaSubmitPhaseListener.PreviousParameters, idToPreviousParametersMapping);
+ }
+ */
+ UIViewRoot viewRoot = context.getViewRoot();
+ Map<String, Object> viewMap = viewRoot.getViewMap();
+ Map<String, String> paramsMap = getActionParameterMap(outcome);
+ if (paramsMap!=null)
+ {
+ log.debug("Setting FORWARD_PAGE_PARAMS for outcome {}.", outcome);
+ viewMap.put(PagePhaseListener.FORWARD_PAGE_PARAMS, paramsMap);
+ }
+ }
+
+ }
+
+ private Map<String, String> getActionParameterMap(String s)
+ {
+ int i = -1;
+ Map<String, String> map = null;
+ while ((i=s.indexOf('=', i+1))>0)
+ {
+ int n = s.lastIndexOf('&', i);
+ if (n<0)
+ n = s.lastIndexOf('?', i);
+ if (n<0)
+ continue; // something is wrong
+ int v = s.indexOf('&');
+ String name = s.substring(n+1, i);
+ String value = (v>i) ? s.substring(i+1, v) : s.substring(i+1);
+ log.debug("Adding view parameter '{}' with value '{}'.", name, value);
+ if (map==null)
+ map = new HashMap<String, String>();
+ map.put(name, value);
+ }
+ return map;
+ }
+
+ @Override
+ public NavigationCase getNavigationCase(FacesContext context, String fromAction, String outcome)
+ {
+ if (parent instanceof ConfigurableNavigationHandler)
+ {
+ NavigationCase navigationCase = ((ConfigurableNavigationHandler) parent).getNavigationCase(context, fromAction, outcome);
+ /*
+ if (navigationCase!=null && !navigationCase.isRedirect())
+ {
+ log.trace("Performing a forward operation!");
+ }
+ */
+ return navigationCase;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ @Override
+ public Map<String, Set<NavigationCase>> getNavigationCases()
+ {
+ if (parent instanceof ConfigurableNavigationHandler)
+ {
+ return ((ConfigurableNavigationHandler) parent).getNavigationCases();
+ }
+ else
+ {
+ return null;
+ }
+ }
+}
Propchange: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageNavigationHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageOutcome.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageOutcome.java?rev=1326123&view=auto
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageOutcome.java (added)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageOutcome.java Sat Apr 14 14:57:28 2012
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.jsf2.pages;
+
+import org.apache.empire.commons.StringUtils;
+
+public class PageOutcome
+{
+ private String outcome;
+ public PageOutcome(String outcome)
+ {
+ if (StringUtils.isEmpty(outcome))
+ throw new RuntimeException("Illegal Outcome Value");
+ this.outcome = outcome;
+ }
+
+ public PageOutcome addParamWithValue(String paramWithValue)
+ {
+ if (paramWithValue==null || paramWithValue.indexOf('=')<0)
+ throw new RuntimeException("Illegal Parameter Value");
+ // assemble
+ if (outcome.indexOf('?')>0)
+ outcome = outcome+"&"+paramWithValue;
+ else
+ outcome = outcome+"?"+paramWithValue;
+ return this;
+ }
+
+ public PageOutcome addParam(String param, String value)
+ {
+ if (StringUtils.isEmpty(value))
+ return this; // Ignore Empty values
+ if (StringUtils.isEmpty(param))
+ throw new RuntimeException("Illegal Parameter Name");
+ String paramWithValue = param + "=" + value;
+ return addParamWithValue(paramWithValue);
+ }
+
+ @Override
+ public String toString()
+ {
+ return outcome;
+ }
+}
Propchange: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageOutcome.java
------------------------------------------------------------------------------
svn:mime-type = text/plain