Example usage for org.apache.wicket.markup.html.form Form setOutputMarkupId

List of usage examples for org.apache.wicket.markup.html.form Form setOutputMarkupId

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form Form setOutputMarkupId.

Prototype

public final Component setOutputMarkupId(final boolean output) 

Source Link

Document

Sets whether or not component will output id attribute into the markup.

Usage

From source file:guru.mmp.application.web.template.pages.UserDirectoryAdministrationPage.java

License:Apache License

/**
 * Constructs a new <code>UserDirectoryAdministrationPage</code>.
 */// w w  w . j a  v  a 2 s  . c om
public UserDirectoryAdministrationPage() {
    super("User Directories");

    try {
        /*
         * The table container, which allows the table and its associated navigator to be updated
         * using AJAX.
         */
        WebMarkupContainer tableContainer = new WebMarkupContainer("tableContainer");
        tableContainer.setOutputMarkupId(true);
        add(tableContainer);

        // The dialog used to confirm the removal of a user directory
        RemoveDialog removeDialog = new RemoveDialog(tableContainer);
        add(removeDialog);

        // The dialog used to select the type of user directory being added
        AddDialog selectUserDirectoryTypeDialog = new AddDialog();
        add(selectUserDirectoryTypeDialog);

        // The "addLink" used to add a new user directory
        AjaxLink<Void> addLink = new AjaxLink<Void>("addLink") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onClick(AjaxRequestTarget target) {
                selectUserDirectoryTypeDialog.show(target);
            }
        };
        tableContainer.add(addLink);

        FilteredUserDirectoryDataProvider dataProvider = new FilteredUserDirectoryDataProvider();

        // The "filterForm" form
        Form<Void> filterForm = new Form<>("filterForm");
        filterForm.setMarkupId("filterForm");
        filterForm.setOutputMarkupId(true);

        // The "filter" field
        TextField<String> filterField = new TextField<>("filter", new PropertyModel<>(dataProvider, "filter"));
        filterForm.add(filterField);

        // The "filterButton" button
        Button filterButton = new Button("filterButton") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onSubmit() {
            }
        };
        filterButton.setDefaultFormProcessing(true);
        filterForm.add(filterButton);

        // The "resetButton" button
        Button resetButton = new Button("resetButton") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onSubmit() {
                dataProvider.setFilter("");
            }
        };
        filterForm.add(resetButton);

        tableContainer.add(filterForm);

        // The user directory data view
        DataView<UserDirectory> dataView = new DataView<UserDirectory>("userDirectory", dataProvider) {
            private static final long serialVersionUID = 1000000;

            @Override
            protected void populateItem(Item<UserDirectory> item) {
                item.add(new Label("name", new PropertyModel<String>(item.getModel(), "name")));
                item.add(new Label("type", new PropertyModel<String>(item.getModel(), "type.name")));

                // The "updateLink" link
                Link<Void> updateLink = new Link<Void>("updateLink") {
                    private static final long serialVersionUID = 1000000;

                    @Override
                    public void onClick() {
                        UpdateUserDirectoryPage page = new UpdateUserDirectoryPage(getPageReference(),
                                item.getModel());

                        setResponsePage(page);
                    }
                };
                item.add(updateLink);

                // The "removeLink" link
                AjaxLink<Void> removeLink = new AjaxLink<Void>("removeLink") {
                    private static final long serialVersionUID = 1000000;

                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        UserDirectory userDirectory = item.getModelObject();

                        if (userDirectory != null) {
                            removeDialog.show(target, userDirectory);
                        } else {
                            target.add(tableContainer);
                        }
                    }
                };
                item.add(removeLink);
            }
        };
        dataView.setItemsPerPage(10);
        dataView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance());
        tableContainer.add(dataView);

        tableContainer.add(new PagingNavigator("navigator", dataView));
    } catch (Throwable e) {
        throw new WebApplicationException("Failed to initialise the UserDirectoryAdministrationPage", e);
    }
}

From source file:guru.mmp.application.web.template.pages.UserGroupsPage.java

