Java Code Examples for org.apache.wicket.util.string.StringValue#toInt()

The following examples show how to use org.apache.wicket.util.string.StringValue#toInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelloDbResponse.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void respond(Attributes attributes) 
{
 final StringValue queriesParam = attributes.getRequest().getQueryParameters().getParameterValue("queries");
 int qs = queriesParam.toInt(1);
 if (qs < 1)
 {
  qs = 1;
 }
 else if (qs > 500)
 {
  qs = 500;
 }
 final int queries = qs;

 try 
 {
byte[] data = getDataFromDatabase(queriesParam, queries);

final WebResponse webResponse = (WebResponse) attributes.getResponse();
webResponse.setContentLength(data.length);
webResponse.setContentType(HelloJsonResponse.APPLICATION_JSON);
webResponse.write(data);
 } 
 catch (Exception ex)
 {
WebResponse response = (WebResponse) attributes.getResponse();

response.setContentType(TEXT_PLAIN);
response.setStatus(500);
response.write(ex.getClass().getSimpleName() + ": " + ex.getMessage());

ex.printStackTrace();
 }
}
 
Example 2
Source File: WicketUtils.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
public static int getAsInt(final PageParameters parameters, final String name, final int defaultValue)
{
  final StringValue sval = parameters.get(name);
  if (sval == null || sval.isNull() == true) {
    return defaultValue;
  } else {
    return sval.toInt();
  }
}
 
Example 3
Source File: AnnotationPage.java    From webanno with Apache License 2.0 4 votes vote down vote up
protected void updateDocumentView(AjaxRequestTarget aTarget, SourceDocument aPreviousDocument,
        StringValue aFocusParameter)
{
    SourceDocument currentDocument = getModelObject().getDocument();
    if (currentDocument == null) {
        return;
    }
    
    // If we arrive here and the document is not null, then we have a change of document
    // or a change of focus (or both)
    
    // Get current focus unit from parameters
    int focus = 0;
    if (aFocusParameter != null) {
        focus = aFocusParameter.toInt(0);
    }
    // If there is no change in the current document, then there is nothing to do. Mind
    // that document IDs are globally unique and a change in project does not happen unless
    // there is also a document change.
    if (aPreviousDocument != null && aPreviousDocument.equals(currentDocument)
            && focus == getModelObject().getFocusUnitIndex()) {
        return;
    }
    
    // never had set a document or is a new one
    if (aPreviousDocument == null ||
            !aPreviousDocument.equals(currentDocument)) { 
        actionLoadDocument(aTarget, focus);
    }
    else {
        try {
            getModelObject().moveToUnit(getEditorCas(), focus, TOP);
            actionRefreshDocument(aTarget);
        }
        catch (Exception e) {
            aTarget.addChildren(getPage(), IFeedback.class);
            LOG.info("Error reading CAS " + e.getMessage());
            error("Error reading CAS " + e.getMessage());
        }
    }
}