Serve different Markup Files for Page in Wicket - wicket

Lets say i want 3 different *.html for a WebPage. F.e. page_small.html,page_tablet.html, page_desktop.html.
How can i detext the screensize and depending on the screen serve one of my 3 *.html
I found wickets getVariation but i cant find a good explanation or example. But is this the right way and can someone provide an example?
#Override
public String getVariation() {
WebClientInfo info = (WebClientInfo) Session.get().getClientInfo();
ClientProperties p = info.getProperties();
p.setJavaScriptEnabled(true);
p.setNavigatorJavaEnabled(true);
System.out.println(p.toString());
// Defaults to -1 ????
int width = p.getScreenWidth();
String size;
System.out.println("width = "+width);
if (width < 1024) {
size = "small";
} else if (width < 1280) {
size = "medium";
} else {
size = "large";
}
String s = super.getVariation();
return s == null ? size : s + "_" + size;
}
but width= -1

You need to render at least one page to be able to get the browser info and then use it while rendering the following pages to decide what variation to use.
You can use getRequestCycleSettings().setGatherExtendedBrowserInfo(true); as #svenmeier suggested or use AjaxClientInfoBehavior as shown at http://examples7x.wicket.apache.org/ajaxhellobrowser/
But I'd recommend if you use responsive design, i.e. CSS media queries.

Your application does not configure Wicket to gather extended browser information:
protected void init() {
getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
}

Related

Is there way to auto resize percentage columns when column group is collapsed/expaned in NatTable

I found ResizeColumnHideShowLayer class at nattable version 1.6.
(about https://bugs.eclipse.org/bugs/show_bug.cgi?id=521486)
That is work fine for normal column headers only.
But, if I collapse a column group, no adjust size to fit window. (no increasing column size)
How can I solve the problem?
Is there way to resize other columns to fit window automatically increase?
Thank you.
Currently not because the ColumnGroupExpandCollapseLayer is taking care of hiding collapsed columns.
I found solution by myself!
It works fine very well. :-)
I was run based on NatTable v1.6 version.(downloaded yesterday)
I think this is a basic feature, so I hope this feature will be included in the next NatTable version.
In narrow tables, behavior that collapsing column group means that may be someone want to view other column data more widely.
Overview (Problem screen and solved screen)
I explain using two application(before, after) screen shot.
Refer to bottom image if you want understand my issue easily at once.
Problem screen
enter image description here
Improved screen
enter image description here
Solution summary :
Add event listener to ColumnGroupExpandCollapseLayer.
      (HideColumnPositionsEvent, ShowColumnPositionsEvent)
Handle above events.
      Get column indices which is hidden by collapsed
      Execute MultiColumnHideCommand with the indices
Layer structure of my test code
↑ ViewportLayer (top layer)
| SelectionLayer
| ColumnGroupExpandCollapseLayer
| ResizeColumnHideShowLayer
| ColumnGroupReorderLayer
| ColumnReorderLayer
| DataLayer (base layer)
Implementation code is below:
void method() {
...
columnGroupExpandCollapseLayer.addLayerListener(new ILayerListener() {
#Override
public void handleLayerEvent(ILayerEvent event) {
boolean doRedraw = false;
//It works for HideColumnPositionsEvent and ShowColumnPositionsEvent
// triggered by ColumnGroupExpandCollapseCommandHandler
if (event instanceof HideColumnPositionsEvent) {
HideColumnPositionsEvent hideEvent = (HideColumnPositionsEvent)event;
Collection<Range> columnPositionRanges = hideEvent.getColumnPositionRanges();
Collection<Integer> convertIntegerCollection = convertIntegerCollection(columnPositionRanges);
int[] positions = convertIntPrimitiveArray(convertIntegerCollection);
//Execute command to hide columns that was hidden by collapsed column group.
MultiColumnHideCommand multiColumnHideCommand = new MultiColumnHideCommand(resizeColumnHideShowLayer, positions);
resizeColumnHideShowLayer.doCommand(multiColumnHideCommand);
doRedraw = true;
}else if (event instanceof ShowColumnPositionsEvent) {//called by ColumnGroupCollapsedCollapseCommandHandler
ShowColumnPositionsEvent showEvent = (ShowColumnPositionsEvent)event;
Collection<Range> columnPositionRanges = showEvent.getColumnPositionRanges();
Collection<Integer> positions = convertIntegerCollection(columnPositionRanges);
//Execute command to show columns that was hidden by expanded column group.
MultiColumnShowCommand multiColumnShowCommand = new MultiColumnShowCommand(positions);
resizeColumnHideShowLayer.doCommand(multiColumnShowCommand);
//Set whether or not to redraw table
doRedraw = true;
}
if (doRedraw) {
natTable.redraw();
}
}
/**
* Merge position values within several Ranges to Integer collection
*/
private Collection<Integer> convertIntegerCollection(Collection<Range> rangeCollection) {
Iterator<Range> rangeIterator = rangeCollection.iterator();
Set<Integer> mergedPositionSet = new HashSet<Integer>();
while (rangeIterator.hasNext()) {
Range range = rangeIterator.next();
mergedPositionSet.addAll(range.getMembers());
}
return mergedPositionSet;
}
/**
* Convert Integer wrapper object to primitive value
*/
private int [] convertIntPrimitiveArray(Collection<Integer> integerCollection) {
Integer [] integers = (Integer [])integerCollection.toArray(new Integer[integerCollection.size()]);
int [] positionPrimitives = new int[integers.length];
for (int i = 0 ; i < integers.length ; i++) {
positionPrimitives[i] = integers[i].intValue();
}
return positionPrimitives;
}
});
}

Proper way to implement custom Css attribute with Itext and html2Pdf

I'm using Itext 7 and their html2Pdf lib.
Is there a way to implement for example cmyk colors.
.wootWorkingCMYK-color{
color: cmyk( 1 , 0.69 , 0.08 , 0.54);
}
I know the itext core part pretty good, looking for away to use the html2Pdf side. I'm aware of the CssApplierFactory but this seems to be to far up the chain.
Well, of course there is a way of processing custom CSS properties like cmyk colors, but unfortunately the code would be quite bulky and you will need to write quite some code for different cases. I will show how to apply custom color for font, but e.g. for backgrounds, borders or other cases you will need to write separate code in a similar way. Reason behind it is that iText layout structure, although designed with HTML/CSS in mind, is not 100% similar and has some differences you have to code around.
Having that said, if you can fork, build and use your custom version from sources, this is the way I would advice to go. Although it has drawbacks like having to rebase to get updates, the solution would be simpler and more generic. To do that, search for usages of CssUtils.parseRgbaColor in pdfHTML module, and you will find that it is used in BackgroundApplierUtil, BorderStyleApplierUtil, FontStyleApplierUtil, OutlineApplierUtil. There you will find code like
if (!CssConstants.TRANSPARENT.equals(cssColorPropValue)) {
float[] rgbaColor = CssUtils.parseRgbaColor(cssColorPropValue);
Color color = new DeviceRgb(rgbaColor[0], rgbaColor[1], rgbaColor[2]);
float opacity = rgbaColor[3];
transparentColor = new TransparentColor(color, opacity);
} else {
transparentColor = new TransparentColor(ColorConstants.BLACK, 0f);
}
Which I belive you can tweak to process cmyk as well, knowing that you know core part pretty well.
Now, the solution without custom pdfHTML version is to indeed start with implementing ICssApplierFactory, or subclassing default implementation DefaultCssApplierFactory. We are mostly interested in customizing implementation of SpanTagCssApplier and BlockCssApplier, but you can consult with DefaultTagCssApplierMapping to get the full list of appliers and cases they are used in, so that you can decide which of them you want to process in your code.
I will show you how to add support for custom color space for font color in the two main applier classes I mentioned and you can work from there.
private static class CustomCssApplierFactory implements ICssApplierFactory {
private static final ICssApplierFactory DEFAULT_FACTORY = new DefaultCssApplierFactory();
#Override
public ICssApplier getCssApplier(IElementNode tag) {
ICssApplier defaultApplier = DEFAULT_FACTORY.getCssApplier(tag);
if (defaultApplier instanceof SpanTagCssApplier) {
return new CustomSpanTagCssApplier();
} else if (defaultApplier instanceof BlockCssApplier) {
return new CustomBlockCssApplier();
} else {
return defaultApplier;
}
}
}
private static class CustomSpanTagCssApplier extends SpanTagCssApplier {
#Override
protected void applyChildElementStyles(IPropertyContainer element, Map<String, String> css, ProcessorContext context, IStylesContainer stylesContainer) {
super.applyChildElementStyles(element, css, context, stylesContainer);
String color = css.get("color2");
if (color != null) {
color = color.trim();
if (color.startsWith("cmyk")) {
element.setProperty(Property.FONT_COLOR, new TransparentColor(parseCmykColor(color)));
}
}
}
}
private static class CustomBlockCssApplier extends BlockCssApplier {
#Override
public void apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker) {
super.apply(context, stylesContainer, tagWorker);
IPropertyContainer container = tagWorker.getElementResult();
if (container != null) {
String color = stylesContainer.getStyles().get("color2");
if (color != null) {
color = color.trim();
if (color.startsWith("cmyk")) {
container.setProperty(Property.FONT_COLOR, new TransparentColor(parseCmykColor(color)));
}
}
}
}
}
// You might want a safer implementation with better handling of corner cases
private static DeviceCmyk parseCmykColor(String color) {
final String delim = "cmyk(), \t\r\n\f";
StringTokenizer tok = new StringTokenizer(color, delim);
float[] res = new float[]{0, 0, 0, 0};
for (int k = 0; k < 3; ++k) {
if (tok.hasMoreTokens()) {
res[k] = Float.parseFloat(tok.nextToken());
}
}
return new DeviceCmyk(res[0], res[1], res[2], res[3]);
}
Having that custom code, you should configure the ConverterProperties accordingly and pass it to HtmlConverter:
ConverterProperties properties = new ConverterProperties();
properties.setCssApplierFactory(new CustomCssApplierFactory());
HtmlConverter.convertToPdf(..., properties);
You might have noticed that I used color2 instead of color, and this is for a reason. pdfHTML has a mechanism of CSS property validation (as browsers do as well), to discard invalid CSS properties when calculating effective properties for an element. Unfortunately, there is no mechanism of customizing this validation logic currently and of course it treats cmyk colors as invalid declarations at the moment. Thus, if you really want to have custom color property, you will have to preprocess your HTML and replace declarations like color: cmyk... to color2: cmyk.. or whatever the property name you might want to use.
As I mentioned at the start of the answer, my recommendation is to build your own custom version :)

TYPO3 News Lightbox

TYPO3 6.2.13, News (tx_news) 3.2.2, Detail views.
Is there a setting to have pop-ups for any image in the detail views?
I see I may use TS plugin.tx_news.settings.detail.media.image.lightbox.enabled, but I am not sure about what it is supposed to output.
Moreover, is there a way/instructions to integrate something like lightbox into templates for News views?
thks
You can add configuration in your TypoScript setyp (fancybox example):
plugin.tx_news.settings.detail.media {
image {
lightbox {
enabled = 1
class = fancybox
width = 200
height = 200
rel = fancybox[myImageSet]
}
}
}
And in your JS file add:
$(document).ready(function() {
$(".fancybox").fancybox();
});
You will have to include appropriate JS files.
It helped me 3 years later. but there is something wrong in your code, detaildetail ... better for other people are also looking for that is, only one detail :-)
plugin.tx_news.settings.detail.media {
image {
lightbox {
enabled = 1
class = fancybox
width = 200
height = 200
rel = fancybox[myImageSet]
}
}
}

Website not working when viewed online

I have just finished building a website for client, instantinteriors.com.au. (Visit this site for source code.)
For some reason, when I view the website in Firefox offline as a file it looks like it should. Upon upload the sizing becomes different, such as the font and div sizes. There is also a failure in some of my scripts to operate.
The website appears to work fine in Safari and Chrome, haven't checked on a Windows yet. There also seems to be something wrong with the form, as I have everything ready working and testing, although as soon as it went onto the host server the client uses it fails.
The reason I emphasise client's server is that when I tested it earlier on the host I use it worked fine.
Here is one of many scripts appearing to fail...
<script type="text/javascript">
$.fn.hasOverflow = function() {
var $this = $(this);
var $children = $this.find('*');
var len = $children.length;
if (len) {
var maxWidth = 0;
var maxHeight = 0
$children.map(function(){
maxWidth = Math.max(maxWidth, $(this).outerWidth(true));
maxHeight = Math.max(maxHeight, $(this).outerHeight(true));
});
return maxWidth > $this.width() || maxHeight > $this.height();
}
return false;
};
$(function() {
var $content = $('#wrap4').children().wrapAll('<div>');
if($content.hasOverflow()){
$("#arrows").css("display", "none");
} else {
$("#arrows").css("display", "block");
}
});
</script>
Is your logic correct? Your hasOverflow function returns true when either your maxWidth or maxHeight is greater than your current width and height. If you have overflow shouldn't the test be if either the current values are greater than the maximums?
You should switch the way you use the hasOverflow result so the arrows are shown when you have overflow. You can use the show() and hide() methods as shorthand.
if($content.hasOverflow()) {
$("#arrows").show();
} else {
$("#arrows").hide();
}
Is this being called when the document is ready? The source formatting makes it hard to tell.