License:Apache License

/**
 * Constructs a new <code>UserGroupsPage</code>.
 *
 * @param previousPage    the previous page
 * @param userDirectoryId the Universally Unique Identifier (UUID) used to uniquely identify the
 *                        user directory
 * @param username        the username identifying the user
 *//*from  w w  w .  j ava  2  s .co  m*/
UserGroupsPage(PageReference previousPage, UUID userDirectoryId, String username) {
    super("User Groups", username);

    try {
        /*
         * The table container, which allows the table and its associated navigator to be updated
         * using AJAX.
         */
        WebMarkupContainer tableContainer = new WebMarkupContainer("tableContainer");
        tableContainer.setOutputMarkupId(true);
        add(tableContainer);

        // The "backLink" link
        Link<Void> backLink = new Link<Void>("backLink") {
            private static final long serialVersionUID = 1000000;

            @Override
            public void onClick() {
                setResponsePage(previousPage.getPage());
            }
        };
        tableContainer.add(backLink);

        // The "addUserToGroupForm" form
        DropDownChoice<String> groupNameField = new DropDownChoice<>("groupName",
                new PropertyModel<>(this, "groupName"), getGroupOptions(userDirectoryId, username));

        groupNameField.setRequired(true);

        Form<Void> addUserToGroupForm = new Form<Void>("addUserToGroupForm") {
            private static final long serialVersionUID = 1000000;

            @Override
            protected void onSubmit() {
                WebSession session = getWebApplicationSession();

                try {
                    securityService.addUserToGroup(userDirectoryId, username, groupName);

                    logger.info(String.format(
                            "User (%s) added the user (%s) to the group (%s) for the user directory (%s)",
                            session.getUsername(), username, groupName, userDirectoryId));

                    groupNameField.setChoices(getGroupOptions(userDirectoryId, username));
                    groupNameField.setModelObject(null);
                } catch (Throwable e) {
                    logger.error(String.format(
                            "Failed to add the user (%s) to the group (%s) for the user directory (%s): %s",
                            username, groupName, userDirectoryId, e.getMessage()), e);

                    UserGroupsPage.this.error(
                            String.format("Failed to add the user %s to the group %s", username, groupName));
                }
            }
        };

        addUserToGroupForm.setMarkupId("addUserToGroupForm");
        addUserToGroupForm.setOutputMarkupId(true);
        tableContainer.add(addUserToGroupForm);

        addUserToGroupForm.add(groupNameField);

        // The group data view
        GroupsForUserDataProvider dataProvider = new GroupsForUserDataProvider(userDirectoryId, username);

        DataView<Group> dataView = new DataView<Group>("group", dataProvider) {
            private static final long serialVersionUID = 1000000;

            @Override
            protected void populateItem(Item<Group> item) {
                Group group = item.getModelObject();

                String name = group.getGroupName();

                item.add(new Label("name", Model.of(name)));

                // The "removeLink" link
                Link<Void> removeLink = new Link<Void>("removeLink") {
                    private static final long serialVersionUID = 1000000;

                    @Override
                    public void onClick() {
                        WebSession session = getWebApplicationSession();

                        Group group = item.getModelObject();

                        try {
                            securityService.removeUserFromGroup(userDirectoryId, username,
                                    group.getGroupName());

                            logger.info(String.format(
                                    "User (%s) removed the user (%s) from the group (%s) for the user directory (%s)",
                                    session.getUsername(), username, group.getGroupName(), userDirectoryId));

                            groupNameField.setChoices(getGroupOptions(userDirectoryId, username));
                            groupNameField.setModelObject(null);
                        } catch (Throwable e) {
                            logger.error(String.format(
                                    "Failed to remove the user (%s) from the group (%s) for the user directory (%s)"
                                            + ": %s",
                                    username, group.getGroupName(), userDirectoryId, e.getMessage()), e);

                            UserGroupsPage.this
                                    .error(String.format("Failed to remove the user %s from the group %s",
                                            username, group.getGroupName()));
                        }
                    }
                };
                item.add(removeLink);
            }
        };

        dataView.setItemsPerPage(10);
        dataView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance());
        tableContainer.add(dataView);

        tableContainer.add(new PagingNavigator("navigator", dataView));
    } catch (Throwable e) {
        throw new WebApplicationException("Failed to initialise the UserGroupsPage", e);
    }
}

