Why does "paragraph reference component" show empty tiles (Geometrixx example)? - java

I use "paragraph reference component" to include pages/subpages. Why does this component show empty tiles (see the attached pic for Geometrixx)? Can it be configured sothat empty tiles not shows?

Reference component displays contents of the external paragraph system (ie. parsys from a different page). Its browse dialog consists of page tree on the left and tiles presenting paragraph systems belonging to the selected page on the right.
Attached picture presents dialog with Contact page selected. Apparently, this page contains 3 paragraph systems. The first one is probably the main parsys, containing text component filled with the contact information. I think there are two reasons why the second and the third tiles are blank:
they are presenting contents of the empty paragraph systems,
they are referencing Inheritance Paragraph Systems which is not compatible with the Reference component.
I don't think there is an out-of-the-box configuration allowing to hide such empty parsys tiles.

Expanding on from Tomek's answer above, the Reference component is using a paragraphreference xtype, which is defined under /libs/cq/ui/widgets/source/widgets/form/ParagraphReference.js.
If you create an overlay, you should be able to change the defined behaviour for an empty parsys. Within the xtype defined in ParagraphReference.js, there is a function, onSelectPage:
function(node, event) {
this.proxy.api["read"].url =
CQ.HTTP.externalize(node.getPath() + ".paragraphs.json", true);
this.store.reload();
}
From this, it seems that CQ is using a paragraphs selector to get back specific content from a page, e.g. take a look at "/content/geometrixx/en.paragraphs.json". Here is a sample JSON object returned by this request:
{
"paragraphs": [{
"path": "/content/geometrixx/en/jcr:content/par/image",
"html": "\n\n\n\n<div class=\"genericImage\">\n\n \n \n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\t\n\t\t\n\t\t\t <img src=\"/content/dam/geometrixx/portraits/jane_doe.jpg/_jcr_content/renditions/original\" alt=\"Jane Doe\" class=\"cq-dd-image\" title=\"Jane Doe\"/>\n\t\t\n\t\n "
}, {
"path": "/content/geometrixx/en/jcr:content/par/title_1",
"html": "<h2>Strategic Consulting<\/h2>\n"
}, {
"path": "/content/geometrixx/en/jcr:content/par/text_1",
"html": "\n\n\n\n\n\n\n<div class=\"copy\"><p><span class="Apple-style-span" style="font-size: 12px;">In&nbsp;today's competitive market, organizations can face several key geometric challenges:</span></p><br><ul><br><li><span class="Apple-style-span" style="font-size: 12px;">Polyhedral Sectioning</span></li><br><li><span class="Apple-style-span" style="font-size: 12px;">Triangulation&nbsp;</span></li><br><li><span class="Apple-style-span" style="font-size: 12px;">Trigonometric Calculation</span></li><br><li><span class="Apple-style-span" style="font-size: 12px;">Ruler and Compass Construction</span></li><br></ul><br><p><span class="Apple-style-span" style="font-size: 12px;"><br/><br>Geometrixx is ready to help your organization deal effectively with all these challenges through our award winning geometric consulting services.</span></p><br><p style="font-family: tahoma, arial, helvetica, sans-serif; font-size: 12px;"></p><br><\/div>\n\n\n\n\n\n\n\n\n<p>\n\n\n<\/p>\n\n"
}, {
"path": "/content/geometrixx/en/jcr:content/par/image_0",
"html": "\n\n\n\n<div class=\"genericImage\">\n\n \n \n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\t\n\t\t\n\t\t\t <img src=\"/content/dam/geometrixx/offices/clean_room.jpg/_jcr_content/renditions/original\" alt=\"Men at Work in the Clean Room\" class=\"cq-dd-image\" title=\"Men at Work in the Clean Room\"/>\n\t\t\n\t\n "
}, {
"path": "/content/geometrixx/en/jcr:content/par/title_2",
"html": "<h2>Shape Technology<\/h2>\n"
}, {
"path": "/content/geometrixx/en/jcr:content/par/text_0",
"html": "\n\n\n\n\n\n\n<div class=\"copy\"><p>The Geometrixx investment in R&D has done more than solidify our industry leadership role, we have now outpaced our competitors to such an extent that we are in an altogether new space.<\/p>\n<p>This is why our high quality polygons and polyhedra provide the only turnkey solutions across the whole range of euclidean geometry. And our mathematicians are working on the next generation of fractal curves to bring you shapes that are unthinkable today.<\/p>\n<p><\/p>\n<p><\/p>\n\n\n <\/div>\n\n\n\n\n\n\n\n\n<p>\n\n\n<\/p>\n\n"
}, {
"path": "/content/geometrixx/en/jcr:content/rightpar/teaser",
"html": "<script type=\"text/javascript\">\nCQURLInfo = {\n \"contextPath\": null,\n \"requestPath\": '\\/content\\/geometrixx\\/en\\/jcr:content\\/rightpar\\/teaser',\n \"selectorString\": null,\n \"selectors\": [],\n \"extension\": 'html',\n \"suffix\": null,\n \"systemId\": '5859bb1d-dee4-484f-ac0d-d83dc1c013ed',\n \"runModes\": 'lbi,dev,publish'\n};<\/script>\n<script type=\"text/javascript\" src=\"/etc/clientlibs/foundation/librarymanager.js\"><\/script>\n<script type=\"text/javascript\">\nCQClientLibraryManager.write([{\"p\":\"/etc/clientlibs/foundation/jquery.js\",\"c\":[]},{\"p\":\"/etc/clientlibs/foundation/shared.js\",\"c\":[]},{\"p\":\"/etc/clientlibs/foundation/jquery-ui.js\",\"c\":[]},{\"p\":\"/etc/clientlibs/foundation/personalization/jcarousel.css\",\"c\":[]},{\"p\":\"/etc/clientlibs/foundation/personalization/jcarousel.js\",\"c\":[]},{\"p\":\"/etc/clientlibs/foundation/personalization.js\",\"c\":[]},{\"p\":\"/etc/clientlibs/foundation/jquery-ui/themes/default.css\",\"c\":[]},{\"p\":\"/etc/clientlibs/foundation/personalization/themes/default.css\",\"c\":[]},{\"p\":\"/etc/clientlibs/foundation/personalization/ie6/themes/default.css\",\"c\":[\"ie6\"]}],false);\n<\/script>\n<script type=\"text/javascript\">$CQ(function() {initializeTeaserLoader([{\"path\":\"/content/campaigns/geometrixx/scott-recommends\",\"name\":\"scott-recommends\",\"title\":\"Scott Recommends\",\"campainName\":\"geometrixx\",\"thumbnail\":\"/content/campaigns/geometrixx/scott-recommends/jcr:content/par/image.img.png\",\"id\":\"geometrixx_scott-recommends\",\"segments\":[\"/etc/segmentation/geometrixx/male\"],\"tags\":[]},{\"path\":\"/content/campaigns/geometrixx/yolanda-recommends\",\"name\":\"yolanda-recommends\",\"title\":\"Yolanda Recommends\",\"campainName\":\"geometrixx\",\"thumbnail\":\"/content/campaigns/geometrixx/yolanda-recommends/jcr:content/par/image.img.png\",\"id\":\"geometrixx_yolanda-recommends\",\"segments\":[\"/etc/segmentation/geometrixx/female\"],\"tags\":[]},{\"path\":\"/content/campaigns/geometrixx/default_teaser\",\"name\":\"default_teaser\",\"title\":\"Default Teaser\",\"campainName\":\"geometrixx\",\"thumbnail\":\"/content/campaigns/geometrixx/default_teaser/jcr:content/par/image.img.png\",\"id\":\"geometrixx_default_teaser\",\"segments\":[],\"tags\":[]}], \"first\", \"_content_geometrixx_en_jcr_content_rightpar_teaser\", \"false\", \"http://localhost:4502/libs/wcm/stats/tracker\", \"/content/geometrixx/en/jcr:content/rightpar/teaser\");\n });<\/script><div id=\"_content_geometrixx_en_jcr_content_rightpar_teaser\" class=\"campaign campaign-geometrixx\"><noscript><div class=\"par parsys\"><div class=\"title section\"><h3>Get the Geometrixx App<\/h3>\n<\/div>\n<div class=\"text module shadow section imagetext\">\n\n\n\n\n\n\n<div class=\"copy\"><p>All things Geometrixx, anytime, anywhere. Our mobile app is is as groundbreaking and remarkably easy-to-use as our shapes. <\/p><p><\/p>\n\n <\/div>\n\n\n\n\n\n\n\n\n<p>\n\n\n<\/p>\n\n<\/div>\n\n\n\n\n<div class=\"genericImage\">\n\n \n \n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\t\n\t\t\n\t\t\t <img src=\"/content/dam/geometrixx/banners/mobile.jpg/_jcr_content/renditions/original\" alt=\"Geometrixx App\" class=\"cq-dd-image\" title=\"Geometrixx App\"/>\n\t\t\n\t\n <\/div>\n<\/div>\n<\/noscript><\/div>"
}],
"count": 7
}
So maybe use this selector to check out the content of the page currently coming back with blank parsys by using the paragraphs.json selector, (it seems that you need to be authenticated to hit this endpoint).
If is the "html" property of these objects that is blank, you could extend the onSelectPage function in your overlayed version to loop through the array of parsys & copy it's "path" property value to its "html" property for these nodes.

