Add a HTML comment using Eclipse RAP - comments

How do I add a HTML comment using Eclipse RAP 3.9 E4?
The following adds the comment text to the HTML albeit in a <div>. I would like the comment text in a <!-- -->.
public class MainEntry extends AbstractEntryPoint
{
protected void createContents(Composite parent)
{
Label comment;
comment = new Label(parent, SWT.NONE);
comment.setText("This is my comment");
comment.setVisible(false);
}
}

Related

<fieldset> and <legend> tags with pdfHtml in itext7

Using HTML file, I generated PDF file using iText pdfHTML. I want to present caption for the content, just like in HTML <fieldset> and <legend> are doing.
I used below HTML code. In HTML page it displayed as expected. But when generated the PDF file using pdfHTML, "Summary" is appear inside the box. Not in the border of box to display caption of the content.
<!DOCTYPE html>
<html>
<body>
<fieldset>
<legend>Summary</legend>
<p>Some paragraph</p>
</fieldset>
</body>
</html>
How can I solve this?
pdfHTML does not support fieldset tag yet and indeed your sample is converted into something like following:
You can plugin in your custom implementation into pdfHTML though to tweak the visual appearance to some degree (depending on your needs). Here is a basic example on how to tweak the visual appearance with a big number of assumptions:
private static class LegendTagWorker extends DivTagWorker {
public LegendTagWorker(IElementNode element, ProcessorContext context) {
super(element, context);
}
#Override
public IPropertyContainer getElementResult() {
IPropertyContainer result = super.getElementResult();
// Shift the position of the legend a bit above
result.setProperty(Property.POSITION, LayoutPosition.RELATIVE);
result.setProperty(Property.TOP, -14);
// Set the background of the text to white so that it does not overlap with the border of outer element
if (result instanceof Div && ((Div) result).getChildren().get(0) instanceof Paragraph) {
Paragraph p = (Paragraph) ((Div) result).getChildren().get(0);
((Text)p.getChildren().get(0)).setBackgroundColor(ColorConstants.WHITE);
}
return result;
}
}
private static class CustomTagWorkerFactory extends DefaultTagWorkerFactory {
#Override
public ITagWorker getCustomTagWorker(IElementNode tag, ProcessorContext context) {
if (tag.name().equals("legend")) {
return new LegendTagWorker(tag, context);
}
return super.getCustomTagWorker(tag, context);
}
}
Then you just need to pass your tag worker factory to converter properties:
ConverterProperties properties = new ConverterProperties();
properties.setTagWorkerFactory(new CustomTagWorkerFactory());
HtmlConverter.convertToPdf(inFile, outFile, properties);
Now we get the following result:
Please note that this is a very basic example and you will need to tweak it to your needs. Before this feature is implemented in pdfHTML you will have to use a workaround - either in code as I suggested, or you can do some tweaks with CSS, similar to the tweaks I am making in Java code

Apex:outputfield not outputting anything on VisualForce Page

I am trying to create a pdf from the Lead Object in Salesforce using the Apex language. I am able to create the pdf and attach it to the Current Lead but it does not pull in any of the information from the Lead into the PDF itself.
Page Code:
<apex:page standardController="Lead" renderAs="pdf" showHeader="false">
<apex:stylesheet value="{!$Resource.pdfCss}"/>
<apex:panelGrid columns="1" width="100%">
<apex:outputText value="{!Lead.Name}" styleClass="companyName"/>
<apex:outputText value="{!NOW()}"></apex:outputText>
</apex:panelGrid>
</apex:page>
Class Code:
public class attachPDFToLead {
private final Lead a; //Lead object
//constructor
public attachPDFToLead(ApexPages.StandardController standardPageController) {
a = (Lead)standardPageController.getRecord();
}
public PageReference attachPDF() {
PageReference pdfPage = Page.PDF;
Blob pdfBlob = pdfPage.getContent();
Attachment attach = new Attachment(parentId = a.Id, Name = 'insuranceVerification.pdf', body = pdfBlob);
insert attach;
PageReference pageURL = new ApexPages.StandardController(a).view();
pageURL.setRedirect(true);
return pageURL;
}
}
Button Setup:
Button Setup

Sitecore Rich Text Validation