From source file:hsa.awp.admingui.edit.AbstractCampaign.java

License:Open Source License

/**
 * Renders the form page. This should be called after setting the {@link Campaign} to work with.
 */// w  w  w  .  j a  va 2  s. c o m
protected void renderPage() {

    form = new Form<Object>("form");
    form.setOutputMarkupId(true);

    studyCourseListSelector = new StudyCourseListSelectorPanel("studyCourseListSelector", getStudyCourseItems(),
            getSelectedStudyCourseItems());
    form.add(studyCourseListSelector);

    // add ProcedureListSelector
    procedureListSelector = new ProcedureListSelectorPanel("procedureListSelector", getProcedureModelItems(),
            getProcedureSelectedItems());
    form.add(procedureListSelector);

    // add EventListSelector
    eventListSelector = new EventListSelectorPanel("eventListSelector", getEventModelItems(),
            getEventSelectedItems());
    final WebMarkupContainer eventSelectorBox = new WebMarkupContainer("eventSelectorBox");
    eventSelectorBox.setOutputMarkupId(true);
    eventSelectorBox.add(eventListSelector);
    form.add(eventSelectorBox);

    feedbackPanel = new FeedbackPanel("feedbackPanel");
    feedbackPanel.setOutputMarkupId(true);

    form.add(feedbackPanel);

    endShow = new DateTimeField("endShow", new Model<Date>());
    endShow.setModelObject(getCampaign().getEndShow().getTime());

    startShow = new DateTimeField("startShow", new Model<Date>());
    startShow.setModelObject(getCampaign().getStartShow().getTime());

    email = new TextField<String>("email", new Model<String>());
    email.setModelObject(getCampaign().getCorrespondentEMail());
    email.setRequired(true);
    email.add(EmailAddressValidator.getInstance());

    name = new TextField<String>("name", new Model<String>());
    name.setModelObject(getCampaign().getName());

    detailText = new TextArea("detailText", new Model<String>());
    detailText.setModelObject(getCampaign().getDetailText());

    List<Term> termChoices = controller.getTermsByMandator(getSession());

    DropDownChoice<Term> termDropDown = new DropDownChoice<Term>("term", termModel, termChoices,
            new IChoiceRenderer<Term>() {

                @Override
                public Object getDisplayValue(Term object) {
                    if (object != null) {
                        return object.toString();
                    } else {
                        return "Alle";
                    }
                }

                @Override
                public String getIdValue(Term object, int index) {
                    if (object != null) {
                        return object.toString();
                    } else {
                        return String.valueOf(index);
                    }
                }
            });

    termDropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            eventSelectorBox.remove(eventListSelector);
            eventListSelector = new EventListSelectorPanel("eventListSelector", getEventModelItems(),
                    getEventSelectedItems());
            eventSelectorBox.add(eventListSelector);
            target.addComponent(eventSelectorBox);
        }
    });

    form.add(endShow);
    form.add(startShow);
    form.add(name);
    form.add(email);
    form.add(detailText);
    form.add(termDropDown);

    add(form);

    form.add(new AjaxButton("submit") {
        /**
         * unique serialization id.
         */
        private static final long serialVersionUID = -545654550066678262L;

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {

            target.addComponent(feedbackPanel);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            target.addComponent(form);
            target.addComponent(feedbackPanel);

            List<String> errors = AbstractCampaign.this.validate(name.getModelObject(),
                    eventListSelector.getSelected(), procedureListSelector.getSelected(),
                    startShow.getModelObject(), endShow.getModelObject(),
                    studyCourseListSelector.getSelected());
            if (errors.size() == 0) {
                Calendar calStartShow = Calendar.getInstance();
                calStartShow.setTime(startShow.getModelObject());

                Calendar calEndShow = Calendar.getInstance();
                calEndShow.setTime(endShow.getModelObject());

                workResult(name.getModelObject(), email.getModelObject(), eventListSelector.getSelected(),
                        procedureListSelector.getSelected(), calStartShow, calEndShow,
                        studyCourseListSelector.getSelected(), (String) detailText.getModelObject());
                //TODO: Sprache
                feedbackPanel.info(getSuccessText());
                this.setVisible(false);
            } else {
                for (String error : errors) {
                    feedbackPanel.fatal(error);
                }
            }
        }
    });
}

