I've included the "Projects" page which lists all the projects and the
AddProjectPanel which contains the logic to save a new project and go back
to the Projects page.
Maybe I should explicitly create a new Projects page in the onSubmit handler
of my AddProjectPanel? Oddly, even today - it doesn't consistently have this
problem. Just 'sometimes' when I set the response page back to the main
listing page - the list isn't updated - generally only happens the first
time ...
Maybe it is a Hibernate thing. I'm still digging.
-Luther
@RequiresAuthorization("user")
public class ProjectsPage extends MenuLayout
{
private String confirmationMessage;
public ProjectsPage()
{
this(new ResourceModel("defaultBodyTitle"));
}
public ProjectsPage(final ResourceModel bodyTitle)
{
super(bodyTitle, ProjectsPage.class);
//
// menu
//
// add
Link link = new Link("add.category.link")
{
private static final long serialVersionUID =
142459578574869903L;
@Override
public void onClick()
{
final Page next = new CategoryPage();
this.setResponsePage(next);
}
};
this.add(link);
// add project
link = new Link("add.project.link")
{
private static final long serialVersionUID =
-7045649583675065507L;
@Override
public void onClick()
{
final Page next = new AddProjectPage();
this.setResponsePage(next);
}
};
this.add(link);
// filter
final AjaxFallbackLink filterLink = new
AjaxFallbackLink("filter.projects.link")
{
private static final long serialVersionUID =
-5599387710174768323L;
@Override
public void onClick(final AjaxRequestTarget target)
{
// noop
}
};
this.add(filterLink);
//
// projects
//
final ListView categories = new ListView("categories",
this.getCategories())
{
private static final long serialVersionUID =
-2181837156022701325L;
@Override
protected void populateItem(final ListItem item)
{
final Category category = (Category) item.getModelObject();
final Label label = new Label("categoryName",
category.getName());
final Link link = new Link("categoryLink")
{
private static final long serialVersionUID =
-4816807486013970750L;
@Override
public void onClick()
{
final Page next = new CategoryPage(category);
this.setResponsePage(next);
}
};
link.add(label);
item.add(link);
final ListView projects = new ListView("projects",
ProjectsPage.this.getProjects(category))
{
private static final long serialVersionUID =
-2181837156022701325L;
@Override
protected void populateItem(final ListItem item)
{
final Project project = (Project)
item.getModelObject();
// project
PageParameters pars = new PageParameters();
String id = project.getId().toString();
pars.add(ProjectPage.Params.ID, id);
BookmarkablePageLink link = new
BookmarkablePageLink("projectLink", ProjectPage.class, pars);
String val = project.getName();
link.add(new Label("projectName", val));
item.add(link);
// acronym
val = project.getAcronym();
item.add(new Label("projectAcronym", val));
// resource
final Resource res = project.getLead();
if (res != null)
{
id = Long.toString(res.getId());
pars = new PageParameters();
pars.add(ResourcePage.Params.ID, id);
val = project.getLead().getUserName();
}
link = new BookmarkablePageLink("projectLeadLink",
ResourcePage.class, pars);
link.add(new Label("projectLead", val));
item.add(link);
// url
val = project.getUrl();
item.add(new Label("projectUrl", val));
}
};
item.add(projects);
}
};
this.add(categories);
}
/**
* @return the confirmationMessage
*/
public String getConfirmationMessage()
{
return this.confirmationMessage;
}
/**
* @param confirmationMessage
* the confirmationMessage to set
*/
public void setConfirmationMessage(final String confirmationMessage)
{
this.confirmationMessage = confirmationMessage;
}
private List<Category> getCategories()
{
final List<Category> categories =
ServiceLocator.getPersistenceService().findAll(Category.class);
return categories;
}
@SuppressWarnings("unchecked")
private List<Project> getProjects(final Category category)
{
final PersistenceService ps =
ServiceLocator.getPersistenceService();
final SimpleExpression clause = Restrictions.eq("category",
category);
final Criteria query = ps.createCriteria(Project.class);
query.add(clause);
final List<Project> projects = query.list();
return projects;
}
}
public class AddProjectPanel extends Panel
{
private static final long serialVersionUID = 6620944941617610148L;
public AddProjectPanel(final String id)
{
super(id);
final Form form = new AddProjectForm("addProjectForm");
this.add(form);
}
private static class AddProjectForm extends Form
{
private static final long serialVersionUID = 4430646734993360357L;
private final Project project;
public AddProjectForm(final String id)
{
super(id);
this.project = new Project();
this.setModel(new CompoundPropertyModel(this.project));
final FeedbackPanel feedbackPanel = new
ErrorFeedbackPanel("feedbackPanel");
this.add(feedbackPanel);
// acronym
this.add(new TextField("acronym").setRequired(true));
// category
final IModel categoryModel = new PropertyModel(this.project,
"category");
IModel detachableModel = new LoadableDetachableModel()
{
private static final long serialVersionUID =
-7673902927079196813L;
@Override
protected Object load()
{
final List<Category> categories =
ServiceLocator.getPersistenceService().findAll(Category.class);
return categories;
}
};
ChoiceRenderer cr = new ChoiceRenderer("name", "id");
DropDownChoice ddc = new DropDownChoice("category",
categoryModel, detachableModel, cr);
ddc.setRequired(true);
this.add(ddc);
// lead
final IModel leadModel = new PropertyModel(this.project,
"lead");
detachableModel = new LoadableDetachableModel()
{
private static final long serialVersionUID =
-7673902927079196813L;
@Override
protected Object load()
{
final List<Resource> people =
ServiceLocator.getPersistenceService().findAll(Resource.class);
return people;
}
};
cr = new ChoiceRenderer("fullName", "id");
ddc = new DropDownChoice("lead", leadModel, detachableModel,
cr);
this.add(ddc);
this.add(new TextField("name").setRequired(true));
this.add(new TextField("url"));
final Button submit = new Button("submit", new
ResourceModel("addSubmitLabel"));
this.add(submit);
}
/**
* @see org.apache.wicket.markup.html.form.Form#onSubmit()
*/
@Override
protected final void onSubmit()
{
// TODO - validate if necessary, handle errors
ServiceLocator.getPersistenceService().saveOrUpdate(this.project);
this.setResponsePage(ProjectsPage.class);
}
}
}
On Sun, Apr 5, 2009 at 3:00 AM, TH Lim <[email protected]> wrote:
>
> For starter, I would remove the filter and Hibernate codes, to localize the
> problem to Wicket.
>
> It helps if you could provide a snippet of the code or better if u can
> provide working code of the problem u encounter.
>
>
>
> luther.baker wrote:
> >
> > I have a page that displays a list of Titles.
> >
> > I have a few links off this page that take you to a second page where you
> > can either
> >
> > a) create a new Title
> > b) edit an existing Title
> > c) delete an existing Title
> >
> > The onClick handlers for b and c create the destination page with the
> > selected object where as option a simply prepares a blank form for the
> > user
> > to type in. In this simplistic case, a Title is simply a bare-bones
> Entity
> > with just a "Long id" and a "String name".
> >
> > All is fine -- except on the very first action. The very first meaning,
> > right after I rebuild and restart the application. After ADDING a new
> > Title
> > - the onSubmit handler of that page simply sets the response page which
> is
> > a
> > POJO page that takes no arguments.
> >
> > That original page comes up - but the listing of Titles is always missing
> > the very last one I entered. If I refresh the screen - all is well. If I
> > add
> > 25 more Titles, they always show up right away - ie: as soon as page 2
> > directs me back to page 1. But for some reason, the very first time - the
> > new entry doesn't show up upon returning the first listing page.
> >
> > I am using some nominal Ajax on the 2nd page to go back and forth between
> > viewing and editing ... but the final submit is always a full refresh
> back
> > to the original page. I recently added b and c ... and oddly enough ...
> > the
> > edits or deletes do not show up on the first page ... the first time
> after
> > a
> > rebuild and restart ... but then work consistently everytime after that.
> >
> > Thoughts? Any quick thoughts as to what migh be going on in my env? For
> > what
> > its worth - I have an outer filter that is creating and commiting
> > Hibernate
> > transactions and they are firing as expected ...
> >
> > Thanks in advance,
> >
> > -Luther
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Cache-oddity-...-maybe-tp22889814p22891364.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>