Does JasperReports support alternating gutter margins yet?

Many people who generate PDFs need to bind them. A good binding requires that every other page support an alternate margin size on its left and right sides. I know JasperReports did not support this in its 3.x series. Is this supported in the 4.x series?
You can accomplish marginMirroring as mentioned by Dave, by subclassing JRPdfExporter, overriding the method, exportReportToStream. Unfortunately, you will need to copy the source for this method into your override. In your override, you will modify the page loop, like so:
for(int pageIndex = startPageIndex; pageIndex <= endPageIndex; pageIndex++)
{
int margin = marginLeft;
if (pageIndex % 2 == 1) margin = marginRight;
parameters.put(JRExporterParameter.OFFSET_X, margin);
setOffset();
...
The constructor for my subclass takes in the margins:
public MirroringJRPdfExporter(int left, int right, int top, int bottom) {
this.marginLeft = left;
this.marginRight = right;
this.marginTop = top;
this.marginBottom = bottom;
}
I took in top and bottom too, just in case I needed to mirror that for page flipping.
Another unfortunate note, exportReportToStream uses a helper, JRPdfExporterTagHelper, and calls 2 methods, init and setPdfWriter, which are protected, so your subclass will not compile unless you subclass the helper too and expose those methods to your subclass. I did this:
public class JRPdfExporterTagHelper extends
net.sf.jasperreports.engine.export.JRPdfExporterTagHelper {
protected JRPdfExporterTagHelper(JRPdfExporter exporter) {
super(exporter);
}
public void setPdfWriter2(PdfWriter pdfWriter) {
setPdfWriter(pdfWriter);
}
public void init2(PdfContentByte pdfContentByte) {
init(pdfContentByte);
}
}
Then, I call it like this:
MirroringJRPdfExporter exporter = new MirroringJRPdfExporter(72, 36, 44, 31);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, output);
exporter.exportReport();
In JasperReports 6.x you can specify margins for even and odd pages separately in the report template (jrxml) by setting
<property name="net.sf.jasperreports.export.pdf.odd.page.offset.x" value="10"/>
<property name="net.sf.jasperreports.export.pdf.even.page.offset.x" value="-10"/>
An example can be found from the JasperReports sample file demo/samples/query/reports/QueryReport.jrxml. I found this solution in an issue.
The same can be set using the JRPdfExporter class when exporting the report to pdf in Java:
JRPdfExporter exporter = new JRPdfExporter();
SimplePdfReportConfiguration configuration = new SimplePdfReportConfiguration();
configuration.setOddPageOffsetX(10);
configuration.setEvenPageOffsetX(-10);
exporter.setConfiguration(configuration);
To work with jasper 5.6 besides the answer to #bigspotteddog I did:
#Override
protected PdfReportConfiguration getCurrentItemConfiguration() {
SimplePdfReportConfiguration config = new SimplePdfReportConfiguration();
PdfReportConfiguration currentItemConfiguration = super.getCurrentItemConfiguration();
config.setCollapseMissingBookmarkLevels(currentItemConfiguration.isCollapseMissingBookmarkLevels());
config.setForceLineBreakPolicy(currentItemConfiguration.isForceLineBreakPolicy());
config.setForceSvgShapes(currentItemConfiguration.isForceSvgShapes());
config.setIgnoreHyperlink(currentItemConfiguration.isIgnoreHyperlink());
config.setOverrideHints(currentItemConfiguration.isOverrideHints());
config.setSizePageToContent(currentItemConfiguration.isSizePageToContent());
config.setEndPageIndex(currentItemConfiguration.getEndPageIndex());
config.setExporterFilter(currentItemConfiguration.getExporterFilter());
config.setHyperlinkProducerFactory(currentItemConfiguration.getHyperlinkProducerFactory());
config.setPageIndex(currentItemConfiguration.getPageIndex());
config.setProgressMonitor(currentItemConfiguration.getProgressMonitor());
config.setStartPageIndex(currentItemConfiguration.getStartPageIndex());
config.setOffsetX(margin);
return config;
}
and :
margin = marginLeft;
if (pageIndex % 2 == 1) margin = marginRight;
in the loop.