From source file:hsa.awp.admingui.edit.DrawProcedurePanel.java

License:Open Source License

/**
 * Constructor for {@link DrawProcedurePanel}. This is the setup for the
 * panel and here are all components registered.
 *
 * @param id       wicket:id which connects markup with code.
 * @param drawProc the draw procedure which have to be edit
 *//* www.j  a  v a 2  s  .com*/
public DrawProcedurePanel(String id, final DrawProcedure drawProc) {

    super(id);

    final DrawProcedure drawProcedure;

    if (drawProc == null) {
        drawProcedure = DrawProcedure.getInstance(controller.getActiveMandator(getSession()));
    } else {
        drawProcedure = drawProc;
    }

    CompoundPropertyModel<DrawProcedure> cpm = new CompoundPropertyModel<DrawProcedure>(drawProcedure);
    final Form<Object> form = new Form<Object>("form");
    form.setDefaultModel(cpm);
    feedbackPanel.setOutputMarkupId(true);
    form.setOutputMarkupId(true);
    // TODO Sprache:
    add(panelLabel.setDefaultModel(new Model<String>("Los-Prozedur bearbeiten")));

    // add validators
    drawName.setRequired(true);
    startDate.setRequired(true);
    endDate.setRequired(true);
    drawDate.setRequired(true);
    maximumPriorityListItems.setRequired(true);
    maximumPriorityLists.setRequired(true);

    // get&add default values
    drawName.setDefaultModel(cpm.bind("name"));
    startDate.setModelObject(drawProcedure.getStartDate().getTime());
    endDate.setModelObject(drawProcedure.getEndDate().getTime());
    drawDate.setModelObject(drawProcedure.getDrawDate().getTime());
    maximumPriorityListItems.setModelObject(Integer.toString(drawProcedure.getMaximumPriorityListItems()));
    maximumPriorityLists.setModelObject(Integer.toString(drawProcedure.getMaximumPriorityLists()));

    if (drawProcedure.getRuleBased() == 0)
        selected = TYPES.get(0);
    else if (drawProcedure.getRuleBased() == 1)
        selected = TYPES.get(1);

    form.add(drawName);

    form.add(startDate);

    form.add(endDate);

    form.add(drawDate);

    form.add(maximumPriorityListItems);

    form.add(maximumPriorityLists);

    form.add(ruleBasedTypes);

    form.add(new AjaxButton("submit") {
        private static final long serialVersionUID = -6537464906539587006L;

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {

            target.addComponent(feedbackPanel);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            target.addComponent(form);
            target.addComponent(feedbackPanel);

            Calendar sD = Calendar.getInstance();
            sD.setTime(startDate.getModelObject());

            Calendar eD = Calendar.getInstance();
            eD.setTime(endDate.getModelObject());

            Calendar dD = Calendar.getInstance();
            dD.setTime(drawDate.getModelObject());

            try {
                DrawProcedure draw = controller.getDrawProcedureById(drawProcedure.getId());
                if (draw == null) {
                    draw = drawProcedure;
                }

                if (selected == TYPES.get(0))
                    draw.setRuleBased(0);
                else if (selected == TYPES.get(1))
                    draw.setRuleBased(1);

                draw.setInterval(sD, eD);
                draw.setDrawDate(dD);
                draw.setMaximumPriorityListItems(Integer.valueOf(maximumPriorityListItems.getModelObject()));
                draw.setMaximumPriorityLists(Integer.valueOf(maximumPriorityLists.getModelObject()));

                // controller writeDrawProcedure to DB

                controller.writeDrawProcedure(draw);
                // setResponsePage(new OnePanelPage(new
                // ConfirmedEditPanel(OnePanelPage.getPanelIdOne())));
                // TODO Sprache:
                feedbackPanel.info("Eingaben bernommen.");
                this.setVisible(false);
            } catch (NumberFormatException nf) {
                // TODO Sprache:
                feedbackPanel.error("Zahl erwartet.");
            } catch (IllegalArgumentException iae) {
                // TODO Sprache:
                feedbackPanel.fatal("Prozedur kann nicht bearbeitet werden.");
            }
        }
    });
    add(feedbackPanel);
    add(form);
}

