Hello,
let me outline a problem I have. If you won't get much from my ramblings
I'll try to provide a simplified ready-to-run example:
I have a list of "thermometers":
public ThermometersPanel( String id, IModel model ) {
super( id, model );
add( new RefreshingView( "list", new PropertyModel( getModel(),
"thermometers" ) ) {
@SuppressWarnings("unchecked")
@Override
protected Iterator getItemModels() {
System.out.println( "get item models called" );
Map<Integer, Thermometer> thermometers =
(Map<Integer, Thermometer>) getModelObject();
return new ModelIteratorAdapter(
thermometers.values().iterator() ) {
@Override
protected IModel model( Object obj ) {
return new ThermometerModel(
(Thermometer) obj );
}
};
}
@Override
protected void populateItem( final Item item ) {
item.add( new Link( "edit", item.getModel() ) {
@Override
public void onClick() {
setResponsePage( new
ThermometerPage( getModel(), getPage() ) );
}
}.add( new Label( "name", new PropertyModel(
item.getModel(), "name" ) ) ) );
item.add( new ThermometerSensorPanel(
"lowLevelSensorPanel", new PropertyModel( item.getModel(),
"lowLevelSensor" ), new
ResourceModel( "lowLevelActions" ) ) );
item.add( new ThermometerSensorPanel(
"highLevelSensorPanel", new PropertyModel( item.getModel(),
"highLevelSensor" ), new
ResourceModel( "highLevelActions" ) ) );
}
} );
}
All models are loadable detachable (hibernate based), storing only
entity id.
The most important part here is:
item.add( new Link( "edit", item.getModel() ) {
@Override
public void onClick() {
setResponsePage( new
ThermometerPage( getModel(), getPage() ) );
}
}.add( new Label( "name", new PropertyModel(
item.getModel(), "name" ) ) ) );
Here, when "edit" clicked I would like to show edit page and after
submission return to the list. So ThermometerPage gets currentPage as
parameter.
Unfortunately one of edit operations in ThermometerPage is delete:
Button deleteButton = new Button( "delete", new ResourceModel( "delete" ) ) {
@Override
public void onSubmit() {
UnitConfig unitConfig = unitConfigService.getCurrentUnitConfig(
UserUtils.getCurrentUnit() );
unitConfigService.removeThermometer( unitConfig,
(Thermometer) getForm().getModelObject() );
setResponsePage( ThermometerPage.this.back );
}
@Override
public boolean isEnabled() {
return ( (Thermometer) getForm().getModelObject() ).getId() !=
null;
}
};
deleteButton.setDefaultFormProcessing( false );
this.add( deleteButton );
When I click delete button this throws:
org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
[com.mobilebox.indigo.model.Thermometer#5]
at
org.hibernate.impl.SessionFactoryImpl$1.handleEntityNotFound(SessionFactoryImpl.java:377)
at
org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:79)
at
org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:68)
at org.hibernate.Hibernate.initialize(Hibernate.java:306)
at
org.springframework.orm.hibernate3.HibernateTemplate.initialize(HibernateTemplate.java:590)
at
com.mobilebox.persistence.GenericHibernateDaoSupport.findById(GenericHibernateDaoSupport.java:53)
at
com.mobilebox.indigo.service.impl.UnitConfigServiceImpl.findThermometerById(UnitConfigServiceImpl.java:165)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:296)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:177)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy32.findThermometerById(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.apache.wicket.proxy.LazyInitProxyFactory$JdkHandler.invoke(LazyInitProxyFactory.java:402)
at org.apache.wicket.proxy.$Proxy43.findThermometerById(Unknown Source)
at
com.mobilebox.indigo.configurator.model.ThermometerModel.loadEntity(ThermometerModel.java:51)
at
com.mobilebox.indigo.configurator.model.ThermometerModel.loadEntity(ThermometerModel.java:1)
at
com.mobilebox.indigo.common.model.PersistentEntityModel.load(PersistentEntityModel.java:56)
at
com.mobilebox.indigo.common.model.PersistentEntityModel.load(PersistentEntityModel.java:1)
at
org.apache.wicket.model.LoadableDetachableModel.getObject(LoadableDetachableModel.java:111)
at
org.apache.wicket.model.AbstractPropertyModel.getTarget(AbstractPropertyModel.java:186)
at
org.apache.wicket.model.AbstractPropertyModel.getObject(AbstractPropertyModel.java:107)
at org.apache.wicket.Component.getModelObject(Component.java:1293)
at
com.mobilebox.indigo.configurator.panel.thermometer.ThermometersPanel$ThermometerSensorPanel.isVisible(ThermometersPanel.java:84)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
the underlined panel is list item's child (see first code snippet)
which clearly mean the list of thermometers hasn't been updated and now
one of thermometer models references an entity that does not exist anymore.
How can I inform the page I am returning to that it's model is no longer
valid? Why doesn't the RefreshingView simply refresh itself from the model?
Please advise.
--
Leszek Gawron
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]