List of usage examples for org.apache.wicket.markup.html.form StatelessForm StatelessForm
public StatelessForm(String id)
From source file:com.doculibre.constellio.wicket.panels.facets.FacetPanel.java
License:Open Source License
public FacetPanel(String id, final SearchableFacet searchableFacet, final FacetsDataProvider dataProvider, final FacetsDataProvider notIncludedDataProvider) { super(id, new CompoundPropertyModel(searchableFacet)); this.searchableFacet = searchableFacet; possibleValuesModel = new LoadableDetachableModel() { @Override//from www. ja v a 2s. c om protected Object load() { SimpleSearch simpleSearch = dataProvider.getSimpleSearch(); String collectionName = simpleSearch.getCollectionName(); ConstellioUser user = ConstellioSession.get().getUser(); List<FacetValue> possibleValues = new ArrayList<FacetValue>(); List<FacetValue> includedFacetPossibleValues = SolrFacetUtils.getPossibleValues(searchableFacet, dataProvider, collectionName, user); List<FacetValue> notIncludedFacetPossibleValues = SolrFacetUtils.getPossibleValues(searchableFacet, notIncludedDataProvider, collectionName, user); possibleValues.addAll(includedFacetPossibleValues); for (FacetValue notIncludedFacetPossibleValue : notIncludedFacetPossibleValues) { boolean alreadyIncluded = false; loop2: for (FacetValue possibleValue : possibleValues) { if (possibleValue.getValue().equals(notIncludedFacetPossibleValue.getValue())) { alreadyIncluded = true; break loop2; } } if (!alreadyIncluded) { possibleValues.add(notIncludedFacetPossibleValue); } } SearchedFacet searchedFacet = simpleSearch.getSearchedFacet(searchableFacet.getName()); // We already applied a value for this facet if (searchedFacet != null) { List<FacetValue> deletedValues = new ArrayList<FacetValue>(); for (FacetValue facetValue : possibleValues) { if (searchedFacet.getExcludedValues().contains(facetValue.getValue())) { // To avoid concurrent modifications deletedValues.add(facetValue); } } for (FacetValue deletedValue : deletedValues) { // Will remove this value from the possible values possibleValues.remove(deletedValue); } for (FacetValue facetValue : possibleValues) { if (searchedFacet.getIncludedValues().contains(facetValue.getValue())) { // Aura pour effet de cocher la case au chargement de la // page selectedValues.add(facetValue); } } applySort(possibleValues, simpleSearch.getFacetSort(searchableFacet.getName()), dataProvider); } return possibleValues; } }; facetForm = new StatelessForm("facetForm"); List<String> sortOptions = new ArrayList<String>(); sortOptions.add(SearchableFacet.SORT_ALPHA); sortOptions.add(SearchableFacet.SORT_NB_RESULTS); IChoiceRenderer sortChoiceRenderer = new StringResourceChoiceRenderer(this); sortField = new DropDownChoice("sort", new Model() { @Override public Object getObject() { SimpleSearch simpleSearch = dataProvider.getSimpleSearch(); return simpleSearch.getFacetSort(searchableFacet.getName()); } @Override public void setObject(final Object object) { SimpleSearch simpleSearch = dataProvider.getSimpleSearch(); simpleSearch.setFacetSort(searchableFacet.getName(), (String) object); possibleValuesModel.detach(); } }, sortOptions, sortChoiceRenderer); sortField.setVisible(!searchableFacet.isQuery() && searchableFacet.isSortable()); sortField.add(new AjaxFormComponentUpdatingBehavior("onchange") { @Override protected void onUpdate(AjaxRequestTarget target) { target.addComponent(FacetPanel.this); } }); refineButton = new Button("refineButton") { @Override public void onSubmit() { SimpleSearch simpleSearch = dataProvider.getSimpleSearch(); SimpleSearch clone = simpleSearch.clone(); for (SearchedFacet searchedFacet : clone.getSearchedFacets()) { if (searchedFacet.getSearchableFacet().equals(searchableFacet)) { List<String> includedValuesNotAlreadySelected = new ArrayList<String>(); for (String includedValue : searchedFacet.getIncludedValues()) { boolean includedValueSelected = false; for (FacetValue selectedValue : selectedValues) { if (selectedValue.getValue().equals(includedValue)) { includedValueSelected = true; break; } } if (!includedValueSelected) { includedValuesNotAlreadySelected.add(includedValue); } } for (String includedValueNotAlreadySelected : includedValuesNotAlreadySelected) { searchedFacet.getIncludedValues().remove(includedValueNotAlreadySelected); } } } for (FacetValue selectedValue : selectedValues) { clone.addSearchedFacet(searchableFacet, selectedValue); } List<SearchedFacet> deletedSearchedFacets = new ArrayList<SearchedFacet>(); for (SearchedFacet searchedFacet : clone.getSearchedFacets()) { if (searchedFacet.getIncludedValues().isEmpty() && searchedFacet.getExcludedValues().isEmpty()) { deletedSearchedFacets.add(searchedFacet); } } for (SearchedFacet deletedSearchedFacet : deletedSearchedFacets) { clone.getSearchedFacets().remove(deletedSearchedFacet); } // ConstellioSession.get().addSearchHistory(clone); clone.setPage(0); PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class); setResponsePage(pageFactoryPlugin.getSearchResultsPage(), SearchResultsPage.getParameters(clone)); } @Override public boolean isVisible() { return getPossibleValues().size() > 1; } }; excludeButton = new Button("excludeButton") { @Override public void onSubmit() { SimpleSearch simpleSearch = dataProvider.getSimpleSearch(); SimpleSearch clone = simpleSearch.clone(); for (FacetValue selectedValue : selectedValues) { clone.excludeSearchedFacet(searchableFacet, selectedValue); } List<SearchedFacet> deletedSearchedFacets = new ArrayList<SearchedFacet>(); for (SearchedFacet searchedFacet : clone.getSearchedFacets()) { if (searchedFacet.getIncludedValues().isEmpty() && searchedFacet.getExcludedValues().isEmpty()) { deletedSearchedFacets.add(searchedFacet); } } for (SearchedFacet deletedSearchedFacet : deletedSearchedFacets) { clone.getSearchedFacets().remove(deletedSearchedFacet); } // ConstellioSession.get().addSearchHistory(clone); clone.setPage(0); PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class); setResponsePage(pageFactoryPlugin.getSearchResultsPage(), SearchResultsPage.getParameters(clone)); } @Override public boolean isVisible() { return getPossibleValues().size() > 1 && !searchableFacet.isQuery(); } }; selectedValuesCheckGroup = new CheckGroup("selectedValuesCheckGroup", selectedValues); listViewContainer = new WebMarkupContainer("listViewContainer"); listViewContainer.setOutputMarkupId(true); possibleValuesListView = new PageableListView("possibleValues", possibleValuesModel, Integer.MAX_VALUE) { @Override protected void populateItem(ListItem item) { FacetValue possibleValue = (FacetValue) item.getModelObject(); final String value = possibleValue.getValue(); int numFound = possibleValue.getDocCount(); Check checkbox = checkboxes.get(value); if (checkbox == null) { checkbox = new Check("selectFacet", new Model(possibleValue)) { @Override public boolean isVisible() { return searchableFacet.isMultiValued() && getPossibleValues().size() > 1; } }; checkboxes.put(value, checkbox); } item.add(checkbox); SimpleSearch simpleSearch = dataProvider.getSimpleSearch(); SimpleSearch cloneAddFacet = simpleSearch.clone(); if (searchableFacet != null && !searchableFacet.isMultiValued()) { cloneAddFacet.removeSearchedFacet(searchableFacet); } cloneAddFacet.addSearchedFacet(searchableFacet, possibleValue); cloneAddFacet.setPage(0); PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class); Link addFacetLink = new BookmarkablePageLink("addFacetLink", pageFactoryPlugin.getSearchResultsPage(), SearchResultsPage.getParameters(cloneAddFacet)); item.add(addFacetLink); if (!searchableFacet.isMultiValued()) { SearchedFacet searchedFacet = simpleSearch.getSearchedFacet(searchableFacet.getName()); if (searchedFacet != null && searchedFacet.getIncludedValues().contains(value)) { item.add(new StyleClassAppender("singleValuedFacetSelected")); } } SimpleSearch cloneDeleteFacet = simpleSearch.clone(); cloneDeleteFacet.excludeSearchedFacet(searchableFacet, possibleValue); Link deleteFacetLink = new BookmarkablePageLink("deleteFacetLink", pageFactoryPlugin.getSearchResultsPage(), SearchResultsPage.getParameters(cloneDeleteFacet)); item.add(deleteFacetLink); SearchedFacet facet = simpleSearch.getSearchedFacet(searchableFacet.getName()); boolean deleteFacetLinkVisible; FacetDisplayPlugin facetDisplayPlugin = PluginFactory.getPlugin(FacetDisplayPlugin.class); if (facetDisplayPlugin == null || !facetDisplayPlugin.isDisplayAllResultsLink(searchableFacet)) { deleteFacetLinkVisible = facet != null && !searchableFacet.isMultiValued() && facet.getIncludedValues().contains(value); } else { deleteFacetLinkVisible = false; } deleteFacetLink.setVisible(deleteFacetLinkVisible); RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices(); String collectionName = simpleSearch.getCollectionName(); RecordCollection collection = collectionServices.get(collectionName); Locale displayLocale = collection.getDisplayLocale(getLocale()); String numFoundFormatted = NumberFormatUtils.format(numFound, displayLocale); Label countLabel = new Label("count", possibleValue.getLabel(displayLocale) + " (" + numFoundFormatted + ")"); addFacetLink.add(countLabel); } }; FacetDisplayPlugin facetDisplayPlugin = PluginFactory.getPlugin(FacetDisplayPlugin.class); if (facetDisplayPlugin == null || facetDisplayPlugin.isPageable(searchableFacet)) { possibleValuesListView.setRowsPerPage(10); } int currentPage = dataProvider.getSimpleSearch().getFacetPage(searchableFacet.getName()); possibleValuesListView.setCurrentPage(currentPage); pagingNavigator = new ConstellioFacetsPagingNavigator("pagingNavigator", possibleValuesListView, dataProvider, searchableFacet.getName()); final SimpleSearch simpleSearch = dataProvider.getSimpleSearch(); SimpleSearch cloneAllResultsFacet = simpleSearch.clone(); cloneAllResultsFacet.setPage(0); cloneAllResultsFacet.removeSearchedFacet(searchableFacet); PageFactoryPlugin pageFactoryPlugin = PluginFactory.getPlugin(PageFactoryPlugin.class); allResultsLink = new BookmarkablePageLink("allResultsLink", pageFactoryPlugin.getSearchResultsPage(), SearchResultsPage.getParameters(cloneAllResultsFacet)) { @Override public boolean isVisible() { boolean visible = super.isVisible(); if (visible) { SearchedFacet searchedFacet = simpleSearch.getSearchedFacet(searchableFacet.getName()); if (searchedFacet != null) { FacetDisplayPlugin facetDisplayPlugin = PluginFactory.getPlugin(FacetDisplayPlugin.class); if (facetDisplayPlugin == null || !facetDisplayPlugin.isDisplayAllResultsLink(searchableFacet)) { visible = false; } else { visible = !searchedFacet.getExcludedValues().isEmpty() || !searchedFacet.getIncludedValues().isEmpty(); } } } return visible; } }; WebMarkupContainer multiValuedFacetOptions = new WebMarkupContainer("multiValuedFacetOptions") { @Override public boolean isVisible() { return searchableFacet.isMultiValued(); } }; WebMarkupContainer facetHeader = new WebMarkupContainer("facetHeader") { @Override public boolean isVisible() { return searchableFacet.isMultiValued() || searchableFacet.isSortable(); } }; WebMarkupContainer facetFooter = new WebMarkupContainer("facetFooter") { @Override public boolean isVisible() { return pagingNavigator.isVisible() || allResultsLink.isVisible(); } }; add(facetForm); facetForm.add(facetHeader); facetForm.add(selectedValuesCheckGroup); facetForm.add(facetFooter); facetHeader.add(sortField); facetHeader.add(multiValuedFacetOptions); multiValuedFacetOptions.add(refineButton); multiValuedFacetOptions.add(excludeButton); selectedValuesCheckGroup.add(listViewContainer); listViewContainer.add(possibleValuesListView); facetFooter.add(pagingNavigator); facetFooter.add(allResultsLink); }
From source file:com.example.justaddwater.web.app.LoginPage.java
License:Apache License
public LoginPage(final PageParameters parameters) { super(parameters); add(new Header("header")); // make the login form stateless so that users don't get "page expired" message // if they leave the page idle for a long time and then return Form form = new StatelessForm("form") { @Override/*from w w w.ja v a 2s .c o m*/ protected void onSubmit() { String username = usernameField.getModelObject(); String password = passwordField.getModelObject(); if (!loginUtil.loginWithPassword(username, password, LoginPage.this)) { error("bad password"); } } }; FeedbackPanel feedback = new FeedbackPanel("feedback"); form.add(feedback); usernameField = new RequiredTextField<String>("username", Model.of("")); usernameField.add(new DefaultFocusBehavior()); form.add(usernameField); passwordField = new PasswordTextField("password", Model.of("")); form.add(passwordField); add(form); }
From source file:com.gitblit.wicket.pages.ChangePasswordPage.java
License:Apache License
public ChangePasswordPage() { super();// ww w . j a va 2 s . c o m if (!GitBlitWebSession.get().isLoggedIn()) { // Change password requires a login throw new RestartResponseException(getApplication().getHomePage()); } if (!app().settings().getBoolean(Keys.web.authenticateAdminPages, true) && !app().settings().getBoolean(Keys.web.authenticateViewPages, false)) { // no authentication enabled throw new RestartResponseException(getApplication().getHomePage()); } UserModel user = GitBlitWebSession.get().getUser(); if (!app().authentication().supportsCredentialChanges(user)) { error(MessageFormat.format(getString("gb.userServiceDoesNotPermitPasswordChanges"), app().settings().getString(Keys.realm.userService, "${baseFolder}/users.conf")), true); } setupPage(getString("gb.changePassword"), user.username); StatelessForm<Void> form = new StatelessForm<Void>("passwordForm") { private static final long serialVersionUID = 1L; @Override public void onSubmit() { String password = ChangePasswordPage.this.password.getObject(); String confirmPassword = ChangePasswordPage.this.confirmPassword.getObject(); // ensure passwords match if (!password.equals(confirmPassword)) { error(getString("gb.passwordsDoNotMatch")); return; } // ensure password satisfies minimum length requirement int minLength = app().settings().getInteger(Keys.realm.minPasswordLength, 5); if (minLength < 4) { minLength = 4; } if (password.length() < minLength) { error(MessageFormat.format(getString("gb.passwordTooShort"), minLength)); return; } UserModel user = GitBlitWebSession.get().getUser(); // convert to MD5 digest, if appropriate String type = app().settings().getString(Keys.realm.passwordStorage, "md5"); if (type.equalsIgnoreCase("md5")) { // store MD5 digest of password password = StringUtils.MD5_TYPE + StringUtils.getMD5(password); } else if (type.equalsIgnoreCase("combined-md5")) { // store MD5 digest of username+password password = StringUtils.COMBINED_MD5_TYPE + StringUtils.getMD5(user.username.toLowerCase() + password); } user.password = password; try { app().gitblit().reviseUser(user.username, user); if (app().settings().getBoolean(Keys.web.allowCookieAuthentication, false)) { app().authentication().setCookie(GitBlitRequestUtils.getServletRequest(), GitBlitRequestUtils.getServletResponse(), user); } } catch (GitBlitException e) { error(e.getMessage()); return; } info(getString("gb.passwordChanged")); setResponsePage(RepositoriesPage.class); } }; NonTrimmedPasswordTextField passwordField = new NonTrimmedPasswordTextField("password", password); passwordField.setResetPassword(false); form.add(passwordField); NonTrimmedPasswordTextField confirmPasswordField = new NonTrimmedPasswordTextField("confirmPassword", confirmPassword); confirmPasswordField.setResetPassword(false); form.add(confirmPasswordField); form.add(new Button("save")); Button cancel = new Button("cancel") { private static final long serialVersionUID = 1L; @Override public void onSubmit() { error(getString("gb.passwordChangeAborted")); setResponsePage(RepositoriesPage.class); } }; cancel.setDefaultFormProcessing(false); form.add(cancel); add(form); }
From source file:com.romeikat.datamessie.core.base.ui.page.SignInPage.java
License:Open Source License
@Override protected void onInitialize() { super.onInitialize(); // Signin page sould be stateless setStatelessHint(true);//w w w . j ava 2s . co m // Form final StatelessForm<Void> form = new StatelessForm<Void>("signInForm") { private static final long serialVersionUID = 1L; @Override protected void onSubmit() { if (Strings.isEmpty(username)) { return; } // Authenticate final boolean authResult = AuthenticatedWebSession.get().signIn(username, password); // If authentication succeeds, redirect user to the requested page if (authResult) { continueToOriginalDestination(); // If we reach this line there was no intercept page, so go to home page setResponsePage(getApplication().getHomePage()); } } }; form.setDefaultModel(new CompoundPropertyModel<SignInPage>(this)); add(form); // Username final TextField<String> usernameTextField = new TextField<String>("username"); usernameTextField.add(new FocusBehavior()); form.add(usernameTextField); // Password final PasswordTextField passwordTextField = new PasswordTextField("password"); form.add(passwordTextField); }
From source file:com.smarthome.web.sources.Login.java
public Login() { add(new login_header("login_header")); final TextField<String> username = new TextField<>("username", Model.of("")); final PasswordTextField pass = new PasswordTextField("pass", Model.of("")); StatelessForm form = new StatelessForm("loginForm") { @Override/*from w w w . jav a 2s . co m*/ protected void onSubmit() { super.onSubmit(); //To change body of generated methods, choose Tools | Templates. LoginSession session = getMySession(); if (session.signIn(username.getValue(), pass.getValue())) { continueToOriginalDestination(); setResponsePage(MainInterface.class); } else { setResponsePage(Application.get().getHomePage()); } } }; add(form); form.add(username); form.add(pass); }
From source file:com.socialsite.authentication.LoginPage.java
License:Open Source License
public LoginPage() { // intialize the spring DAO InjectorHolder.getInjector().inject(this); final StatelessForm<Object> form = new StatelessForm<Object>("loginform"); add(form);// www . ja v a 2s .com form.add(new RequiredTextField<String>("username", new PropertyModel<String>(this, "userName"))); form.add(new PasswordTextField("password", new PropertyModel<String>(this, "password"))); SubmitLink login; form.add(login = new SubmitLink("login") { /** * */ private static final long serialVersionUID = 1L; @Override public void onSubmit() { final User user = userDao.checkUserStatus(userName, password); if (user == null) { error("Invalid username or password"); return; } final SocialSiteSession session = SocialSiteSession.get(); session.setSessionUser(new SessionUser(user.getId(), SocialSiteRoles.ownerRole)); session.setUserId(user.getId()); setResponsePage(new HomePage()); } }); // submits the form when the user hit return form.setDefaultButton(login); // feedback panel add(new FeedbackPanel("feedback")); }
From source file:com.zh.snmp.snmpweb.pages.BasePage.java
License:Apache License
public BasePage(final PageParameters parameters) { super(parameters); add(new Link("logout") { @Override/*w ww . ja va 2 s . com*/ public boolean isVisible() { return BaseSession.get().isSignedIn(); } @Override public void onClick() { BaseSession.get().signOut(); setResponsePage(SnmpPage.class, null); } }); add(form = isFormStateless() ? new StatelessForm("form") { @Override public void onSubmit() { main.onSubmitForm(); } } : new Form("form") { @Override public void onSubmit() { main.onSubmitForm(); } }); form.add(main = buildContent(MAIN, parameters)); main.setOutputMarkupId(true); form.add(new Label("panelTitle", getPanelTitleModel())).setOutputMarkupId(true); add(modal = new ModalWindow("modal")); form.add(feedback = new FeedbackPanel("feedback")); //addMainMenuToForm(null); feedback.setOutputMarkupId(true); tabContainer = new TabContainer(MENU, this, getMainMenuConfig()) { @Override protected void onTabMenuClick(Class<? extends MarkupContainer> parentClz, Class<? extends BasePanel> panelClz, IModel model, AjaxRequestTarget art) { Class<? extends BasePanel>[] config = getMenuConfig(panelClz); if (config != null && config.length > 0 && config[0] == panelClz && parentClz != panelClz) { changePanel(config, model, panelClz, art); } else { changePanel(panelClz, model, art); } } }; add(tabContainer); //actualizeMenu(null); }
From source file:cz.zcu.kiv.eegdatabase.wui.ui.experiments.components.ExperimentListForm.java
License:Apache License
/** * * @param id id of the component/*from w w w.jav a 2 s. co m*/ * @param titleModel title which is displayed at the top of the window * @param listOfExperiments list of experiments to choose from */ public ExperimentListForm(String id, IModel<String> titleModel, IModel<List<Experiment>> listOfExperiments) { super(id); this.selectedExperiments = new HashSet<Experiment>(); this.cont = new StatelessForm("cont"); this.cont.setOutputMarkupId(true); this.add(cont); this.add(new Label("title", titleModel)); this.addExperimentList(cont, listOfExperiments); this.addControls(cont); }
From source file:cz.zcu.kiv.eegdatabase.wui.ui.experiments.components.ExperimentPackageDetailPanel.java
License:Apache License
public ExperimentPackageDetailPanel(String id, IModel<ResearchGroup> resGroup) { super(id);/*w w w.j a v a 2 s. c o m*/ this.packageModel = new Model<ExperimentPackage>(new ExperimentPackage()); this.licenseModel = new Model<License>(); this.keywordsModel = new Model<Keywords>(new Keywords()); this.resGroupModel = resGroup; form = new StatelessForm("form"); this.add(form); addBasicInfoFields(); addLicenseSelect(); addLicenseAddWindow(); addControls(); }
From source file:cz.zcu.kiv.eegdatabase.wui.ui.licenses.components.LicenseRequestForm.java
License:Apache License
public LicenseRequestForm(String id, IModel<License> license) { super(id);/*w w w . j a v a2 s . c o m*/ this.licenseModel = license; form = new StatelessForm("form"); this.persLicense = new PersonalLicense(); this.add(form); this.add(new Label("title", ResourceUtils.getModel("heading.license.request", licenseModel))); this.addComponents(); this.addControls(); }