From source file:hsa.awp.admingui.edit.FifoProcedurePanel.java

License:Open Source License

/**
 * Constructor for {@link FifoProcedurePanel}. This is the setup for the panel and here are all components registered.
 *
 * @param id       wicket:id which connects markup with code.
 * @param fifoProc the existing FifoProcedure which have to be edit
 *///from   w  w  w.j  a va  2s  . co m
public FifoProcedurePanel(String id, final FifoProcedure fifoProc) {

    super(id);

    final FifoProcedure fifoProcedure;

    if (fifoProc == null) {
        fifoProcedure = FifoProcedure.getInstance(controller.getActiveMandator(getSession()));
    } else {
        fifoProcedure = fifoProc;
    }

    CompoundPropertyModel<FifoProcedure> cpm = new CompoundPropertyModel<FifoProcedure>(fifoProcedure);
    final Form<Object> form = new Form<Object>("form");
    form.setDefaultModel(cpm);
    form.setOutputMarkupId(true);
    feedbackPanel.setOutputMarkupId(true);
    // add validators
    fifoName.setRequired(true);
    startDate.setRequired(true);
    endDate.setRequired(true);

    // get&add default values
    fifoName.setDefaultModel(cpm.bind("name"));
    startDate.setModelObject(fifoProcedure.getStartDate().getTime());
    endDate.setModelObject(fifoProcedure.getEndDate().getTime());
    //TODO Sprache:
    add(panelLabel.setDefaultModel(new Model<String>("Fifo-Prozedur bearbeiten")));

    form.add(fifoName);

    form.add(startDate);

    form.add(endDate);

    form.add(new AjaxButton("submit") {
        private static final long serialVersionUID = -6537464906539587006L;

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {

            target.addComponent(feedbackPanel);
        }

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            Calendar sD = Calendar.getInstance();
            sD.setTime(startDate.getModelObject());

            Calendar eD = Calendar.getInstance();
            eD.setTime(endDate.getModelObject());

            try {
                fifoProcedure.setInterval(sD, eD);
                controller.writeFifoProcedure(fifoProcedure);
                //                    setResponsePage(new OnePanelPage(new ConfirmedEditPanel(OnePanelPage.getPanelIdOne())));
                //TODO Sprache:
                feedbackPanel.info("Eingaben \u00e4bernommen.");
                this.setVisible(false);

                target.addComponent(this);
                target.addComponent(feedbackPanel);
            } catch (IllegalArgumentException iae) {
                //TODO Sprache:
                feedbackPanel.fatal("Prozedur kann nicht bearbeitet werden.");
            }
        }
    });
    add(feedbackPanel);
    add(form);
}

From source file:hsa.awp.admingui.report.view.EventListPrintingPanel.java

License:Open Source License

/**
 * Constructor.//from   w ww. j a va2  s .  co  m
 *
 * @param id wicket:id
 */
