use of org.apache.wicket.Response in project gitblit by gitblit.
the class ObjectContainer method onComponentTagBody.
@Override
public void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
Response response = getResponse();
response.write("\n");
// add all object's parameters:
for (String name : getParameterNames()) {
String value = getValue(name);
if (value != null) {
response.write("<param name=\"");
response.write(name);
response.write("\" value=\"");
response.write(value);
response.write("\"/>\n");
}
}
super.onComponentTagBody(markupStream, openTag);
}
use of org.apache.wicket.Response in project servoy-client by Servoy.
the class WebEventExecutor method generateDragAttach.
/**
* @param component2
* @param response
*/
@SuppressWarnings("nls")
public static void generateDragAttach(Component component, IHeaderResponse response) {
DraggableBehavior draggableBehavior = null;
Component behaviorComponent = component;
if ((behaviorComponent instanceof IComponent) && !(behaviorComponent instanceof IFormDataDragNDrop)) {
behaviorComponent = (Component) component.findParent(IFormDataDragNDrop.class);
}
if (behaviorComponent != null) {
Iterator<IBehavior> behaviors = behaviorComponent.getBehaviors().iterator();
Object behavior;
while (behaviors.hasNext()) {
behavior = behaviors.next();
if (behavior instanceof DraggableBehavior) {
draggableBehavior = (DraggableBehavior) behavior;
break;
}
}
}
if (draggableBehavior == null)
return;
boolean bUseProxy = draggableBehavior.isUseProxy();
boolean bResizeProxyFrame = draggableBehavior.isResizeProxyFrame();
boolean bXConstraint = draggableBehavior.isXConstraint();
boolean bYConstraint = draggableBehavior.isYConstraint();
CharSequence dragUrl = draggableBehavior.getCallbackUrl();
String jsCode = null;
if (behaviorComponent instanceof IFormDataDragNDrop) {
final StringBuilder sbAttachDrag = new StringBuilder(100);
sbAttachDrag.append("Servoy.DD.attachDrag([");
final StringBuilder sbAttachDrop = new StringBuilder(100);
sbAttachDrop.append("Servoy.DD.attachDrop([");
final boolean hasDragEvent = ((IFormDataDragNDrop) behaviorComponent).getDragNDropController().getForm().getOnDragMethodID() > 0 || ((IFormDataDragNDrop) behaviorComponent).getDragNDropController().getForm().getOnDragOverMethodID() > 0;
final boolean hasDropEvent = ((IFormDataDragNDrop) behaviorComponent).getDragNDropController().getForm().getOnDropMethodID() > 0;
if (component instanceof WebDataRenderer || component instanceof WebCellBasedView) {
if (hasDragEvent)
sbAttachDrag.append('\'').append(component.getMarkupId()).append("',");
if (hasDropEvent)
sbAttachDrop.append('\'').append(component.getMarkupId()).append("',");
if (component instanceof WebDataRenderer) {
Iterator<? extends Component> dataRendererIte = ((WebDataRenderer) component).iterator();
Object dataRendererChild;
while (dataRendererIte.hasNext()) {
dataRendererChild = dataRendererIte.next();
if (dataRendererChild instanceof IWebFormContainer)
continue;
if (dataRendererChild instanceof WrapperContainer)
dataRendererChild = ((WrapperContainer) dataRendererChild).getDelegate();
if (dataRendererChild instanceof IComponent && ((IComponent) dataRendererChild).isEnabled()) {
updateDragAttachOutput(dataRendererChild, sbAttachDrag, sbAttachDrop, hasDragEvent, hasDropEvent);
}
}
} else if (component instanceof WebCellBasedView) {
ListView<IRecordInternal> table = ((WebCellBasedView) component).getTable();
table.visitChildren(new IVisitor<Component>() {
public Object component(Component comp) {
if (comp instanceof IComponent && comp.isEnabled()) {
updateDragAttachOutput(comp, sbAttachDrag, sbAttachDrop, hasDragEvent, hasDropEvent);
}
return null;
}
});
}
} else if (component != null && component.isEnabled()) {
updateDragAttachOutput(component, sbAttachDrag, sbAttachDrop, hasDragEvent, hasDropEvent);
}
if (sbAttachDrag.length() > 25) {
sbAttachDrag.setLength(sbAttachDrag.length() - 1);
sbAttachDrag.append("],'");
sbAttachDrag.append(dragUrl);
sbAttachDrag.append("', ");
sbAttachDrag.append(bUseProxy);
sbAttachDrag.append(", ");
sbAttachDrag.append(bResizeProxyFrame);
sbAttachDrag.append(", ");
sbAttachDrag.append(bXConstraint);
sbAttachDrag.append(", ");
sbAttachDrag.append(bYConstraint);
sbAttachDrag.append(");");
jsCode = sbAttachDrag.toString();
}
if (sbAttachDrop.length() > 25) {
sbAttachDrop.setLength(sbAttachDrop.length() - 1);
sbAttachDrop.append("],'");
sbAttachDrop.append(dragUrl);
sbAttachDrop.append("');");
if (jsCode != null)
jsCode += '\n' + sbAttachDrop.toString();
else
jsCode = sbAttachDrop.toString();
}
if (jsCode != null) {
if (response == null) {
jsCode = (new StringBuilder().append("\n<script type=\"text/javascript\">\n").append(jsCode).append("</script>\n")).toString();
Response cyleResponse = RequestCycle.get().getResponse();
cyleResponse.write(jsCode);
} else
response.renderOnDomReadyJavascript(jsCode);
}
} else // default handling
{
jsCode = "Servoy.DD.attachDrag(['" + component.getMarkupId() + "'],'" + dragUrl + "', " + bUseProxy + ", " + bResizeProxyFrame + ", " + bXConstraint + ", " + bYConstraint + ")";
if (response == null) {
jsCode = (new StringBuilder().append("\n<script type=\"text/javascript\">\n").append(jsCode).append("</script>\n")).toString();
Response cyleResponse = RequestCycle.get().getResponse();
cyleResponse.write(jsCode);
} else
response.renderOnDomReadyJavascript(jsCode);
}
}
use of org.apache.wicket.Response in project servoy-client by Servoy.
the class WebDataLookupField method init.
private void init() {
add(new HeaderContributor(new IHeaderContributor() {
private static final long serialVersionUID = 1L;
public void renderHead(IHeaderResponse response) {
// $NON-NLS-1$
response.renderCSSReference(new CompressedResourceReference(WebDataLookupField.class, "servoy_lookupfield.css"));
}
}) {
@Override
public boolean isEnabled(Component component) {
return !getScriptObject().isReadOnly() && getScriptObject().isEnabled();
}
});
setOutputMarkupPlaceholderTag(true);
AutoCompleteSettings behSettings = new AutoCompleteSettings();
behSettings.setMaxHeightInPx(200);
behSettings.setPreselect(true);
behSettings.setShowCompleteListOnFocusGain(true);
behSettings.setAdjustInputWidth(false);
ClientProperties clp = (application.getApplicationType() != IApplication.HEADLESS_CLIENT ? ((WebClientInfo) Session.get().getClientInfo()).getProperties() : // in case of batch processors/jsp, we can't get browser info because UI is not given by web client components
null);
if (clp != null && (!clp.isBrowserInternetExplorer() || clp.getBrowserVersionMajor() >= 8)) {
// smart positioning doesn't work on IE < 8 (probably because of unreliable clientWidth/clientHeight browser element js properties)
behSettings.setUseSmartPositioning(true);
// don't know if the problem this setting is for can still be reproduced (I couldn't reproduce it)... this is true by default and makes fields in IE and Opera appear/dissapear if they would be covered by type-ahead popup
behSettings.setUseHideShowCoveredIEFix(false);
} else {
behSettings.setUseSmartPositioning(false);
behSettings.setUseHideShowCoveredIEFix(true);
}
behSettings.setThrottleDelay(500);
IAutoCompleteRenderer<Object> renderer = new IAutoCompleteRenderer<Object>() {
protected String getTextValue(Object object) {
// $NON-NLS-1$
String str = "";
if (object instanceof DisplayString) {
str = object.toString();
} else if (object != null && !(object instanceof String)) {
IConverter con = getConverter(object.getClass());
if (con != null) {
str = con.convertToString(object, getLocale());
} else {
str = object.toString();
}
} else if (object != null) {
str = object.toString();
}
// $NON-NLS-1$//$NON-NLS-2$
if (str == null || str.trim().equals(""))
return " ";
return WebBaseButton.sanitize(str, getScriptObject().trustDataAsHtml()).toString();
}
protected void renderChoice(Object object, Response response, String criteria) {
if (IValueList.SEPARATOR_DESIGN_VALUE.equals(object))
return;
String renderedObject = getTextValue(object);
// escape the markup if it is not html or not just an empty none breaking space (null or empty string object)
if (!renderedObject.equals(" ") && !HtmlUtils.hasHtmlTag(renderedObject))
renderedObject = // $NON-NLS-1$
HtmlUtils.escapeMarkup(// $NON-NLS-1$
renderedObject, // $NON-NLS-1$
true, false).toString();
response.write(renderedObject);
}
/*
* (non-Javadoc)
*
* @see org.apache.wicket.extensions.ajax.markup.html.autocomplete.IAutoCompleteRenderer#render(java.lang.Object, org.apache.wicket.Response,
* java.lang.String)
*/
public void render(Object object, Response response, String criteria) {
String textValue = getTextValue(object);
if (textValue == null) {
throw new IllegalStateException("A call to textValue(Object) returned an illegal value: null for object: " + object.toString());
}
textValue = textValue.replaceAll("\\\"", """);
response.write("<li textvalue=\"" + textValue + "\"");
response.write(">");
renderChoice(object, response, criteria);
response.write("</li>");
}
/*
* (non-Javadoc)
*
* @see org.apache.wicket.extensions.ajax.markup.html.autocomplete.IAutoCompleteRenderer#renderHeader(org.apache.wicket.Response)
*/
@SuppressWarnings("nls")
public void renderHeader(Response response) {
StringBuffer listStyle = new StringBuffer();
listStyle.append("style=\"");
String fFamily = "Tahoma, Arial, Helvetica, sans-serif";
String bgColor = "#ffffff";
String fgColor = "#000000";
String fSize = TemplateGenerator.DEFAULT_FONT_SIZE + "px";
String padding = "2px";
String margin = "0px";
if (getFont() != null) {
Font f = getFont();
if (f != null) {
if (f.getFamily() != null) {
fFamily = f.getFamily();
if (fFamily.contains(" "))
fFamily = "'" + fFamily + "'";
}
if (f.getName() != null) {
String fName = f.getName();
if (fName.contains(" "))
fName = "'" + fName + "'";
fFamily = fName + "," + fFamily;
}
if (f.isBold())
listStyle.append("font-weight:bold; ");
if (f.isItalic())
listStyle.append("font-style:italic; ");
fSize = Integer.toString(f.getSize()) + "px";
}
}
if (getListColor() != null && getListColor().getAlpha() == 255) {
// background shouldn't be transparent
bgColor = getWebColor(getListColor().getRGB());
}
if (getForeground() != null) {
fgColor = getWebColor(getForeground().getRGB());
}
Insets _padding = getPadding();
if (getPadding() != null)
padding = _padding.top + "px " + _padding.right + "px " + _padding.bottom + "px " + _padding.left + "px";
listStyle.append("font-family:" + fFamily + "; ");
listStyle.append("background-color: " + bgColor + "; ");
listStyle.append("color: " + fgColor + "; ");
listStyle.append("font-size:" + fSize + "; ");
// extract padding and border
listStyle.append("min-width:" + (getSize().width - 6) + "px; ");
listStyle.append("margin: " + margin + "; ");
listStyle.append("padding: " + padding + "; ");
listStyle.append("text-align:" + TemplateGenerator.getHorizontalAlignValue(getHorizontalAlignment()));
listStyle.append("\"");
response.write("<ul " + listStyle + ">");
}
/*
* (non-Javadoc)
*
* @see org.apache.wicket.extensions.ajax.markup.html.autocomplete.IAutoCompleteRenderer#renderFooter(org.apache.wicket.Response)
*/
public void renderFooter(Response response) {
// $NON-NLS-1$
response.write("</ul>");
}
/**
* Returns web color representation of int rgba color by
* removing the alpha value
*
* @param color int representation of rgba color
* @return web color of form #rrggbb
*/
private String getWebColor(int color) {
String webColor = Integer.toHexString(color);
int startIdx = webColor.length() - 6;
if (startIdx < 0)
startIdx = 0;
webColor = webColor.substring(startIdx);
StringBuilder sb = new StringBuilder();
sb.append('#');
int nrMissing0 = 6 - webColor.length();
for (int i = 0; i < nrMissing0; i++) {
sb.append('0');
}
sb.append(webColor);
return sb.toString();
}
};
AutoCompleteBehavior<Object> beh = new AutoCompleteBehavior<Object>(renderer, behSettings) {
private static final long serialVersionUID = 1L;
/**
* @see org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteBehavior#getChoices(java.lang.String)
*/
@Override
protected Iterator<Object> getChoices(String input) {
String filteredInput = filterInput(input);
if (changeListener != null)
dlm.getValueList().removeListDataListener(changeListener);
try {
dlm.fill(parentState, getDataProviderID(), filteredInput, false);
return dlm.iterator();
} catch (Exception ex) {
Debug.error(ex);
} finally {
if (changeListener != null)
dlm.getValueList().addListDataListener(changeListener);
}
return Collections.emptyList().iterator();
}
/**
* filters the input in case of masked input (removes the mask)
*/
private String filterInput(String input) {
String displayFormat = WebDataLookupField.this.parsedFormat.getDisplayFormat();
if (displayFormat != null && displayFormat.length() > 0 && input.length() == displayFormat.length()) {
int index = firstBlankSpacePosition(input, displayFormat);
if (index == -1)
return input;
return input.substring(0, index);
}
return input;
}
/**
* Computes the index of the first space char found in the input and is not ' ' nor '*' in the format
* Example:
* input '12 - 3 - '
* format '## - ## - #'
* returns 6
* @param input
* @param displayFormat
* @return The index of the first space char found in the input and is not ' ' nor '*' in the format
*/
private int firstBlankSpacePosition(String input, String displayFormat) {
for (int i = 0; i < input.length(); i++) {
if ((input.charAt(i) == ' ') && (displayFormat.charAt(i) != ' ') && (displayFormat.charAt(i) != '*'))
return i;
}
return 0;
}
/**
* @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#getFailureScript()
*/
@Override
protected CharSequence getFailureScript() {
// $NON-NLS-1$
return "onAjaxError();";
}
/**
* @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#getPreconditionScript()
*/
@Override
protected CharSequence getPreconditionScript() {
// $NON-NLS-1$
return "onAjaxCall();" + super.getPreconditionScript();
}
// need to set this behavior to true (enterHidesWithNoSelection) because otherwise the onKeyDown events
// or other events for the component with type ahead would be null in Firefox, and would not execute as
// expected on the other browsers...
@Override
public void renderHead(IHeaderResponse response) {
settings.setShowListOnEmptyInput(Boolean.TRUE.equals(UIUtils.getUIProperty(getScriptObject(), application, IApplication.TYPE_AHEAD_SHOW_POPUP_WHEN_EMPTY, Boolean.TRUE)));
settings.setShowListOnFocusGain(Boolean.TRUE.equals(UIUtils.getUIProperty(getScriptObject(), application, IApplication.TYPE_AHEAD_SHOW_POPUP_ON_FOCUS_GAIN, Boolean.TRUE)));
if (!getScriptObject().isReadOnly() && getScriptObject().isEnabled()) {
super.renderHead(response);
// $NON-NLS-1$ //$NON-NLS-2$
response.renderJavascript("Wicket.AutoCompleteSettings.enterHidesWithNoSelection = true;", "AutocompleteSettingsID");
}
}
/**
* @see org.apache.wicket.behavior.AbstractBehavior#isEnabled(org.apache.wicket.Component)
*/
@Override
public boolean isEnabled(Component component) {
IFormUIInternal<?> formui = findParent(IFormUIInternal.class);
if (formui != null && formui.isDesignMode()) {
return false;
}
return super.isEnabled(component) && WebClientSession.get().useAjax();
}
};
add(beh);
}
use of org.apache.wicket.Response in project servoy-client by Servoy.
the class WebForm method renderHead.
@SuppressWarnings("nls")
@Override
public void renderHead(HtmlHeaderContainer headercontainer) {
super.renderHead(headercontainer);
Response response = headercontainer.getHeaderResponse().getResponse();
response.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"");
StringBuilder sb = new StringBuilder();
sb.append(UrlUtils.rewriteToContextRelative("servoy-webclient/formcss/", RequestCycle.get().getRequest()));
sb.append(formController.getForm().getSolution().getName());
sb.append("/");
sb.append(formController.getName());
sb.append("_t");
long prevLMT = lastModifiedTime;
if (lastModifiedTime == 0 || isUIRecreated()) {
lastModifiedTime = System.currentTimeMillis();
}
sb.append(Long.toString(lastModifiedTime));
sb.append("t.css");
response.write(RequestCycle.get().getOriginalResponse().encodeURL(sb));
response.write("\" id=\"formcss_");
response.write(formController.getName());
response.write(Long.toString(lastModifiedTime));
response.write("\"");
getResponse().println(" />");
if (isUIRecreated()) {
if (this.getParent() instanceof WebTabPanel) {
String tabPanelId = this.getParent().getMarkupId();
String showWebFormjs = "$('#" + getMarkupId() + "').css('visibility','" + (isVisible() ? "inherit" : "hidden") + "');";
// show WebForm after rearrangeTabsInTabPanel() is done
String jsCall = "rearrageTabsInTabPanel('" + tabPanelId + "');" + showWebFormjs;
headercontainer.getHeaderResponse().renderOnLoadJavascript(jsCall);
}
StringBuffer cssRef = new StringBuffer();
cssRef.append("Servoy.Utils.removeFormCssLink('formcss_");
cssRef.append(formController.getName());
cssRef.append(prevLMT);
cssRef.append("');");
headercontainer.getHeaderResponse().renderJavascript(cssRef, null);
}
if (isFormInWindow()) {
List<Component> componentz = getTabSeqComponents();
int max = -1;
int min = Integer.MAX_VALUE;
String maxTabIndexElemId = null;
String minTabIndexElemId = null;
for (Component c : componentz) {
int tabIndex = TabIndexHelper.getTabIndex(c);
if (tabIndex > max) {
max = tabIndex;
maxTabIndexElemId = c.getMarkupId();
}
if (tabIndex != -1 && tabIndex < min) {
min = tabIndex;
minTabIndexElemId = c.getMarkupId();
}
}
if (minTabIndexElemId != null && maxTabIndexElemId != null) {
headercontainer.getHeaderResponse().renderOnLoadJavascript("Servoy.TabCycleHandling.registerListeners('" + minTabIndexElemId + "','" + maxTabIndexElemId + "');");
}
}
if (isFormInFormPopup()) {
TreeMap<String, String> tm = new TreeMap<String, String>();
for (Component c : getTabSeqComponents()) {
tm.put(String.valueOf(TabIndexHelper.getTabIndex(c)), c.getMarkupId());
}
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("Servoy.TabCycleHandling.forceTabbingSequence([");
for (Map.Entry<String, String> entry : tm.entrySet()) {
stringBuffer.append("'" + entry.getValue() + "',");
}
stringBuffer.deleteCharAt(stringBuffer.length() - 1);
stringBuffer.append("]);");
headercontainer.getHeaderResponse().renderOnLoadJavascript(stringBuffer.toString());
}
}
use of org.apache.wicket.Response in project servoy-client by Servoy.
the class MainPage method configureResponse.
/**
* @see wicket.Page#configureResponse()
*/
@SuppressWarnings("nls")
@Override
protected void configureResponse() {
super.configureResponse();
if (getWebRequestCycle().getResponse() instanceof WebResponse) {
final WebResponse response = getWebRequestCycle().getWebResponse();
HTTPUtils.setNoCacheHeaders(response.getHttpServletResponse(), "no-store");
}
final RequestCycle cycle = getRequestCycle();
final Response response = cycle.getResponse();
if (main != null) {
final MarkupStream markupStream = main.getAssociatedMarkupStream(false);
if (markupStream != null) {
// markupStream.setCurrentIndex(0); // this doesn't seem to be needed
MarkupElement m = markupStream.get();
if (m != null) {
String docType = m.toString().trim();
if (docType.toUpperCase().startsWith("<!DOCTYPE")) {
int index = docType.indexOf('>');
if (index != -1) {
// delegate form doctype to be the mainpage doctype
response.write(docType.substring(0, index + 1));
} else {
// delegate form doctype to be the mainpage doctype
response.write(docType);
}
}
}
}
}
}
Aggregations