This is because you are not using the model correctly.
This line takes the value of the panel model object , as it was set during construction , and uses it to create the component model.
add(new Label("messageText", new PropertyModel<Message>(getModelObject(), Message.BODY_FIELD)));
Even worse, when you click on the link, the panel is assigned a new model:
MessagePanel.this.setDefaultModel(new JPAEntityModel<Message>(nextMessage));
But this, obviously, does not affect the label model, since it is already set to the original value.
So, there are two things that need to be changed in order to make it work. First, your shortcut model should use your panel model directly:
new Model<Message>() { @Override public Message getObject() { return MessagePanel.this.getModelObject().getMessage();
(Note: the code above is not necessarily the best solution, but it is a working solution that demonstrates how models can be used dynamically.)
And ideally, you should not replace the model when you click on the link, just change the model object. If you need a custom model class ( JPAEntityModel ), you still should not accept the pre-constructed model in the panel constructor, but only the first message object. The reason the current implementation does not apply the use of JPAEntityModel from the very beginning, only after the first click of the link.