public EventListPrintingPanel(String id) {

    super(id);

    final DropDownChoice<Campaign> source = new DropDownChoice<Campaign>("eventListPrintingPanel.sourceList",
            new Model<Campaign>(), controller.getCampaignsByMandator(getSession()),
            new ChoiceRenderer<Campaign>("name"));

    final CheckBox matNumber = new CheckBox("eventListPrintingPanel.matNumber", new Model<Boolean>());
    final CheckBox email = new CheckBox("eventListPrintingPanel.email", new Model<Boolean>());

    listSelector = new EventSortedListSelectorPanel("eventListPrintingPanel.listSelector",
            getSelectableEvents(), new LinkedList<Event>());
    listSelector.setOutputMarkupId(true);

    final Form<Object> form = new Form<Object>("eventListPrintingPanel.form");
    form.setOutputMarkupId(true);

    source.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        /**
         * uuid.
         */
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {

            if (source.getModelObject() == null) {
                listSelector.setVisible(false);
            } else {
                EventSortedListSelectorPanel eventSelector = new EventSortedListSelectorPanel(
                        "eventListPrintingPanel.listSelector",
                        controller.getEventsByCampaign(source.getModelObject()), new LinkedList<Event>());
                listSelector.replaceWith(eventSelector);
                listSelector = eventSelector;
                listSelector.setVisible(true);
            }
            target.addComponent(form);
        }
    });

    Button pdfPrint = new Button("eventListPrintingPanel.pdfDownload") {
        @Override
        public void onSubmit() {

            if (listSelector.getSelected().size() <= 0) {
                error("Keine Veranstaltung gewhlt");
                return;
            }

            final List<ExportList> lists = new ArrayList<ExportList>();
            for (Event event : listSelector.getSelected()) {
                lists.add(new ParticipantList(event, matNumber.getModelObject(), email.getModelObject()));
            }

            IResourceStream resourceStream = new AbstractResourceStreamWriter() {
                /**
                 * generated UID.
                 */
                private static final long serialVersionUID = -7988815924081508988L;

                @Override
                public String getContentType() {

                    return ((PdfPrintable) lists.get(0)).getPdfProperties().getMimeType();
                }

                public void write(OutputStream output) {
                    Printer printer = new PdfPrinter();
                    printer.setOutputStream(output);
                    printer.print(lists);
                }
            };

            getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream).setFileName(
                    "Teilnehmerliste" + ((PdfPrintable) lists.get(0)).getPdfProperties().getFileExtension()));
            return;
        }
    };

    Button csvPrint = new Button("eventListPrintingPanel.csvDownload") {
        @Override
        public void onSubmit() {

            if (listSelector.getSelected().size() <= 0) {
                error("Keine Veranstaltung gewhlt");
                return;
            }

            final List<ExportList> lists = new ArrayList<ExportList>();
            for (Event event : listSelector.getSelected()) {
                lists.add(new ParticipantList(event, matNumber.getModelObject(), email.getModelObject(), true));
            }

            IResourceStream resourceStream = new AbstractResourceStreamWriter() {
                /**
                 * generated UID.
                 */
                private static final long serialVersionUID = -7988815924081508988L;

                @Override
                public String getContentType() {

                    return new CsvProperties().getMimeType();
                }

                public void write(OutputStream output) {
                    Printer printer = new CsvPrinter();
                    printer.setOutputStream(output);
                    printer.print(lists);
                }
            };

            getRequestCycle().setRequestTarget(new ResourceStreamRequestTarget(resourceStream)
                    .setFileName("Teilnehmerliste" + new CsvProperties().getFileExtension()));
        }
    };

    form.add(source);
    form.add(matNumber);
    form.add(email);
    form.add(listSelector);
    form.add(pdfPrint);
    form.add(csvPrint);

    add(form);

    add(new FeedbackPanel("feedback")

    );
}

From source file:hsa.awp.admingui.rule.RuleCreatePanel.java

License:Open Source License

/**
 * Creates a new {@link RuleCreatePanel}.
 *
 * @param id wicket-id.// www.j a  v a 2  s .co m
 */