Related

Thymeleaf hide tag wen th:text="#{var}"

Hi I'm trying to hide tags wen the message is empty but I can't seem to figure out how, for what I read if I want to hide and empty variable all I need to do is either with "unless" or "if":
<p th:unless="${#strings.isEmpty(myVar.theEmptyVar)}">
But when I use the message type var It doesn't seem to work the code fails
<p th:unless=""{#strings.isEmpty(messageVar)}">
The closest I got is this but it won't show anything:
<p th:if="${!#strings.isEmpty('[[#{label}]]')}" >
I've been going up and down the thymeleaf documentation and google but I can't seem to find a solution that works, thanks.
Assuming you have label, which is an empty entry in a messages file, like this:
label=
...then you can use the following in your Thymeleaf template:
<p th:if=" ! ${#strings.isEmpty(#messages.msg('label'))}">
my text
</p>
The ! is a negation ("not"). Therefore, because the message for label is empty, you will not see "my text" in the web page, and the <p> tag will not be created.
If you remove the ! then you will see "my text", inside the <p> tag.
You cannot use #{label} directly in this specific case. You have to wrap it in the #messages.msg() method.
Also, if the label message does not exist in the message file, then this will behave the same way as label=.

substrings find and replace in large string using java

I have list of articles in html.In every article i have multiple image tags like added below
<img alt="quick-start" class="alignnone size-full wp-image-16745" height="224" sizes="(max-width: 474px) 100vw, 474px" src="http://localhost/myfolder/my-content/uploads/2016/11/Quick-start.jpg" srcset="http://localhost/myfolder/my-content/uploads/2016/11/Quick-start.jpg 474w, http://localhost/myfolder/my-content/uploads/2016/11/Quick-start-300x142.jpg 300w" style="box-sizing: border-box; margin-top: 10px; margin-bottom: 10px;" width="474" />
Problem Statement:
I want to replace urls of image present in src, srcset i-e http://localhost/myfolder/my-content/uploads/2016/11/Quick-start.jpg to some other url.
whats the best approach to do that. I am thinking about functional programming in java
Yes this can be done using java.But it will be easy if you manipulate using java script framework like jquery.
$(".image2").attr("src","image1.jpg");

Magnolia rich text fields

I'm looking at outputting Rich Text in Magnolia directly to the front-end. I'm defining the field as below:
#TabFactory("Content")
public void contentTab(UiConfig cfg, TabBuilder tab) {
tab.fields(
cfg.fields.text("title").label("Title"),
cfg.fields.richText("subtitle").label("Subtitle")
);
}
Within a template, when information is saved into the JCR it appears to encode the data with HTML entities:
Title: ${content.title}
Subtitle: ${content.subtitle}
Outputs (raw source) ...
Title: The Title Field
Subtitle: <p>The Subtitle Field</p>
But should output (raw source) ...
Title: The Title Field
Subtitle: <p>The Subtitle Field</p>
Is there a way to stop the Rich Text fields from being encoded automatically?
The decode function works:
https://documentation.magnolia-cms.com/display/DOCS/cmsfn#cmsfn-DecodeHTML
[#if content.text?has_content]
${cmsfn.decode(content).text}
[/#if]
Most framework try to get rid of the XSS-kind of attacks so it is a good way to use the template as the following:
Title: ${content.title}
Subtitle: <p>${content.subtitle}</p>
It will prevent the users (or admins) to run magic JS or some other bad codes on the client.
Back to the question: check out the documentation here https://documentation.magnolia-cms.com/display/DOCS/Component+definition. There is something called escapeHtml take a look at it. :)
Edit: as bashaus pointed out he was using page properties not components. The solution in this way the following:
[#if content.text?has_content]
${cmsfn.decode(content).text}
[/#if]
TL.DR: Try to avoid html characters in dynamic content, but the feature is able to be turned off.

Vaadin FormLayout formatting

Im new at vaadin 7 and have a little issue with formatting.
I have spend a few hours but no luck.
I have:
2 Form layouts on my vertical Layout.
2 Labels on each form layout.
Better check the screenshot
I want format label test as on the right part of screenshot.
Can you please advice or share thoughts or ideas.
I'm not 100% certain if I get what you're trying to do, but you might be able to achieve this through custom CSS.
It is hard to write out the exact CSS since it would require seeing the HTML generated by Vaadin and testing it with that, but it would be something like this for the labels:
.padded-form-layout v-caption:first-child {
float: left;
padding-left: 30px; /* set desired padding used for each label */
}
Of course, you'll need something similar for the values as well.
Above, padded-form-layout is the class name you define for layouts that need this look. In Java:
formLayout.setStyleName("padded-form-layout");
To figure out what the CSS modifications needed are I recommend you open the page in browser (Chrome or Firefox will do) and use the dev tools to directly modify the CSS to figure out what rules are needed. I usually do this by simply typing a style tag to the element, something like this (in this example, style="XXXXX" would be added manually. This is possible at least with Chrome's developer tools):
<div class="v-formlayout v-layout v-widget v-has-width" style="width: 100%;">
<!-- ... -->
<td class="v-formlayout-captioncell">
<div class="v-caption v-caption-hasdescription">
<span id="gwt-uid-21" for="gwt-uid-22" style="XXXXX">First name:</span>
<span class="v-required-field-indicator" aria-hidden="true">*</span>
</div>
</td>
<!-- ... -->
</div>
To be able to use the CSS, you'll need to either add it to your theme somehow and compile it (see Vaadin documentation about themes), or by using the #StyleSheet annotation

Editing text file dojo

I am learning dojo and a begginer. I would like to load and edit a text file from interface using Dojo. Please direct me which component in dojo would suffice this.
From the answer to my comment, my understanding is that you want to:
Enter a file name into a form on your webpage.
Dojo will then load that particular text file from your sever.
The file then needs to be displayed on the screen in some sort of editing componant.
The user then needs the facility to post the file back to the server.
I would have thought that the best approach is to use dojo/request to get the text file and then use it again to post it back. You could the various dojo dijits to do the selecting and displaying.
A very crude solution would be:
<form data-dojo-type="dijit/form/Form">
<input type="text" id="fileName" data-dojo-type="dijit/form/TextBox" />
<button data-dojo-type="dijit/form/Button" type="button">Get
<script type="dojo/on" data-dojo-event="click">
require([
"dijit/registry",
"dojo/request"
], function(registry, request) {
var fileName = registry.byId("fileName").get("value");
request(fileName, {
"handleAs": "text"
}).then(function(content){
registry.byId("content").set("value", content);
});
});
</script>
</button><br /><br />
<textarea id="content" data-dojo-type="dijit/form/TextBox"></textarea>
<button data-dojo-type="dijit/form/Button" type="button">Send
<script type="dojo/on" data-dojo-event="click">
require([
"dijit/registry",
"dojo/request"
], function(registry, request) {
var content = registry.byId("content").get("value");
request("myhandler.php", {
"method": "post",
"data": {
"content": content
}
}).then(function(content){
// deal with the response
});
});
</script>
</button>
</form>
This will load a text file with the filename you enter in the text box (after clicking get). The content is loaded into the textarea for editing and can be sent back to a server script by clicking send.
This is as I said, "a very crude example". However, it shows the use of dojo/request to receive and post information to/from the server. Obviously, you'd want a more sophisticated solution that hides/shows widgets at the appropriate moment. You would probably want to replace the filename textbox with a some sort of combo populated via your server code...etc, etc.
I'd suggest you write your own widget to encapsulate the whole operation, rather than declare it all in markup. You could use dojo/request to load a json file from the server to populate a combo box to select the file. You'd also want to ensure the information being posted back is from a trusted source.
Important! This will only work if the textfile and you webpage are residing on the same domain. It will not work for cross-domain requests. If you want to do cross-domain you'll need to create a json solution.

Categories

Resources