I'm trying to add a new TablePages control that lets you type in the page
you want to go to in a single textfield form.
There seems to be a common pattern with the Table subcomponents to grab the
TableModel through the TableView "parent" control, and I'm running into
problems getting that control in different circumstances.
First, when posting the new page # from the form the code:
public ITableModelSource getTableModelSource()
{
IRequestCycle objCycle = getPage().getRequestCycle();
ITableModelSource objSource =
(ITableModelSource) objCycle.getAttribute(
ITableModelSource.TABLE_MODEL_SOURCE_ATTRIBUTE);
if (objSource == null)
throw new ApplicationRuntimeException(
"The component "
+ getId()
+ " must be contained within an ITableModelSource
component, such as TableView",
this,
null,
null);
return objSource;
}
Fails - I assume because we are in 'rewind' phase? I saw that the links the
old TablePages create store both the page number and a ComponentAddress of
the TableView, so I added a hidden field:
<input jwcid="@Hidden"
value="ognl:tableComponentAddress"/>
and a set/getTableComponentAddress()
public ComponentAddress getTableComponentAddress()
{
ComponentAddress objAddress = new
ComponentAddress(getTableModelSource());
return objAddress;
}
public void setTableComponentAddress(ComponentAddress componentAddress)
{
this.tableComponentAddress = componentAddress;
}
and then I can use this.tableComponentAddress in my form listener instead of
getTableModelSource().
Is there a better way to do this? Seems incredibly hacky to me.
Now I have a problem with Validators. I want to make sure you can't type in
a page # in the form that is outside the range:
Because the Max Validator needs to run off an ognl property (pageCount from
TablePages) I need to add it as a bean to the component spec:
<bean name="pageFormValidator" class="org.apache.tapestry.form.validator.Max
">
<set name="max" value="ognl:pageCount"/>
</bean>
Works fine when initially loaded. However I'm running into another rewind
problem on form post, because it runs the validator, and getPageCount()
relies on getTableModelSource() again, which is unavailable.
Does anyone have any suggestions on getting the "parent" TableView component
in this scenario?
Here's the relevant part of stack trace:
-
org.apache.tapestry.contrib.table.components.AbstractTableViewComponent.getTableModelSource
(AbstractTableViewComponent.java:40)
- com.zzz.tapestry.table.TablePager.getPageCount(TablePager.java:79)
- sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:39)
- sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:25)
- java.lang.reflect.Method.invoke(Method.java:585)
- ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:491)
- ognl.OgnlRuntime.getMethodValue(OgnlRuntime.java:904)
- ognl.ObjectPropertyAccessor.getPossibleProperty(
ObjectPropertyAccessor.java:54)
- ognl.ObjectPropertyAccessor.getProperty(ObjectPropertyAccessor.java:122)
- ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1616)
- ognl.ASTProperty.getValueBody(ASTProperty.java:96)
- ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
- ognl.SimpleNode.getValue(SimpleNode.java:210)
- ognl.Ognl.getValue(Ognl.java:333)
- ognl.Ognl.getValue(Ognl.java:310)
-
org.apache.tapestry.services.impl.ExpressionEvaluatorImpl.readCompiled
(ExpressionEvaluatorImpl.java:91)
-
$ExpressionEvaluator_10829f019b9.readCompiled($ExpressionEvaluator_10829f019b9.java)
- org.apache.tapestry.binding.ExpressionBinding.resolveExpression(
ExpressionBinding.java:110)
- org.apache.tapestry.binding.ExpressionBinding.getObject(
ExpressionBinding.java:103)
- org.apache.tapestry.binding.AbstractBinding.getObject(
AbstractBinding.java:87)
- org.apache.tapestry.bean.BindingBeanInitializer.setBeanProperty(
BindingBeanInitializer.java:76)
- org.apache.tapestry.bean.BeanProvider.instantiateBean(
BeanProvider.java:241)
- org.apache.tapestry.bean.BeanProvider.getBean(BeanProvider.java:158)
- org.apache.tapestry.binding.BeanBinding.getObject(BeanBinding.java:64)
- org.apache.tapestry.binding.AbstractBinding.getObject(
AbstractBinding.java:87)
- $TextField_15.getValidators($TextField_15.java)
-
org.apache.tapestry.form.ValidatableFieldSupportImpl.getValidatorsIterator
(ValidatableFieldSupportImpl.java:51)
- org.apache.tapestry.form.ValidatableFieldSupportImpl.validate(
ValidatableFieldSupportImpl.java:83)
-
$ValidatableFieldSupport_10829f019c1.validate($ValidatableFieldSupport_10829f019c1.java)
- org.apache.tapestry.form.TextField.rewindFormComponent(
TextField.java:84)
Thanks