Re: Error: Not detached model found

2015-11-18 Thread leejoyprakash
Thanks Sven, it worked ... 

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Error-Not-detached-model-found-tp4672624p4672642.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Error: Not detached model found

2015-11-17 Thread leejoyprakash
I am getting the following error while working with Wicket 6.19:

 Caused by:
org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream$ObjectCheckException:
Not detached model found!
A problem occurred while checking object with type:
com.test.web.components.CurrentUserModel
Field hierarchy is:
   [class=com.test.web.base.pages.HomePage, path=0]
private java.lang.Object 
org.apache.wicket.MarkupContainer.children
[class=[Ljava.lang.Object;]
  java.lang.Object org.apache.wicket.Component.data[1]
[class=com.test.web.HeaderPanel, path=0:headerPanel]
private java.lang.Object 
org.apache.wicket.MarkupContainer.children
[class=[Ljava.lang.Object;]
  private java.lang.String
org.apache.wicket.markup.html.image.resource.LocalizedImageResource.variation[2]
[class=com.test.web.LoginStatusPanel, path=0:headerPanel:loginStatusPanel]
java.lang.Object 
org.apache.wicket.Component.data
[class=com.test.web.components.CurrentUserModel] <- field that is
causing the problem

Code:

@RequireHttps
public class HomePage extends WebPage {
private HeaderPanel headerPanel;
private LoginStatusPanel loginStatusPanel;
private MenuPanel menuPanel;

public HomePage(String id) {
super();
initialize();
}

public HomePage(String id, PageParameters parameters) {
super(parameters);
initialize();
}

@Override
protected void onInitialize() {
Request request = RequestCycle.get().getRequest();
if (request instanceof ServletWebRequest)
{
ServletWebRequest wr = (ServletWebRequest) 
request;
HttpSession session = 
wr.getContainerRequest().getSession();
if (session != null) {
}
}
super.onInitialize();
}

public String getApplicationId(){
return applicationId;
}

private void initialize() {
add(headerPanel = new HeaderPanel("headerPanel"));
headerPanel.add(loginStatusPanel = new
LoginStatusPanel("loginStatusPanel"));
headerPanel.add(menuPanel = new MenuPanel("menuPanel"));
}
}

public class HeaderPanel extends Panel {
private Label headerTitleLbl;

public HeaderPanel(String id) {
super(id);
add(headerTitleLbl=new Label("headerTitle",
WebApplication.getAppTitle()));
headerTitleLbl.setOutputMarkupId(true);
}
}

public class LoginStatusPanel extends Panel {

public LoginStatusPanel(String id) {
super(id, new CurrentUserModel()); // Line 1
}

protected void onInitialize() {
IModel authModel = 
(IModel)
getDefaultModel();
final Authentication auth = authModel.getObject();

if (auth != null && auth.isAuthenticated() && !(auth 
instanceof
AnonymousAuthenticationToken))
{
Fragment fragment = new Fragment("frag", 
"loggedInFragment", this);
Label status;
fragment.add(status = new Label("status", 
"Logged in as "));
fragment.add(new Label("userId", new 
PropertyModel(authModel,
"name")));
add(fragment);
}
else
{
Fragment fragment = new Fragment("frag", 
"loggedOutFragment", this);
fragment.add(new Label("status", "Logged out"));
fragment.add(new ExternalLink("login", 
"/LoginPage", "Log In"));
add(fragment);
}
super.onInitialize();
}
}

public class MenuPanel extends Panel {
public MenuPanel(String id) {
super(id);
add(new MenuPanel("menu", 
WebApplication.getMenuList()));
}
}

public class CurrentUserModel extends
LoadableDetachableModel {

Re: Error: Not detached model found

2015-11-17 Thread leejoyprakash
Hello Sven,

This error is thrown in my test case. I think my basic understanding about
the way wicket works is wrong.

In my CustomerWicketTester class(which inherits from WicketTester), I have
overridden the method as follows:

@Override
public void executeAjaxEvent(final Component component, final String event)
{
serializationChecker();
super.executeAjaxEvent(component, event);
}

So from my test case while calling 'wicketTester.clickTreeNode("Users");'
which intern calls executeAjaxEvent throws the above error.

Following is my custom JavaSerializer class and the method which uses it:

public void serializationChecker(){
javaSerializer.serialize(getLastRenderedPage());
}

private class CustomJavaSerializer extends JavaSerializer {

private final String appKey;
public CustomJavaSerializer(String applicationKey) {
super(applicationKey);
this.appKey = applicationKey;
}

@Override
protected ObjectOutputStream newObjectOutputStream(OutputStream out) 
throws
IOException {
IObjectChecker checker = new NotDetachedModelChecker();
IObjectChecker checker2 = new
SerializableChecker.ObjectSerializationChecker();
return new CheckingObjectOutputStream(out, checker, checker2);
 }

@Override
public byte[] serialize(Object object) throws WicketRuntimeException {
try
{
final ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream oos = null;
try
{
oos = newObjectOutputStream(out);
oos.writeObject(appKey);
oos.writeObject(object);
}
finally
{
try
{
IOUtils.close(oos);
}
finally
{
out.close();
}
}
return out.toByteArray();
}
catch (Exception e)
{
throw new WicketRuntimeException("Error serializing object " +
object.getClass() + " [object=" + object + "]", e);
}
}
}


--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Error-Not-detached-model-found-tp4672624p4672632.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org