use of org.apache.wicket.markup.head.IHeaderResponse in project syncope by apache.
the class Relationships method getViewFragment.
private Fragment getViewFragment() {
final Map<String, List<RelationshipTO>> relationships = new HashMap<>();
addRelationship(relationships, getCurrentRelationships().toArray(new RelationshipTO[] {}));
final Fragment viewFragment = new Fragment("relationships", "viewFragment", this);
viewFragment.setOutputMarkupId(true);
viewFragment.add(new Accordion("relationships", relationships.keySet().stream().map(relationship -> {
return new AbstractTab(new ResourceModel("relationship", relationship)) {
private static final long serialVersionUID = 1037272333056449378L;
@Override
public Panel getPanel(final String panelId) {
return new ListViewPanel.Builder<>(RelationshipTO.class, pageRef).setItems(relationships.get(relationship)).includes("otherEndType", "otherEndKey").addAction(new ActionLink<RelationshipTO>() {
private static final long serialVersionUID = -6847033126124401556L;
@Override
public void onClick(final AjaxRequestTarget target, final RelationshipTO modelObject) {
removeRelationships(relationships, modelObject);
send(Relationships.this, Broadcast.DEPTH, new ListViewReload<>(target));
}
}, ActionType.DELETE, AnyEntitlement.UPDATE.getFor(anyTO.getType()), true).build(panelId);
}
};
}).collect(Collectors.toList())) {
private static final long serialVersionUID = 1037272333056449379L;
@Override
public void renderHead(final IHeaderResponse response) {
super.renderHead(response);
if (relationships.isEmpty()) {
response.render(OnDomReadyHeaderItem.forScript(String.format("$('#emptyPlaceholder').append(\"%s\")", getString("relationships.empty.list"))));
}
}
});
final ActionsPanel<RelationshipTO> panel = new ActionsPanel<>("actions", null);
viewFragment.add(panel);
panel.add(new ActionLink<RelationshipTO>() {
private static final long serialVersionUID = 3257738274365467945L;
@Override
public void onClick(final AjaxRequestTarget target, final RelationshipTO ignore) {
Fragment addFragment = new Fragment("relationships", "addFragment", Relationships.this);
addOrReplace(addFragment);
addFragment.add(new Specification().setRenderBodyOnly(true));
target.add(Relationships.this);
}
}, ActionType.CREATE, AnyEntitlement.UPDATE.getFor(anyTO.getType())).hideLabel();
return viewFragment;
}
use of org.apache.wicket.markup.head.IHeaderResponse in project wicket by apache.
the class WebPage method validateHeaders.
/**
* Validate that each component which wanted to contribute to the header section actually was
* able to do so.
*/
private void validateHeaders() {
// search for HtmlHeaderContainer in the first level of children or deeper
// if there are transparent resolvers used
HtmlHeaderContainer header = visitChildren(new IVisitor<Component, HtmlHeaderContainer>() {
@Override
public void component(final Component component, final IVisit<HtmlHeaderContainer> visit) {
if (component instanceof HtmlHeaderContainer) {
visit.stop((HtmlHeaderContainer) component);
} else if (component instanceof TransparentWebMarkupContainer == false) {
visit.dontGoDeeper();
}
}
});
if (header == null) {
// the markup must at least contain a <body> tag for wicket to automatically
// create a HtmlHeaderContainer. Log an error if no header container
// was created but any of the components or behaviors want to contribute
// something to the header.
header = new HtmlHeaderContainer(HtmlHeaderSectionHandler.HEADER_ID);
add(header);
RequestCycle requestCycle = getRequestCycle();
Response orgResponse = requestCycle.getResponse();
try {
StringResponse tempResponse = new StringResponse();
requestCycle.setResponse(tempResponse);
// Render all header sections of all components on the page
AbstractHeaderRenderStrategy.get().renderHeader(header, null, getPage());
IHeaderResponse headerResponse = header.getHeaderResponse();
headerResponse.close();
CharSequence collectedHeaderOutput = tempResponse.getBuffer();
if (collectedHeaderOutput.length() > 0) {
reportMissingHead(collectedHeaderOutput);
}
} catch (Exception e) {
// just swallow this exception, there isn't much we can do about.
log.error("header/body check throws exception", e);
} finally {
this.remove(header);
requestCycle.setResponse(orgResponse);
}
}
}
use of org.apache.wicket.markup.head.IHeaderResponse in project wicket by apache.
the class FilteringHeaderResponse method getContent.
/**
* Gets the content that was rendered to this header response and matched the filter with the
* given name.
*
* @param filterName
* the name of the filter to get the bucket for
* @return the content that was accepted by the filter with this name
*/
@SuppressWarnings("resource")
public final CharSequence getContent(String filterName) {
if (filterName == null || !responseFilterMap.containsKey(filterName)) {
return "";
}
List<HeaderItem> resp = responseFilterMap.get(filterName);
final StringResponse strResponse = new StringResponse();
IHeaderResponse headerRenderer = new HeaderResponse() {
@Override
protected Response getRealResponse() {
return strResponse;
}
@Override
public boolean wasRendered(Object object) {
return FilteringHeaderResponse.this.getRealResponse().wasRendered(object);
}
@Override
public void markRendered(Object object) {
FilteringHeaderResponse.this.getRealResponse().markRendered(object);
}
};
headerRenderer = decorate(headerRenderer);
for (HeaderItem curItem : resp) {
headerRenderer.render(curItem);
}
headerRenderer.close();
return strResponse.getBuffer();
}
use of org.apache.wicket.markup.head.IHeaderResponse in project wicket by apache.
the class SimplePage2 method addXXX.
private MarkupContainer addXXX(final String id, final MarkupContainer parent) {
MarkupContainer container = new WebMarkupContainer(id);
parent.add(container);
container.add(new Behavior() {
private static final long serialVersionUID = 1L;
@Override
public void renderHead(Component component, IHeaderResponse response) {
response.render(CssHeaderItem.forUrl(id + ".css"));
}
});
return container;
}
use of org.apache.wicket.markup.head.IHeaderResponse in project wicket by apache.
the class Component method internalRenderHead.
/**
* THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT!
*
* Print to the web response what ever the component wants to contribute to the head section.
* Make sure that all attached behaviors are asked as well.
* <p>
* NOT intended for overriding by framework clients. Rather, use
* {@link Component#renderHead(org.apache.wicket.markup.head.IHeaderResponse)}
* </p>
*
* @param container
* The HtmlHeaderContainer
*/
public void internalRenderHead(final HtmlHeaderContainer container) {
if (isVisibleInHierarchy() && isRenderAllowed()) {
if (log.isDebugEnabled()) {
log.debug("internalRenderHead: {}", toString(false));
}
IHeaderResponse response = container.getHeaderResponse();
// Allow component to contribute
if (response.wasRendered(this) == false) {
StringResponse markupHeaderResponse = new StringResponse();
Response oldResponse = getResponse();
RequestCycle.get().setResponse(markupHeaderResponse);
try {
// Make sure the markup source strategy contributes to the header first
// to be backward compatible. WICKET-3761
getMarkupSourcingStrategy().renderHead(this, container);
CharSequence headerContribution = markupHeaderResponse.getBuffer();
if (Strings.isEmpty(headerContribution) == false) {
response.render(StringHeaderItem.forString(headerContribution));
}
} finally {
RequestCycle.get().setResponse(oldResponse);
}
// Then let the component itself to contribute to the header
renderHead(response);
response.markRendered(this);
}
// Then ask all behaviors
for (Behavior behavior : getBehaviors()) {
if (isBehaviorAccepted(behavior)) {
if (response.wasRendered(behavior) == false) {
behavior.renderHead(this, response);
List<IClusterable> pair = Arrays.asList(this, behavior);
response.markRendered(pair);
}
}
}
}
}
Aggregations