What's the best way of validating if a RTE Field has any content?
I've tried to add the expression "^(?!\s*$).+" to the validation but it doesn't work. This happens because RTE adds some html tags (that authors cannot see unless they switch for the HTML view) and the value of the field is actually not empty.
Rich Text fields could have a variety of empty tags for example by default Sitecore will replace line breaks with empty p tags. See HtmlEditor.LineBreak setting in Web.config:
<!-- HTML EDITOR LINE BREAK
Specifies the tag that the HTML editor inserts on Enter. Values can be
"br", "div" and "p".
-->
<setting name="HtmlEditor.LineBreak" value="p" />
Or only entering a whitespace will save the field value as <p> </p>
There are two approaches that could be considered.
The first is whether to worry about the different scenarios that the content editor could enter content into the rich text editor. The content editor may not be detailed about worrying about the markup and may decide to remove it leaving line breaks or whitespaces. You could handle the value from the fields by using HtmlAgilityPack to check if any nodes has inner text:
public bool HasContent(string val)
{
var htmlVal = new HtmlDocument();
htmlVal.LoadHtml(val);
if (htmlVal.DocumentNode == null || !htmlVal.DocumentNode.ChildNodes.Any())
return false;
return htmlVal.DocumentNode.ChildNodes.Any(x => !string.IsNullOrWhiteSpace(x.InnerText));
}
If nothing comes back, you would not render the value to the page eliminating possible empty p tags.
The second approach would be to create a custom validation rule. To complete this, you will need to create a field rule, the custom validator class and associating the validation rule on any rich text fields. Below are the steps:
Open Content Editor and navigate to sitecore/System/Settings/ValidationRules/Field Rules/Text and add "Validation Rule" named "No Content For Rich Text"
Fill out Title, Description and Type
Create RichTextValidator class under Web project under Validators folder
RichTextValidator.cs
using HtmlAgilityPack;
using Sitecore.Data.Validators;
using System;
using System.Linq;
using System.Runtime.Serialization;
namespace MyProject.Web.Validators
{
[Serializable]
public class RichTextValidator : StandardValidator
{
public RichTextValidator() { }
public RichTextValidator(SerializationInfo info, StreamingContext context) : base(info, context)
{ }
private bool HasContent(string val)
{
var htmlVal = new HtmlDocument();
htmlVal.LoadHtml(val);
if (htmlVal.DocumentNode == null || !htmlVal.DocumentNode.ChildNodes.Any())
return false;
return htmlVal.DocumentNode.ChildNodes.Any(x => !string.IsNullOrWhiteSpace(x.InnerText) && x.InnerText != " ");
}
protected override ValidatorResult Evaluate()
{
string contextText = this.ControlValidationValue;
if (!HasContent(contextText))
return ValidatorResult.CriticalError;
return ValidatorResult.Valid;
}
protected override ValidatorResult GetMaxValidatorResult()
{
return GetFailedResult(ValidatorResult.CriticalError);
}
public override string Name
{
get { return "Rich text contains no content."; }
}
}
}
On the data template field, add the validation rule
Finally, the rich text field should indicate a critical error when there is either just empty tags or <p> </p>

MVC6 TagHelpers with disposable