public RuleCreatePanel(String id) {

    super(id);

    Form<Rule> form = new Form<Rule>("rule.create.form");
    add(form);
    form.setOutputMarkupId(true);

    final WebMarkupContainer ruleContainer = new WebMarkupContainer("rule.create.container");
    add(ruleContainer);
    ruleContainer.setOutputMarkupId(true);

    ruleContainer.add(new EmptyRulePanel("rule.create.container.createPanel"));

    final DropDownChoice<String> choices = new DropDownChoice<String>("rule.create.typeSelect",
            new Model<String>(), RuleType.getNames());
    form.add(choices);
    choices.setOutputMarkupId(true);

    choices.add(new OnChangeAjaxBehavior() {
        /**
         * unique serialization id.
         */
        private static final long serialVersionUID = 5597414843387619927L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {

            target.addComponent(ruleContainer);

            try {
                RuleType ruleType = RuleType.findByName((String) choices.getDefaultModelObject());
                ruleContainer.removeAll();
                Panel panel;

                if (ruleType == null) {
                    panel = new EmptyRulePanel("rule.create.container.createPanel");
                } else {
                    Constructor<? extends Panel> constructor = ruleType.getRulePanel()
                            .getConstructor(new Class[] { String.class });
                    panel = constructor.newInstance(new Object[] { "rule.create.container.createPanel" });
                }

                ruleContainer.add(panel);
            } catch (Exception e) {
                e.printStackTrace();
                getLogger().error(e.toString());

                return;
            }
        }
    });
}

From source file:io.ucoin.ucoinj.web.pages.admin.ToolsPage.java

License:Open Source License

public ToolsPage(final PageParameters parameters) {
    super(parameters);

    IModel<ToolsPage> model = new CompoundPropertyModel<ToolsPage>(this);

    isIndexingLastBlocksRunning = false;

    // Progression panel
    progressionModel = new WicketProgressionModel(getSession().getId());
    progressionPanel = new ProgressionPanel("progress", progressionModel) {
        private static final long serialVersionUID = 1L;

        @Override/*from  www.j  a va2 s  .  co m*/
        protected void onConfigure() {
            super.onConfigure();
            setVisibilityAllowed(isIndexingLastBlocksRunning);
        }

        @Override
        public void onComplete(AjaxRequestTarget target) {
            ToolsPage.this.onIndexLastBlocksComplete(target);
        }
    };
    progressionPanel.setOutputMarkupId(true);
    progressionPanel.setOutputMarkupPlaceholderTag(true);
    add(progressionPanel);

    Form<ToolsPage> form = new Form<ToolsPage>("form", model);
    form.setOutputMarkupId(true);
    add(form);

    AjaxButton startIndexLastBlocksButton = new AjaxButton("startIndexLastBlocksButton", form) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onAfterSubmit(AjaxRequestTarget target, Form<?> form) {
            super.onAfterSubmit(target, form);
            startIndexLastBlocks(target);
        }
    };
    form.add(startIndexLastBlocksButton);

    // auto refresh
    selfUpdatingTimer = new AbstractAjaxTimerBehavior(Duration.seconds(5)) {
        @Override
        protected void onTimer(AjaxRequestTarget target) {
            //String message = new StringResourceModel("tools.refreshLastUpdateDate.done", ToolsPage.this, new Model<ToolsPage>(ToolsPage.this)).getString();
            stop(target);

            //info(message);
            target.add(ToolsPage.this);
        }
    };
    selfUpdatingTimer.stop(null);
    add(selfUpdatingTimer);
}

From source file:io.ucoin.ucoinj.web.pages.home.HomePage.java

License:Open Source License

public HomePage(final PageParameters parameters) {
    super(parameters);
    setUseGlobalFeedback(false);//www .  ja  va  2s.  co m

    form = new Form<HomePage>("searchForm");
    form.setOutputMarkupId(true);
    add(form);

    // FeedbackPanel
    final FeedbackPanel feedback = new JQueryFeedbackPanel("feedback");
    feedback.setOutputMarkupId(true);
    form.add(feedback);

    IAutoCompleteRenderer autoCompleteRenderer = new IAutoCompleteRenderer<String>() {
        private static final long serialVersionUID = 1L;

        public void renderHeader(Response response) {
            response.write("<ul>");
        }

        public void render(String choice, Response response, String criteria) {
            response.write("<li textvalue=\"" + choice + "\"");
            response.write(">");

            // Put the substring after the criteria in bold
            if (choice.startsWith(criteria) && choice.length() > criteria.length()) {
                choice = criteria + "<b>" + choice.substring(criteria.length()) + "</b>";
            }

            response.write(choice);
            response.write("</li>");
        }

        public void renderFooter(Response response, int count) {
            response.write("</ul>");
        }
    };

    // Search text
    searchTextField = new AutoCompleteTextField<String>("searchText",
            new PropertyModel<String>(this, "searchQuery"), autoCompleteRenderer) {
        private static final long serialVersionUID = 1L;

        @Override
        protected Iterator<String> getChoices(String input) {
            return doSuggestions(input).iterator();
        }
    };
    searchTextField.add(new AjaxFormComponentUpdatingBehavior("keyup") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            // do search
            searchTextField.updateModel();
        }

        @Override
        protected void onError(AjaxRequestTarget target, RuntimeException e) {
            // Here the Component's model object will remain unchanged,
            // so that it doesn't hold invalid input
        }
    });
    searchTextField.setRequired(true);
    form.add(searchTextField);

    // Submit button
    {
        Button searchButton = new AjaxButton("searchButton") {

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                // do search
                doSearch(target, searchQuery);

                // Force to hide autocomplete choices
                target.appendJavaScript("$('div.wicket-aa-container').hide();" + "$('#"
                        + searchTextField.getMarkupId() + "').attr('autocomplete', 'off');");
            }
        };
        searchButton.setDefaultFormProcessing(false);
        searchButton.setOutputMarkupId(true);
        form.add(searchButton);
        form.setDefaultButton(searchButton);
    }

    //form.add(new AjaxFormValidatingBehavior("keyup", Duration.ONE_SECOND));

    // Search result
    {
        // Parent container
        resultParent = new WebMarkupContainer("resultParent");
        resultParent.setOutputMarkupId(true);
        resultParent.setOutputMarkupPlaceholderTag(true);
        resultParent.setVisible(false);
        add(resultParent);

        // History items
        {
            resultListView = new ListView<SearchResult>("resultItems", new ListModel<SearchResult>()) {
                protected void populateItem(ListItem<SearchResult> item) {
                    SearchResult result = item.getModelObject();

                    // link
                    PageParameters pageParameters = new PageParameters();
                    pageParameters.add(CurrencyPage.CURRENCY_PARAMETER, result.getId());
                    BookmarkablePageLink link = new BookmarkablePageLink("openCurrencyLink", CurrencyPage.class,
                            pageParameters);
                    item.add(link);

                    // Currency name
                    Label label = new Label("currencyName", result.getValue());
                    label.setEscapeModelStrings(false);
                    label.setOutputMarkupPlaceholderTag(false);
                    link.add(label);
                }
            };
            resultListView.setReuseItems(true);
            resultListView.setOutputMarkupId(true);
            resultParent.add(resultListView);
        }
    }
}

From source file:io.ucoin.ucoinj.web.pages.login.LoginPage.java

License:Open Source License

public LoginPage(final PageParameters parameters) {
    super(parameters);

    if (SecurityContextHelper.isAuthenticateNotAnonymous()) {
        setResponsePage(Application.get().getHomePage());
        return;//from  www .  j  a  v a 2 s . c  o  m
    }
    WebSession sesion = getWebSession();
    LoggerFactory.getLogger(LoginPage.class).info("" + sesion.isSignedIn());

    // Challenge message
    WebMarkupContainer challengeMessageField = new WebMarkupContainer("challengeMessage") {
        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);

            tag.put("value", ServiceLocator.instance().getChallengeMessageStore().createNewChallenge());
        }
    };
    challengeMessageField.setMarkupId("challengeMessage");
    challengeMessageField.setOutputMarkupId(true);
    add(challengeMessageField);

    Form form = new Form("form");
    form.setMarkupId("form");
    form.setOutputMarkupId(true);
    add(form);
}