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/08/16 14:31:17 UTC
svn commit: r1373805 - in /empire-db/trunk: ./
empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/
empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/
empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/
Author: doebele
Date: Thu Aug 16 12:31:16 2012
New Revision: 1373805
URL: http://svn.apache.org/viewvc?rev=1373805&view=rev
Log:
EMPIREDB-154
Allow InputTag in Tables - works with Mojarra 2.1.6
Modified:
empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/InputTag.java
empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/LinkTag.java
empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/CheckboxInputControl.java
empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/SelectInputControl.java
empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextAreaInputControl.java
empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java
empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
empire-db/trunk/pom.xml
Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/InputTag.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/InputTag.java?rev=1373805&r1=1373804&r2=1373805&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/InputTag.java (original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/InputTag.java Thu Aug 16 12:31:16 2012
@@ -46,9 +46,16 @@ public class InputTag extends UIInput im
private InputControl control = null;
private InputControl.InputInfo inpInfo = null;
+ private static int itemIdSeq = 0;
+ private final int itemId;
+
public InputTag()
{
super();
+ // Debug stuff
+ itemId = ++itemIdSeq;
+ if (log.isDebugEnabled())
+ log.debug("InputTag {} created", itemId);
}
@Override
@@ -66,12 +73,19 @@ public class InputTag extends UIInput im
private boolean initState(FacesContext context)
{
+ // Must have children
+ if (getChildCount()==0)
+ { log.warn("InputTag has no children! Unable to init Input state.");
+ log.warn("Problem might be related to Mojarra 2.1.7 to 2.1.11 (and possibly later) - please use Mojarra 2.1.6!");
+ return false;
+ }
+ // Read only State
Boolean ros = (Boolean)getStateHelper().get(readOnlyState);
if (ros!=null && ros.booleanValue())
return false;
- // control = ;
+ // Init Control and inputInfo;
control = helper.getInputControl();
- inpInfo = helper.getInputInfo(context);
+ inpInfo = helper.getInputInfo(context);
return (control!=null && inpInfo!=null);
}
Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/LinkTag.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/LinkTag.java?rev=1373805&r1=1373804&r2=1373805&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/LinkTag.java (original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/LinkTag.java Thu Aug 16 12:31:16 2012
@@ -97,12 +97,13 @@ public class LinkTag extends UIOutput im
linkComponent = (HtmlOutcomeTargetLink)c;
else
{ // Something's wrong here?
- log.info("INFO: Unexpected child node for {}!", getClass().getName());
+ log.info("INFO: Unexpected child node for {}! Child item type is {}.", getClass().getName(), c.getClass().getName());
// Check facetComponent
UIPanel facetComponent = (UIPanel)getFacets().get(UIComponent.COMPOSITE_FACET_NAME);
if (facetComponent==null)
{
log.warn("WARN: component's facetComponent has not been set! Using Default (javax.faces.Panel).");
+ log.warn("Problem might be related to Mojarra 2.1.7 to 2.1.11 (and possibly later) - please use Mojarra 2.1.6!");
facetComponent = (UIPanel)context.getApplication().createComponent("javax.faces.Panel");
facetComponent.setRendererType("javax.faces.Group");
getFacets().put(UIComponent.COMPOSITE_FACET_NAME, facetComponent);
Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/CheckboxInputControl.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/CheckboxInputControl.java?rev=1373805&r1=1373804&r2=1373805&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/CheckboxInputControl.java (original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/CheckboxInputControl.java Thu Aug 16 12:31:16 2012
@@ -25,7 +25,7 @@ import javax.faces.component.html.HtmlSe
import javax.faces.context.FacesContext;
import org.apache.empire.exceptions.InternalException;
-import org.apache.empire.jsf2.controls.InputControl;
+import org.apache.empire.exceptions.UnexpectedReturnValueException;
public class CheckboxInputControl extends InputControl
{
@@ -48,19 +48,30 @@ public class CheckboxInputControl extend
protected void createInputComponents(UIComponent parent, InputInfo ii, FacesContext context, List<UIComponent> compList)
{
HtmlSelectBooleanCheckbox input;
- try
- { input = inputComponentClass.newInstance();
- } catch (InstantiationException e1) {
- throw new InternalException(e1);
- } catch (IllegalAccessException e2) {
- throw new InternalException(e2);
- }
- copyAttributes(parent, ii, input);
+ if (compList.size()==0)
+ { try {
+ input = inputComponentClass.newInstance();
+ } catch (InstantiationException e1) {
+ throw new InternalException(e1);
+ } catch (IllegalAccessException e2) {
+ throw new InternalException(e2);
+ }
+ copyAttributes(parent, ii, input);
+ // add
+ compList.add(input);
+ }
+ else
+ { // check type
+ UIComponent comp = compList.get(0);
+ if (!(comp instanceof HtmlSelectBooleanCheckbox))
+ throw new UnexpectedReturnValueException(comp.getClass().getName(), "compList.get");
+ // cast
+ input = (HtmlSelectBooleanCheckbox)comp;
+ }
- setInputValue(input, ii);
+ // Set Value
input.setDisabled(ii.isDisabled());
-
- compList.add(input);
+ setInputValue(input, ii);
}
}
Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java?rev=1373805&r1=1373804&r2=1373805&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java (original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java Thu Aug 16 12:31:16 2012
@@ -236,9 +236,8 @@ public abstract class InputControl
public void renderInput(UIComponent comp, InputInfo ii, FacesContext context, boolean encode)
throws IOException
{
- int count = comp.getChildCount();
- if (count<1)
- createInputComponents(comp, ii, context, comp.getChildren());
+ // createInputComponents
+ createInputComponents(comp, ii, context, comp.getChildren());
// Encode all
if (!encode)
return;
Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/SelectInputControl.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/SelectInputControl.java?rev=1373805&r1=1373804&r2=1373805&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/SelectInputControl.java (original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/SelectInputControl.java Thu Aug 16 12:31:16 2012
@@ -29,6 +29,7 @@ import org.apache.empire.commons.OptionE
import org.apache.empire.commons.Options;
import org.apache.empire.data.Column;
import org.apache.empire.exceptions.InternalException;
+import org.apache.empire.exceptions.UnexpectedReturnValueException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -69,33 +70,44 @@ public class SelectInputControl extends
protected void createInputComponents(UIComponent parent, InputInfo ii, FacesContext context, List<UIComponent> compList)
{
HtmlSelectOneMenu input;
- try {
- input = inputComponentClass.newInstance();
- } catch (InstantiationException e1) {
- throw new InternalException(e1);
- } catch (IllegalAccessException e2) {
- throw new InternalException(e2);
- }
- copyAttributes(parent, ii, input);
-
- Options options = ii.getOptions();
- if (ii.isRequired()==false)
- { // Empty entry
- options = new Options(options);
- addSelectItem(input, ii, new OptionEntry("", getNullText(ii)));
- }
- if (options!=null && options.size()>0)
- { // Add options
- for (OptionEntry e : options)
- { // Option entries
- addSelectItem(input, ii, e);
+ if (compList.size()==0)
+ { try {
+ input = inputComponentClass.newInstance();
+ } catch (InstantiationException e1) {
+ throw new InternalException(e1);
+ } catch (IllegalAccessException e2) {
+ throw new InternalException(e2);
}
+ copyAttributes(parent, ii, input);
+
+ Options options = ii.getOptions();
+ if (ii.isRequired()==false)
+ { // Empty entry
+ options = new Options(options);
+ addSelectItem(input, ii, new OptionEntry("", getNullText(ii)));
+ }
+ if (options!=null && options.size()>0)
+ { // Add options
+ for (OptionEntry e : options)
+ { // Option entries
+ addSelectItem(input, ii, e);
+ }
+ }
+ // add
+ compList.add(input);
+ }
+ else
+ { // check type
+ UIComponent comp = compList.get(0);
+ if (!(comp instanceof HtmlSelectOneMenu))
+ throw new UnexpectedReturnValueException(comp.getClass().getName(), "compList.get");
+ // cast
+ input = (HtmlSelectOneMenu)comp;
}
+ // Set Value
input.setDisabled(ii.isDisabled());
setInputValue(input, ii);
-
- compList.add(input);
}
private String getNullText(InputInfo ii)
Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextAreaInputControl.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextAreaInputControl.java?rev=1373805&r1=1373804&r2=1373805&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextAreaInputControl.java (original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextAreaInputControl.java Thu Aug 16 12:31:16 2012
@@ -25,6 +25,7 @@ import javax.faces.component.html.HtmlIn
import javax.faces.context.FacesContext;
import org.apache.empire.exceptions.InternalException;
+import org.apache.empire.exceptions.UnexpectedReturnValueException;
public class TextAreaInputControl extends InputControl
{
@@ -55,27 +56,40 @@ public class TextAreaInputControl extend
protected void createInputComponents(UIComponent parent, InputInfo ii, FacesContext context, List<UIComponent> compList)
{
HtmlInputTextarea input;
- try {
- input = inputComponentClass.newInstance();
- } catch (InstantiationException e1) {
- throw new InternalException(e1);
- } catch (IllegalAccessException e2) {
- throw new InternalException(e2);
- }
- copyAttributes(parent, ii, input);
-
- int cols = getFormatInteger(ii, FORMAT_COLS, FORMAT_COLS_ATTRIBUTE);
- if (cols>0)
- input.setCols(cols);
-
- int rows = getFormatInteger(ii, FORMAT_ROWS, FORMAT_ROWS_ATTRIBUTE);
- if (rows>0)
- input.setRows(rows);
+ if (compList.size()==0)
+ { try {
+ input = inputComponentClass.newInstance();
+ } catch (InstantiationException e1) {
+ throw new InternalException(e1);
+ } catch (IllegalAccessException e2) {
+ throw new InternalException(e2);
+ }
+ copyAttributes(parent, ii, input);
+
+ int cols = getFormatInteger(ii, FORMAT_COLS, FORMAT_COLS_ATTRIBUTE);
+ if (cols>0)
+ input.setCols(cols);
+
+ int rows = getFormatInteger(ii, FORMAT_ROWS, FORMAT_ROWS_ATTRIBUTE);
+ if (rows>0)
+ input.setRows(rows);
+
+ // add
+ compList.add(input);
+ }
+ else
+ { // check type
+ UIComponent comp = compList.get(0);
+ if (!(comp instanceof HtmlInputTextarea))
+ throw new UnexpectedReturnValueException(comp.getClass().getName(), "compList.get");
+ // cast
+ input = (HtmlInputTextarea)comp;
+ }
+ // Set Value
input.setDisabled(ii.isDisabled());
setInputValue(input, ii);
- compList.add(input);
}
/*
Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java?rev=1373805&r1=1373804&r2=1373805&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java (original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java Thu Aug 16 12:31:16 2012
@@ -37,6 +37,7 @@ import org.apache.empire.commons.StringU
import org.apache.empire.data.Column;
import org.apache.empire.data.DataType;
import org.apache.empire.exceptions.InternalException;
+import org.apache.empire.exceptions.UnexpectedReturnValueException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -74,41 +75,49 @@ public class TextInputControl extends In
protected void createInputComponents(UIComponent parent, InputInfo ii, FacesContext context, List<UIComponent> compList)
{
HtmlInputText input;
- try {
- input = inputComponentClass.newInstance();
- } catch (InstantiationException e1) {
- throw new InternalException(e1);
- } catch (IllegalAccessException e2) {
- throw new InternalException(e2);
- }
- copyAttributes(parent, ii, input);
-
- int maxLength = 0;
- DataType type = ii.getColumn().getDataType();
- switch(type)
- {
- case CHAR:
- case TEXT:
- maxLength = ((int) Math.round(ii.getColumn().getSize()));
- break;
- case DECIMAL:
- maxLength = ((int) Math.round(ii.getColumn().getSize()))+1;
- break;
- default:
- maxLength = 0;
+ if (compList.size()==0)
+ { try {
+ input = inputComponentClass.newInstance();
+ } catch (InstantiationException e1) {
+ throw new InternalException(e1);
+ } catch (IllegalAccessException e2) {
+ throw new InternalException(e2);
+ }
+ // once
+ copyAttributes(parent, ii, input);
+ // maxlength
+ int maxLength = 0;
+ DataType type = ii.getColumn().getDataType();
+ switch(type)
+ {
+ case CHAR:
+ case TEXT:
+ maxLength = ((int) Math.round(ii.getColumn().getSize()));
+ break;
+ case DECIMAL:
+ maxLength = ((int) Math.round(ii.getColumn().getSize()))+1;
+ break;
+ default:
+ maxLength = 0;
+ }
+ if (maxLength>0)
+ input.setMaxlength(maxLength);
+ // add
+ compList.add(input);
+ }
+ else
+ { // check type
+ UIComponent comp = compList.get(0);
+ if (!(comp instanceof HtmlInputText))
+ throw new UnexpectedReturnValueException(comp.getClass().getName(), "compList.get");
+ // cast
+ input = (HtmlInputText)comp;
}
- if (maxLength>0)
- input.setMaxlength(maxLength);
-
- /*
- if (ii.getColumn().getName().equals("TITLE_DE"))
- log.info(ii.getColumn().getName());
- */
+ // Set Value
input.setDisabled(ii.isDisabled()); // || ii.getColumn().isAutoGenerated()
setInputValue(input, ii);
- compList.add(input);
}
// ------- parsing -------
Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java?rev=1373805&r1=1373804&r2=1373805&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java (original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java Thu Aug 16 12:31:16 2012
@@ -47,6 +47,7 @@ import org.apache.empire.data.DataType;
import org.apache.empire.data.Record;
import org.apache.empire.data.RecordData;
import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.DBRecord;
import org.apache.empire.db.DBRowSet;
import org.apache.empire.exceptions.BeanPropertyGetException;
import org.apache.empire.exceptions.BeanPropertySetException;
@@ -324,8 +325,43 @@ public class TagEncodingHelper implement
public void encodeBegin()
{
- if (this.record != null && !(this.record instanceof Record))
- this.record = null;
+ /* nothing */
+ }
+
+ private void checkRecord()
+ {
+ // Record may change even for the same instance
+ if (this.record== null)
+ return;
+ // Check direct record property
+ Object rec = tag.getAttributes().get("record");
+ if (rec!=null)
+ { // record directly specified
+ if (rec!=this.record)
+ { // Record has changed
+ if (log.isTraceEnabled())
+ { // Debug output
+ if ((rec instanceof DBRecord) && (this.record instanceof DBRecord))
+ { // a database record change
+ String keyOld = StringUtils.toString(((DBRecord)this.record).getKeyValues());
+ String keyNew = StringUtils.toString(((DBRecord)rec).getKeyValues());
+ String rowSet = StringUtils.valueOf(((DBRecord)rec).getRowSet().getName());
+ log.trace("Changing "+tag.getClass().getSimpleName()+" record of rowset "+rowSet+" from {} to {}", keyOld, keyNew);
+ }
+ else
+ { // probably a bean change
+ log.trace("Changing "+tag.getClass().getSimpleName()+" record of class "+rec.getClass().getSimpleName());
+ }
+ }
+ // change now
+ setRecord(rec);
+ }
+ }
+ else
+ { // Invalidate if not an instance of Record
+ if (!(this.record instanceof Record))
+ this.record = null;
+ }
}
public InputControl getInputControl()
@@ -358,6 +394,8 @@ public class TagEncodingHelper implement
if (log.isDebugEnabled() && !controlType.equals(TextInputControl.NAME))
log.debug("Auto-detected field control for " + column.getName() + " is " + controlType);
}
+ // check record
+ checkRecord();
return control;
}
@@ -618,7 +656,7 @@ public class TagEncodingHelper implement
Object rec = tag.getAttributes().get("record");
if (rec == null && hasValueAttribute())
- { // See if the record is in value
+ { // See if the record is in value
return null;
}
@@ -636,11 +674,12 @@ public class TagEncodingHelper implement
}
return rec;
}
-
+
protected boolean hasValueAttribute()
{
// direct value is set (no expression)
- if (tag.getAttributes().containsKey("value"))
+ Object v = tag.getLocalValue();
+ if (v!=null) // tag.getAttributes().containsKey("value"))
return true;
// Find expression
if (hasValueExpr != null)
@@ -648,7 +687,7 @@ public class TagEncodingHelper implement
// Find expression
ValueExpression ve = findValueExpression();
if (ve != null)
- { // weiter untersuchen
+ { // check
if (log.isDebugEnabled())
{
FacesContext ctx = FacesContext.getCurrentInstance();
Modified: empire-db/trunk/pom.xml
URL: http://svn.apache.org/viewvc/empire-db/trunk/pom.xml?rev=1373805&r1=1373804&r2=1373805&view=diff
==============================================================================
--- empire-db/trunk/pom.xml (original)
+++ empire-db/trunk/pom.xml Thu Aug 16 12:31:16 2012
@@ -310,12 +310,12 @@
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
- <version>2.1.7</version>
+ <version>2.1.6</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
- <version>2.1.7</version>
+ <version>2.1.6</version>
</dependency>
<!-- Misc -->
<dependency>