In the older MVC HTML Helpers, one could use IDisposable to wrap content - for example the BeginForm helper would automatically wrap *stuff* with a closing form tag
<% using (Html.BeginForm()) {%>
*stuff*
<% } %>
Is this wrapping of content supported with MVC6 TagHelpers?
For example I would like this
<widget-box title="My Title">Yay for content!</widget-box>
to be expanded into a bootstrap widget-box with wrapping divs:
<div class="widget-box">
<div class="widget-header">
<h4 class="widget-title">My Title</h4>
</div>
<div class="widget-body">
<div class="widget-main">
Yay for content!
</div>
</div>
</div>
Is this possible with TagHelpers?
Solution: I have baked #DanielJG's answer into a working demo on github which consumes WidgetBoxTagHelper.cs (will stay current with Beta/RC/RTM as am using the lib in my production app)
Tag helpers have to implement the interface ITagHelper (as pointed by #NTaylorMullen, the TagHelper class is just a convenience class you can use when implementing it) which forces you to use the methods Process and ProcessAsync, so you cannot rely on adding contents in a Dispose method.
However you have full control over the output content so you can replace/modify it as you need. For example, a quick approximation to your widget tag helper (Using the 1.0 version of the framework):
[HtmlTargetElement("widget-box")]
public class WidgetTagHelper : TagHelper
{
public string Title { get; set; }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var outerTag = new TagBuilder("div");
outerTag.Attributes.Add("class", output.TagName);
output.MergeAttributes(outerTag);
output.TagName = outerTag.TagName;
//Create the header
var header = new TagBuilder("div");
header.Attributes.Add("class", "widget-header");
header.InnerHtml.Append(this.Title);
output.PreContent.SetHtmlContent(header);
//Create the body and replace original tag helper content
var body = new TagBuilder("div");
body.Attributes.Add("class", "widget-body");
var originalContents = await output.GetChildContentAsync();
body.InnerHtml.Append(originalContents.GetContent());
output.Content.SetHtmlContent(body);
}
}
In your razor you will have:
<widget-box title="My Title">Yay for content!</widget-box>
Which will be rendered as:
<div class="widget-box">
<div class="widget-header">My Title</div>
<div class="widget-body">Yay for content!</div>
</div>
Don´t forget to register the tag helpers in your assembly by adding a #addTagHelper directive to the _ViewImports.cshtml file. For example this will register all helpers in my application:
#addTagHelper *, WebApplication2
OLD beta7 code
In beta7 you had to use the [TargetElement] attribute.
The TagBuilder class had a SetInnerText method you could use to set its context as text.
The code looked like:
[TargetElement("widget-box")]
public class WidgetTagHelper : TagHelper
{
private IHtmlEncoder encoder;
public WidgetTagHelper(IHtmlEncoder encoder)
{
this.encoder = encoder;
}
public string Title { get; set; }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var outerTag = new TagBuilder("div");
outerTag.Attributes.Add("class", output.TagName);
output.MergeAttributes(outerTag);
output.TagName = outerTag.TagName;
//Create the header
var header = new TagBuilder("div");
header.Attributes.Add("class", "widget-header");
header.SetInnerText(this.Title);
output.PreContent.SetContent(header);
//Create the body and replace original tag helper content
var body = new TagBuilder("div");
body.Attributes.Add("class", "widget-body");
var originalContents = await context.GetChildContentAsync();
using (var writer = new StringWriter())
{
body.TagRenderMode = TagRenderMode.StartTag;
body.WriteTo(writer, encoder);
originalContents.WriteTo(writer, encoder);
body.TagRenderMode = TagRenderMode.EndTag;
body.WriteTo(writer, encoder);
output.Content.SetContent(writer.ToString());
}
}
}
OLD beta5 code
There was an InnerHtml property in the tag helpers.
There was a ToHtmlString method in the tag helpers used to render them as html.
The code looked like:
[TargetElement("widget-box")]
public class WidgetTagHelper: TagHelper
{
public string Title { get; set; }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var outerTag = new TagBuilder("div");
outerTag.Attributes.Add("class", output.TagName);
output.MergeAttributes(outerTag);
output.TagName = outerTag.TagName;
//Create the header
var header = new TagBuilder("div");
header.Attributes.Add("class", "widget-header");
header.InnerHtml = this.Title;
output.PreContent.SetContent(header.ToHtmlString(TagRenderMode.Normal).ToString());
//Create the body and replace original tag helper content
var body = new TagBuilder("div");
body.Attributes.Add("class", "widget-body");
var originalContents = await context.GetChildContentAsync();
body.InnerHtml = originalContents.GetContent();
output.Content.SetContent(body.ToHtmlString(TagRenderMode.Normal).ToString());
}
}

MS AJAX Library 4.0 Sys.create.dataView

One again Microsoft poor documentation has left me confused. I am trying to use the new features of the .NET 4.0 framework. I am using the following code to populate the Title and Director but it keeps getting blank.
The service returns the result correctly like
[d: { title = "ss, director ="" } something like that but the li never gets populated.
<script language="javascript" type="text/javascript">
Sys.require([Sys.components.dataView, Sys.components.dataContext,Sys.scripts.WebServices], function () {
Sys.create.dataView("#moviesView",
{
dataProvider: "MovieService.svc",
fetchOperation: "GetMovies",
autoFetch: true
});
});
</script>
And here it the HTML code:
<ul id="moviesView">
<li>
{{Title}} - {{Director}}
</li>
</ul>
IS THIS THE LATEST URL TO Start.js file.
<script src="http://ajax.microsoft.com/ajax/beta/0911/Start.js"></script>
Here is the Ajax-Enabled WCF Service:
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MovieService
{
[OperationContract]
public Movie GetMovies()
{
return new Movie() { Title = "SS", Director = "SSSSS" };
}
}
[DataContract]
public class Movie
{
[DataMember]
public string Title { get; set; }
[DataMember]
public string Director { get; set; }
}
You need to add the sys-template class attribute to the unordered list tag.
<ul id="moviesView" class="sys-template">
Here's an excerpt from Client-side Data Binding in ASP.NET AJAX 4.0
The one other requirement for defining
a template is the parent element must
have the sys-template CSS class
applied, and that class must be
defined with display set to none, as
shown in the example above. This
convention serves two purposes – it
helps the parser identify which
elements are part of a template on
your page (which will become important
when we use declarative
instantiation), and it keeps the
template markup hidden until ASP.NET
Ajax has completed the binding (it
will toggle the display to be
visible).

Resources