I'm trying to use JTidy to pretty print a well formed HTML generated by the user:
<div class="component-holder ng-binding ng-scope ui-draggable ui-draggable-handle" data-component="cronos-datasource" id="cronos-datasource-817277">
<datasource name="" entity="" key="" endpoint="" rows-per-page="">
<i class="cpn cpn-datasource"></i>
</datasource>
</div>
This is my config:
Tidy tidy = new Tidy();
tidy.setXHTML(true);
tidy.setIndentContent(true);
tidy.setPrintBodyOnly(true);
tidy.setTidyMark(false);
tidy.setWraplen(2000);
tidy.setDropProprietaryAttributes(false);
tidy.setDropEmptyParas(false);
tidy.setTrimEmptyElements(false);
But jTidy is removing my AngularJS datasource directive. Is there a way to workarround this issue?
I'm getting this from the log:
line 1 column 191 - Error: <datasource> is not recognized!
line 1 column 191 - Warning: discarding unexpected <datasource>
Removing tidy.setXHTML(true) or setting it to false and adding tidy.setXmlTags(true) actually solve this issue and it start to consider user defined tags, but this is not a good solution because JTidy starts trying to close self enclosing tags.
<!-- this code -->
<img src="anythig.jpg"/>
<div id="anyid"></div>
<!-- will become -->
<img src="anythig.jpg">
<div id="anyid"></div>
</img>
I need a formatter for a text editor. I can't assure what directives our users will define and use. It must be a generic solution which works for any user defined directive
Try setting the following property after your current configuration:
Properties props = new Properties();
props.setProperty("new-blocklevel-tags", "datasource");
tidy.getConfiguration().addProps(props);
See http://tidy.sourceforge.net/docs/quickref.html#new-blocklevel-tags.
I have solved this problem by make some changes in JTidy source
https://github.com/nanndoj/jtidy
I have added a new configuration called dropProprietaryTags
tidy.setDropProprietaryTags(false);
Now it's working fine for me. It's set to true by default so JTidy can work in the old way if the new property is not set to false
Related
I use Thymeleaf as a templating engine and I usually output variable value like this:
in Java I set:
ctx.setVariable("tester", "hello");
and in html template I output:
<span th:text="${tester}"></span>
This works great, but I would like to output a variable without the need of a tag. Something following would be great:
${tester}
Unfortunately it does not work. My goal is to avoid unnecessary tag to output the variable value. Is this possible to do with Thymeleaf?
My goal is to avoid unnecessary tag to output the variable value. Is this possible to do with Thymeleaf?
Yes this is possible. You can use the Thymeleaf synthetic th:block tag (see here).
Example template excerpt:
<body>
<th:block th:text="${tester}"></th:block>
</body>
This renders the following HTML:
<body>
hello
</body>
Only the variable is displayed.
Use Thymeleaf expression inlining (docs) using either [[...]] or [(...)]. With expression inlining, you do not need to use synthetic tags.
Example:
<body>
The value of tester is [[${tester}]].
</body>
Thymeleaf triggers on the "th:" tag and as far as I know thats the only way.
The behaviour you describe works with JSF.
Best regards
Ben
I also managed to figure out some workaround:
<span th:text="${tester}" th:remove="tag"></span>
th:remove removes span tag, but preserves content.
I am working on a Java (Struts) based web application. I have to show some content by getting from DB in jsp. Example content:
<div>
some code here
<a> link here</>
</div>
I am using textarea for the time but when I put this into textarea using following tag:
<html:textarea property = "contentFromDB" rows = "12" cols = "70" styleClass = "textarea" disabled="true"/>
It shows the HTML in the textarea, is there any way I may show the content in the textarea with out HTML tags or I may show the content in any other tag like P or span, I cannot find these tags in the struts tagLib as well.
The <html:xxx> tags are for forms.
The best practice is to use JSTL's <c:out> with an appropriately-scoped object (e.g., a request attribute) and set escape to false:
<c:out value="xxx" escapeXml="false" />
Alternatively if you're on an antiquated container or just have nothing better to do, use the <bean:write> tag. I don't recall its escaping behavior(s), if any.
I am currently using Struts2 tags for my form, and to show its error messages. My question is that the default markup for showing error messages in Struts2 tags is the usage of <ul> tag. is there anyway I can change this? I want the error messages to be displayed as <span> not a list.
How would I achieve this?
Another option is to change the CSS for UL elements.
This approach works only if you specifically care about appearance, not the DOM itself.
You can override template files which are used for rendering errors. Copy actionerror.ftl and fielderror.ftl files from the simple theme from struts2-core jar to your application and modify them not to use ul/li tags.
The tags render according to their theme. The question then changes to: How do you change the theme? You can change it for the tag
(set theme attribute on the tag to simple), page, request, or generally.
http://struts.apache.org/2.2.1/docs/struts-2-themes.html
Personally I like writing html, that is I don't like any "help" from the struts2 default theme. So in my struts.xml I simply use:
<constant name="struts.ui.theme" value="simple" />
Web developers should know html.
Update:
Generally use YUI reset.css so I probably missed this...
If you extend ActionSupport on the action there is a getFieldErrors() method so you could use <s:property value='fieldError["field_name"]'/> that will return the associated error message string of course without any formatting.
It isn't much less readable than the <s:fielderror/> tag... after all we need to use property tags all the time anyways.
I had same issue I used following code to resolve my issue
<s:if test="fieldErrors.get('email').size() > 0">
<s:property value="fieldErrors.get('email').get(0)"/>
</s:if>
Where email is name of my field. This way we don't have to modify CSS.
Here is a tutorial to show the use of the Struts 2âēs ActionError and ActionMessage class.
http://www.mkyong.com/struts2/struts-2-actionerror-actionmessage-example/
ActionError â is used to send error feedback message to user â display via < s:actionerror/ >
<s:if test="hasActionErrors()">
<div class="errors">
<s:actionerror/>
</div>
</s:if>
ActionMessage â is used to send information feedback message to user,display via < s:actionmessage/ >
<s:if test="hasActionMessages()">
<div class="welcome">
<s:actionmessage/>
</div>
</s:if>
I want to set the "dir" property of my table from resource bundle based on the locale.
Here is snippet:
<fmt:setBundle basename="class.path.to.resource.bundle"/>
<table align=center class="" dir=<fmt:message key="registration.direction"/>>
When the page renders I get this:
<table align=center dir=???registration.direction???>
I have two resource bundles for english and arabic.
registration.direction = ltr -> English
registration.direction = rtl -> Arabic
Please tell what I am doing wrong? The dir should have "ltr" or "rtl" depending on the locale.
Thanks
BR
SC
two things
1) I would add a variable to store the message result in
<fmt:message key="registration.direction" var="direction" />
then
2) I would do the following with your code
<fmt:setBundle basename="class.path.to.resource.bundle"/>
<fmt:message key="registration.direction" var="direction" />
<table align=center class="" dir="${direction}">
Now as far as your resource bundles, typically You should have the following structure for your resource bundles
/foo/bar/MyResourceBundle.properties
/foo/bar/MyResourceBundle_en.properties
/foo/bar/MyResourceBundle_en_US.properties
/foo/bar/MyResourceBundle_<lang>[_COUNTRY[_VAR]].properties
If your bundle is not structured in this fashion that might be some of your problem.
Make sure that all keys that are expected to be available are defined in MyResourceBundle with reasonable defaults.
I'm amending this answer as I'm not sure if my comment got lost in a hide function.
With the fact that you are using Struts 2, I'm under the impression that you're using the i18n interceptor. The interceptor will store the current locale in the sesion variable named WW_TRANS_I18N_LOCALE. As such you should be able to get to it and set the locale for the JSTL tags by using the following:
<fmt:setLocale scope="session" value="${sessionScope.WW_TRANS_I18N_LOCALE}" />
Hope that works for you.
I have an app that may run at http://serverA/m/ or http://serverA/mobile/. I have a shared header with a search form that needs to go to http://serverA/installationName/search.
However, if I use <form action="/search"> it goes to the root of the server, not the tomcat application.
If I use <form action="search"> it goes to a path relative to the current page. (i.e http://serverA/m/someOtherPage/search
I've tried <c:url value="search"> and <c:url value="/search"> but neither of them seem to work.
In intelliJ, <c:url value="/search"> gives me "Cannot resolve controller URL /search" even though I have a controller defined with #RequestMapping("/search")
<form action="<c:url value="/search" />" />
Using <c:url> is the way. Ignore what the IDE tells you. They are not good at that. Just try to run it.
Bozho is right. I have used HTML BASE tag too:
<base href="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/" />
If you can put this tag in a few places (ideally in only one JSP) you can get your code cleaner.
You can (apart from other responders hints) also use Spring JSP tag (spring:url) which is modeled after the JSTL c:url tag (see Bozhos reply). The tld reference:
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/spring.tld.html#spring.tld.url
And the bottom of this mvc:resources block for an example use:
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-static-resources
you will not be able to imbed the c:url tag directly in the attribute, if your form tag is a jsp tag (perhaps, <sf:form>).
In that situation I do the following:
<c:url var="someName" value="some uri value"/>
<sf:form path="${someName}" ...>