Example usage for org.apache.wicket.util.string StringValue toString

List of usage examples for org.apache.wicket.util.string StringValue toString

Introduction

In this page you can find the example usage for org.apache.wicket.util.string StringValue toString.

Prototype

@Override
public final String toString() 

Source Link

Usage

From source file:org.devgateway.eudevfin.ui.common.pages.HeaderFooter.java

License:Open Source License

private void configureLanguage(PageParameters pageParameters) {
    StringValue lang = pageParameters.get(Constants.LANGUAGE_PAGE_PARAM);

    LocaleHelper beanSession = ((WicketSpringApplication) getApplication()).getSpringContext()
            .getBean("localeHelperSession", LocaleHelper.class);
    LocaleHelper beanRequest = ((WicketSpringApplication) getApplication()).getSpringContext()
            .getBean("localeHelperRequest", LocaleHelper.class);
    if (!lang.isEmpty()) {
        // TODO: verify lang in supported languages
        Session.get().setLocale(new Locale(lang.toString()));
        if (beanRequest != null)
            beanRequest.setLocale(lang.toString());
        if (beanSession != null)
            beanSession.setLocale(lang.toString());
    } else if (beanSession != null && beanRequest != null && beanSession.getLocale() != null) {
        // THIS IS AN UGLY HACK NEEDS ANOTHER SOLUTION
        beanRequest.setLocale(beanSession.getLocale());
    }//from  www.j  ava 2 s . co  m
}

From source file:org.devgateway.toolkit.forms.wicket.page.BasePage.java

License:Open Source License

/**
 * Selects/changes the default language in the current session. If the
 * {@link WebConstants#LANGUAGE_PARAM} is found in the
 * {@link PageParameters} then its contents is set as language in the
 * session object.// w ww.  ja  va2 s .c om
 */
protected void selectLanguage() {
    StringValue lang = this.getPageParameters().get(WebConstants.LANGUAGE_PARAM);
    if (!lang.isEmpty()) {
        WebSession.get().setLocale(new Locale(lang.toString()));
    }
}

From source file:org.efaps.mobile.wicket.MobileSession.java

License:Apache License

/**
 *
 *///from   w  w  w.j a v  a  2  s . c om
public void openContext() {
    if (isAuthenticated()) {
        try {
            if (!Context.isTMActive()) {
                final ServletWebRequest request = (ServletWebRequest) RequestCycle.get().getRequest();

                final Map<String, String[]> parameters = new HashMap<String, String[]>();
                final IRequestParameters reqPara = request.getRequestParameters();
                for (final String name : reqPara.getParameterNames()) {
                    final List<StringValue> values = reqPara.getParameterValues(name);
                    final String[] valArray = new String[values.size()];
                    int i = 0;
                    for (final StringValue value : values) {
                        valArray[i] = value.toString();
                        i++;
                    }
                    parameters.put(name, valArray);
                }
                final Map<String, Object> sessionAttributes = new HashMap<String, Object>();
                for (final String attribute : getAttributeNames()) {
                    sessionAttributes.put(attribute, getAttribute(attribute));
                }
                Context.begin(this.userName, super.getLocale(), sessionAttributes, parameters, null, true);
                // set the locale in the context and in the session
                setLocale(Context.getThreadContext().getLocale());
                setAttribute(UserAttributesSet.CONTEXTMAPKEY, Context.getThreadContext().getUserAttributes());
                Context.getThreadContext().setPath(request.getContextPath());
            }
        } catch (final EFapsException e) {
            MobileSession.LOG.error("could not initialise the context", e);
            throw new RestartResponseException(new InternalErrorPage());
        }
    }
}

From source file:org.efaps.ui.wicket.behaviors.update.AbstractRemoteUpdateBehavior.java

License:Apache License

@Override
protected void respond(final AjaxRequestTarget _target) {
    final RequestCycle requestCycle = RequestCycle.get();
    final StringValue key = requestCycle.getRequest().getRequestParameters()
            .getParameterValue(IRemoteUpdateListener.PARAMETERKEY);
    if (this.key2listener.containsKey(key.toString())) {
        this.key2listener.get(key.toString()).onEvent(getComponent(), _target);
    }/*w  w  w .j  a  va 2  s  .  c  o m*/
}

From source file:org.efaps.ui.wicket.components.date.DateTimePanel.java

License:Apache License

/**
 * Method to get for the parameters returned from the form as a datetimes.
 *
 * @param _date date/*from ww w  .j  a v a2s .c o  m*/
 * @param _hour hour
 * @param _minute minutes
 * @param _ampm am/pm
 * @return valid string
 * @throws EFapsException on error
 */
public List<DateTime> getDateList(final List<StringValue> _date, final List<StringValue> _hour,
        final List<StringValue> _minute, final List<StringValue> _ampm) throws EFapsException {
    final List<DateTime> ret = new ArrayList<>();
    if (_date != null) {
        Iterator<StringValue> hourIter = null;
        Iterator<StringValue> minuteIter = null;
        Iterator<StringValue> ampmIter = null;
        if (_hour != null) {
            hourIter = _hour.iterator();
        }
        if (_minute != null) {
            minuteIter = _minute.iterator();
        }
        if (_ampm != null) {
            ampmIter = _ampm.iterator();
        }

        for (final StringValue date : _date) {
            if (!date.isNull() && !date.isEmpty()) {
                final DateTimeFormatter fmt = DateTimeFormat
                        .forPattern(this.converter.getDatePattern(Context.getThreadContext().getLocale()))
                        .withChronology(Context.getThreadContext().getChronology());
                fmt.withLocale(getLocale());
                final MutableDateTime mdt = fmt.parseMutableDateTime(date.toString());
                if (hourIter != null) {
                    final StringValue hourStr = hourIter.next();
                    final int hour = Integer.parseInt(hourStr.toString("0"));
                    mdt.setHourOfDay(hour);
                    if (ampmIter != null) {
                        final StringValue ampmStr = ampmIter.next();
                        if ("am".equals(ampmStr.toString("am"))) {
                            if (hour == 12) {
                                mdt.setHourOfDay(0);
                            }
                        } else {
                            if (hour != 12) {
                                mdt.setHourOfDay(hour + 12);
                            }
                        }
                    }
                    if (minuteIter != null) {
                        final StringValue minuteStr = minuteIter.next();
                        final int minute = Integer.parseInt(minuteStr.toString("0"));
                        mdt.setMinuteOfHour(minute);
                    }
                }
                ret.add(mdt.toDateTime());
            }
        }
    }
    return ret;
}

From source file:org.efaps.ui.wicket.components.FormContainer.java

License:Apache License

/**
 * Handle the multipart to store the files and parameters in the context also.
 * @return true if multipart// w w w . j  a v a2  s. c om
 */
@Override
protected boolean handleMultiPart() {
    final boolean ret = super.handleMultiPart();
    try {
        if (isMultiPart() && getRequest() instanceof MultipartServletWebRequest) {
            for (final Entry<String, List<FileItem>> entry : ((MultipartServletWebRequest) getRequest())
                    .getFiles().entrySet()) {
                for (final FileItem fileItem : entry.getValue()) {
                    final FileParameter parameter = new FileParameter(entry.getKey(), fileItem);
                    Context.getThreadContext().getFileParameters().put(entry.getKey(), parameter);
                }
            }

            final Map<String, String[]> parameters = new HashMap<>();
            final IRequestParameters reqPara = getRequest().getRequestParameters();
            for (final String name : reqPara.getParameterNames()) {
                final List<StringValue> values = reqPara.getParameterValues(name);
                final String[] valArray = new String[values.size()];
                int i = 0;
                for (final StringValue value : values) {
                    valArray[i] = value.toString();
                    i++;
                }
                parameters.put(name, valArray);
            }
            Context.getThreadContext().getParameters().putAll(parameters);
        }
    } catch (final EFapsException e) {
        throw new RestartResponseAtInterceptPageException(new ErrorPage(e));
    }
    return ret;
}

From source file:org.efaps.ui.wicket.components.gridx.behaviors.ModalVisitor.java

License:Apache License

