t6nn
5/3/2012 - 9:06 PM

Tapestry persistence and mutable objects

Tapestry persistence and mutable objects

public class PersistenceTest {

	@Persist(PersistenceConstants.SESSION)
	private List<String> state;

	public List<String> getState() {
		if(state == null) {
			state = new ArrayList<String>();
		}
		return state;
	}

	void onActionFromChangeState() {
		getState().add(UUID.randomUUID().toString());
	}
}
public class PersistenceTest {

	@Persist(PersistenceConstants.CLIENT)
	private List<String> state;
	
	// ... snipped ...
}
public class PersistenceTest {

	// ... snipped ...

	void onActionFromChangeState() {
		getState().add(UUID.randomUUID().toString());
		state = state; // <-- what a lovely hack!
	}
}