Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ContainerTagPage extends WebPage {
- @SpringBean(name="containerTagService")
- private ContainerTagService containerTagService;
- public ContainerTagPage() {
- add(new FeedbackPanel("feedback"));
- // DataProvider speaks to the database
- final IDataProvider dataProvider = new IDataProvider<ContainerTag>() {
- public Iterator iterator(int first, int count) {
- return containerTagService.findAll().iterator();
- }
- public int size() {
- return containerTagService.countAll().intValue();
- }
- public IModel<ContainerTag> model(final ContainerTag tag) {
- return new LoadableDetachableModel<ContainerTag>() {
- @Override
- protected ContainerTag load() {
- return tag;
- }
- };
- }
- public void detach() {
- }
- };
- // The data view
- final DataView dataView = new DataView<ContainerTag>("list", dataProvider) {
- @Override
- protected void populateItem(Item<ContainerTag> item) {
- ContainerTag containerTag = item.getModelObject();
- item.add(new Label("id", containerTag.getId().toString()));
- item.add(new Label("name", containerTag.getName()));
- item.add(new Label("description", containerTag.getDescription()));
- item.add(new Label("active", containerTag.getActive().toString()));
- }
- @Override
- protected Item newItem(final String id, int index, final IModel model) {
- return new OddEvenItem(id, index, model);
- }
- };
- // Markup container that will be replaced with ajax
- final WebMarkupContainer wmc = new WebMarkupContainer("containerTags");
- wmc.setOutputMarkupId(true);
- wmc.add(dataView);
- add(wmc);
- // Modal window to edit the container tag
- final ModalWindow modalWindow = new ModalWindow("modalWindow");
- add(modalWindow);
- modalWindow.setPageCreator(new ModalWindow.PageCreator() {
- public Page createPage() {
- return new ManageContainerTagPage(ContainerTagPage.this, modalWindow);
- }
- });
- modalWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
- public void onClose(AjaxRequestTarget target) {
- // Refresh the list of tags with ajax
- target.addComponent(wmc);
- }
- });
- add(new AjaxLink("showModal") {
- public void onClick(AjaxRequestTarget target) {
- modalWindow.show(target);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement