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

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

Introduction

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

Prototype

public final int toInt() throws StringValueConversionException 

Source Link

Document

Convert this text to an int.

Usage

From source file:cz.zcu.kiv.eegdatabase.wui.ui.people.form.PersonAddParamFormPage.java

License:Apache License

public PersonAddParamFormPage(PageParameters parameters) {

    StringValue paramId = parameters.get(DEFAULT_PARAM_ID);

    if (paramId.isNull() || paramId.isEmpty())
        throw new RestartResponseAtInterceptPageException(ListPersonPage.class);

    setPageTitle(ResourceUtils.getModel("pageTitle.addPersonOptionalParameter"));

    add(new ButtonPageMenu("leftMenu", PersonPageLeftMenu.values()));

    PersonOptParamVal param = new PersonOptParamVal();
    param.setPerson(personFacade.getPersonForDetail(paramId.toInt()));

    add(new PersonAddParamForm("form", new Model<PersonOptParamVal>(param), facade, getFeedback()));
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.people.form.PersonFormPage.java

License:Apache License

public PersonFormPage(PageParameters parameters) throws IOException {

    StringValue paramId = parameters.get(DEFAULT_PARAM_ID);

    if (paramId.isNull() || paramId.isEmpty())
        throw new RestartResponseAtInterceptPageException(ListPersonPage.class);

    setPageTitle(ResourceUtils.getModel("pageTitle.editPerson"));
    add(new Label("title", ResourceUtils.getModel("pageTitle.editPerson")));

    add(new ButtonPageMenu("leftMenu", PersonPageLeftMenu.values()));

    Person person = facade.getPersonForDetail(paramId.toInt());

    if (!securityFacade.userCanEditPerson(person.getPersonId()))
        throw new RestartResponseAtInterceptPageException(PersonDetailPage.class,
                PageParametersUtils.getDefaultPageParameters(person.getPersonId()));

    add(new PersonForm("form", new Model<Person>(person), educationFacade, facade, getFeedback()));
}

From source file:cz.zcu.kiv.eegdatabase.wui.ui.scenarios.ScenarioDetailPage.java

License:Apache License

private int parseParameters(PageParameters parameters) {

    StringValue value = parameters.get(BasePage.DEFAULT_PARAM_ID);
    if (value.isNull() || value.isEmpty()) {
        throw new RestartResponseAtInterceptPageException(EEGDataBaseApplication.get().getHomePage());
    }/*from   ww w. j ava  2s .c om*/
    return value.toInt();
}

From source file:name.martingeisse.wicket.util.StringValueUtil.java

License:Open Source License

/**
 * Decodes an integer parameter, returning null if the value is empty or malformed.
 * @param value the value to decode//from   www.  ja va2  s .  com
 * @return the decoded value or null
 */
public static Integer getOptionalInteger(StringValue value) {
    if (value == null || value.isEmpty()) {
        return null;
    }
    try {
        return value.toInt();
    } catch (StringValueConversionException e) {
        return null;
    }
}

From source file:name.martingeisse.wicket.util.StringValueUtil.java

License:Open Source License

/**
 * Decodes an integer parameter with the specified lower and upper cap. Throws a
 * {@link StringValueConversionException} if the value is empty, malformed,
 * or outside the allowed range. //from  w  ww . j a va2  s  . co  m
 * 
 * @param value the value
 * @param lowerCap the lower bound for the value
 * @param upperCap the upper bound for the value
 * @return the decoded value
 */
public static Integer getMandatoryRangeCappedInteger(StringValue value, int lowerCap, int upperCap) {
    int decoded = value.toInt();
    if (decoded < lowerCap || decoded > upperCap) {
        String lowerCapText = (lowerCap == Integer.MIN_VALUE ? "*" : Integer.toString(lowerCap));
        String upperCapText = (upperCap == Integer.MAX_VALUE ? "*" : Integer.toString(upperCap));
        throw new StringValueConversionException(
                "value " + decoded + " is outside the allowed range: " + lowerCapText + " .. " + upperCapText);
    }
    return decoded;
}

From source file:net.dontdrinkandroot.extensions.wicket.jqueryui.SortableBehavior.java

License:Apache License

@Override
protected void respond(AjaxRequestTarget target) {
    final StringValue oldPositionValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("oldPosition");
    final StringValue newPositionValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("newPosition");
    final StringValue outValue = this.getComponent().getRequest().getQueryParameters().getParameterValue("out");
    final StringValue componentPathValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("componentPath");

    final int oldPosition = oldPositionValue.toInt();
    final int newPosition = newPositionValue.toInt();
    final boolean out = outValue.toBoolean();
    final String droppedComponentPath = componentPathValue.toString("");
    final String boundComponentPath = this.getComponent().getPageRelativePath();

    if (boundComponentPath.equals(droppedComponentPath)) {

        /* The dropped component is one of our list items */
        if (out) {
            /* Item was dragged outside of the list, remove it */
            this.onRemove(target, oldPosition, newPosition);
        } else {//www .j  av  a2  s. c  o m
            /* Item was dragged within the list, update position */
            this.onPositionChanged(target, oldPosition, newPosition);
        }
    } else {

        /* Retrieve the dropped component by its path and insert its model into the list */
        final Component droppedComponent = this.getComponent().getPage().get(droppedComponentPath);
        Object droppedComponentModelObject = null;
        if (droppedComponent != null) {
            droppedComponentModelObject = droppedComponent.getDefaultModelObject();
        }
        this.onInsert(target, droppedComponentModelObject, newPosition);
    }
}

From source file:net.dontdrinkandroot.wicket.behavior.ajax.KeyEventBehavior.java

License:Apache License

@Override
protected void onEvent(AjaxRequestTarget target) {

    final StringValue altKeyValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("keyEvent.altKey");
    final boolean altKey = altKeyValue.toBoolean();

    final StringValue charCodeValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("keyEvent.charCode");
    final int charCode = charCodeValue.toInt();

    final StringValue ctrlKeyValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("keyEvent.ctrlKey");
    final boolean ctrlKey = ctrlKeyValue.toBoolean();

    final StringValue keyCodeValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("keyEvent.keyCode");
    final int keyCode = keyCodeValue.toInt();

    final StringValue metaKeyValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("keyEvent.metaKey");
    final boolean metaKey = metaKeyValue.toBoolean();

    final StringValue shiftKeyValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("keyEvent.shiftKey");
    final boolean shiftKey = shiftKeyValue.toBoolean();

    final StringValue whichValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("keyEvent.which");
    final int which = whichValue.toInt();

    this.onEvent(target, new KeyEventResponse(which, keyCode, charCode, altKey, ctrlKey, metaKey, shiftKey));
}

From source file:net.dontdrinkandroot.wicket.behavior.jqueryui.SortableBehavior.java

License:Apache License

@Override
protected void respond(AjaxRequestTarget target) {

    final StringValue oldPositionValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("oldPosition");
    final StringValue newPositionValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("newPosition");
    final StringValue outValue = this.getComponent().getRequest().getQueryParameters().getParameterValue("out");
    final StringValue componentPathValue = this.getComponent().getRequest().getQueryParameters()
            .getParameterValue("componentPath");

    int oldPosition = oldPositionValue.toInt();
    int newPosition = newPositionValue.toInt();
    boolean out = outValue.toBoolean();
    String droppedComponentPath = componentPathValue.toString("");
    String boundComponentPath = this.getComponent().getPageRelativePath();

    if (boundComponentPath.equals(droppedComponentPath)) {

        /* The dropped component is one of our list items */
        if (out) {
            /* Item was dragged outside of the list, remove it */
            this.onRemove(target, oldPosition);
        } else {// w  ww .ja  v a 2 s  .  c  om
            /* Item was dragged within the list, update position */
            this.onPositionChanged(target, oldPosition, newPosition);
        }

    } else {

        /* Retrieve the dropped component by its path and insert its model into the list */
        Component droppedComponent = this.getComponent().getPage().get(droppedComponentPath);
        Object droppedComponentModelObject = null;
        if (droppedComponent != null) {
            droppedComponentModelObject = droppedComponent.getDefaultModelObject();
        }
        this.onInsert(target, droppedComponentModelObject, newPosition);
    }
}

From source file:net.rrm.ehour.ui.manage.customer.CustomerManagePage.java

License:Open Source License

public CustomerManagePage(PageParameters params) {
    this();/* ww  w.j a  v a2s  .c  o  m*/

    StringValue id = params.get("id");

    if (!id.isEmpty()) {
        try {
            CustomerAdminBackingBean editBean = createEditBean(id.toInt());

            AddEditTabbedPanel<CustomerAdminBackingBean> tabbedPanel = getTabbedPanel();
            tabbedPanel.forceLoadEditTab(editBean);
        } catch (Exception e) {

        }
    }
}

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

License:Apache License

@Override
public void process(final IFormSubmitter _submittingComponent) {
    // if their is a GridXComponent convert the ids to oids
    visitChildren(GridXComponent.class, new IVisitor<GridXComponent, Void>() {

        @Override/* w  w w . j  av  a  2 s . c  o  m*/
        public void component(final GridXComponent _gridX, final IVisit<Void> _visit) {
            try {
                final EFapsRequestParametersAdapter parameters = (EFapsRequestParametersAdapter) getRequest()
                        .getRequestParameters();
                final List<StringValue> selectedRows = parameters.getParameterValues("selectedRow");
                if (CollectionUtils.isNotEmpty(selectedRows)) {
                    final List<StringValue> newValues = new ArrayList<>();
                    for (final StringValue value : selectedRows) {
                        final UIGrid uiGrid = (UIGrid) _gridX.getDefaultModelObject();
                        final Row row = uiGrid.getValues().get(value.toInt());
                        newValues.add(StringValue.valueOf(row.getInstance().getOid()));
                    }
                    parameters.setParameterValues("selectedRow", newValues);
                }
            } catch (StringValueConversionException | EFapsException e) {
                FormContainer.LOG.error("Catched exeption", e);
            }
        }
    });

    // for a dropdown add the previous value as a parameter
    if (_submittingComponent instanceof AjaxFormSubmitter
            && ((AjaxFormSubmitter) _submittingComponent).getFormSubmittingComponent() != null
            && ((AjaxFormSubmitter) _submittingComponent)
                    .getFormSubmittingComponent() instanceof DropDownField) {
        final Object object = ((DropDownField) ((AjaxFormSubmitter) _submittingComponent)
                .getFormSubmittingComponent()).getDefaultModelObject();
        if (object instanceof DropDownOption) {
            final String key = ((DropDownField) ((AjaxFormSubmitter) _submittingComponent)
                    .getFormSubmittingComponent()).getInputName();
            ((EFapsRequestParametersAdapter) ((EFapsRequest) RequestCycle.get().getRequest())
                    .getRequestParameters()).addParameterValue(key + "_eFapsPrevious",
                            ((DropDownOption) object).getValue());
        }
    }
    super.process(_submittingComponent);
    // it must be ensured that the counter for sets is rested or we have big problems
    resetSetCounter();
}