@Override
public void component(final ModalWindowContainer _modal, final IVisit<ModalWindowContainer> _visit) {
    _modal.reset();//from   w ww .j  a  v  a 2s .  co  m
    final IRequestParameters para = _modal.getRequest().getRequestParameters();
    final StringValue rid = para.getParameterValue("rid");
    final UIGrid uiGrid = (UIGrid) _modal.getPage().getDefaultModelObject();
    final Long cmdId = uiGrid.getID4Random(rid.toString());

    final ModalWindowAjaxPageCreator pageCreator = new ModalWindowAjaxPageCreator(new ICmdUIObject() {

        /**
         * The Constant
         * serialVersionUID.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public AbstractCommand getCommand() throws EFapsException {
            return Command.get(cmdId);
        }

        @Override
        public Instance getInstance() {
            return null;
        }

        @Override
        public List<Return> executeEvents(final EventType _eventType, final Object... _objectTuples)
                throws EFapsException {
            return null;
        }
    }, _modal);
    try {
        final Command cmd = Command.get(cmdId);
        _modal.setInitialHeight(cmd.getWindowHeight());
        _modal.setInitialWidth(cmd.getWindowWidth());
    } catch (final CacheReloadException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    _modal.setPageCreator(pageCreator);
    _visit.stop(_modal);
}

From source file:org.efaps.ui.wicket.components.gridx.behaviors.SubmitBehavior.java

License:Apache License

@Override
protected void onSubmit(final AjaxRequestTarget _target) {
    super.onSubmit(_target);

    final IRequestParameters para = getComponent().getRequest().getRequestParameters();
    final StringValue rid = para.getParameterValue("rid");
    final UIGrid uiGrid = (UIGrid) getComponent().getPage().getDefaultModelObject();
    final Long cmdId = uiGrid.getID4Random(rid.toString());

    try {/*w  ww  . jav a  2s  .  c o m*/
        final Command cmd = Command.get(cmdId);
        final List<StringValue> oidValues = para.getParameterValues("selectedRow");
        final String[] oids = ParameterUtil.parameter2Array(para, "selectedRow");
        boolean check = false;
        if (cmd.getSubmitSelectedRows() > -1) {
            if (cmd.getSubmitSelectedRows() > 0) {
                check = oidValues == null ? false : oidValues.size() == cmd.getSubmitSelectedRows();
            } else {
                check = oidValues == null ? false : !oidValues.isEmpty();
            }
        } else {
            check = true;
        }

        if (check) {
            if (cmd.isAskUser()) {
                getComponent().getPage().visitChildren(ModalWindowContainer.class,
                        new IVisitor<ModalWindowContainer, Void>() {

                            @Override
                            public void component(final ModalWindowContainer _modal,
                                    final IVisit<Void> _visit) {
                                _modal.setPageCreator(new ModalWindow.PageCreator() {

                                    private static final long serialVersionUID = 1L;

                                    @Override
                                    public Page createPage() {
                                        Page page = null;
                                        try {
                                            page = new DialogPage(getComponent().getPage().getPageReference(),
                                                    UICmdObject.getModel(cmdId), oids);
                                        } catch (final EFapsException e) {
                                            page = new ErrorPage(e);
                                        }
                                        return page;
                                    }
                                });
                                _modal.setInitialHeight(150);
                                _modal.setInitialWidth(350);
                                _modal.show(_target);
                                _visit.stop();
                            }
                        });
            } else {
                boolean updatePage = true;
                if (cmd.hasEvents(EventType.UI_COMMAND_EXECUTE)) {
                    try {
                        final List<Return> rets;
                        if (oidValues != null) {
                            rets = cmd.executeEvents(EventType.UI_COMMAND_EXECUTE, ParameterValues.OTHERS,
                                    oids);
                        } else {
                            rets = cmd.executeEvents(EventType.UI_COMMAND_EXECUTE);
                        }
                        if (cmd.isTargetShowFile() && rets != null && !rets.isEmpty()) {
                            final Object object = rets.get(0).get(ReturnValues.VALUES);
                            if (object instanceof File) {
                                ((EFapsSession) getComponent().getSession()).setFile((File) object);
                                ((AbstractMergePage) getComponent().getPage()).getDownloadBehavior()
                                        .initiate(_target);
                                updatePage = false;
                            }
                        }
                    } catch (final EFapsException e) {
                        throw new RestartResponseException(new ErrorPage(e));
                    }
                }
                if (updatePage) {
                    uiGrid.reload();
                    getComponent().setResponsePage(new GridPage(Model.of(uiGrid)));
                }
            }
        } else {
            getComponent().getPage().visitChildren(ModalWindowContainer.class,
                    new IVisitor<ModalWindowContainer, Void>() {

                        @Override
                        public void component(final ModalWindowContainer _modal, final IVisit<Void> _visit) {
                            _modal.setPageCreator(new ModalWindow.PageCreator() {

                                private static final long serialVersionUID = 1L;

                                @Override
                                public Page createPage() {
                                    return new DialogPage(getComponent().getPage().getPageReference(),
                                            "SubmitSelectedRows.fail" + cmd.getSubmitSelectedRows(), false,
                                            false);
                                }
                            });
                            _modal.setInitialHeight(150);
                            _modal.setInitialWidth(350);
                            _modal.show(_target);
                            _visit.stop();
                        }
                    });
        }
    } catch (final EFapsException e) {
        SubmitBehavior.LOG.error("Catched", e);
    }
}

From source file:org.efaps.ui.wicket.components.gridx.behaviors.SubmitModalBehavior.java

License:Apache License

@Override
protected void onSubmit(final AjaxRequestTarget _target) {
    super.onSubmit(_target);

    try {//ww w  . j  a  v a 2 s.  com
        final IRequestParameters para = getComponent().getRequest().getRequestParameters();
        final StringValue rid = para.getParameterValue("rid");
        final UIGrid uiGrid = (UIGrid) getComponent().getPage().getDefaultModelObject();
        final Long cmdId = uiGrid.getID4Random(rid.toString());
        final Command cmd = Command.get(cmdId);
        final List<StringValue> oidValues = para.getParameterValues("selectedRow");
        boolean check = false;
        if (cmd.getSubmitSelectedRows() > -1) {
            if (cmd.getSubmitSelectedRows() > 0) {
                check = oidValues == null ? false : oidValues.size() == cmd.getSubmitSelectedRows();
            } else {
                check = oidValues == null ? false : !oidValues.isEmpty();
            }
        } else {
            check = true;
        }
        if (check) {
            final ModalWindowContainer modal = getComponent().getPage()
                    .visitChildren(ModalWindowContainer.class, new ModalVisitor());
            modal.show(_target);
        } else {
            getComponent().getPage().visitChildren(ModalWindowContainer.class,
                    new IVisitor<ModalWindowContainer, Void>() {

                        @Override
                        public void component(final ModalWindowContainer _modal, final IVisit<Void> _visit) {
                            _modal.setPageCreator(new ModalWindow.PageCreator() {

                                private static final long serialVersionUID = 1L;

                                @Override
                                public Page createPage() {
                                    return new DialogPage(getComponent().getPage().getPageReference(),
                                            "SubmitSelectedRows.fail" + cmd.getSubmitSelectedRows(), false,
                                            false);
                                }
                            });
                            _modal.setInitialHeight(150);
                            _modal.setInitialWidth(350);
                            _modal.show(_target);
                            _visit.stop();
                        }
                    });
        }
    } catch (final Exception e) {
        SubmitModalBehavior.LOG.error("Catched", e);
    }
}

From source file:org.efaps.ui.wicket.components.menutree.MenuUpdateBehavior.java

License:Apache License

@Override
protected void respond(final AjaxRequestTarget _target) {
    super.respond(_target);
    final RequestCycle requestCycle = RequestCycle.get();
    final StringValue key = requestCycle.getRequest().getRequestParameters()
            .getParameterValue(IRemoteUpdateListener.PARAMETERKEY);
    if (MenuUpdateBehavior.PARAMETERKEY4UPDATE.equals(key.toString())) {
        final MenuTree tree = (MenuTree) getComponent();
        final TreeMenuModel treeModel = (TreeMenuModel) tree.getProvider();
        final Iterator<? extends UIMenuItem> iter = treeModel.getRoots();
        while (iter.hasNext()) {
            final UIMenuItem item = iter.next();
            if (item.requeryLabel()) {
                tree.updateNode(item, _target);
            }// w ww .j  a  v  a2s  .  c om
            for (final UIMenuItem desc : item.getDescendants()) {
                if (desc.requeryLabel()) {
                    tree.updateNode(desc, _target);
                }
            }
        }
    }
}