Springsource Tools Suite thymeleaf tags are unknown - sts-springsourcetoolsuite

I am usind Springsource Tools Suite and I want to develop a maven based web project. The parent archetype creator has used thymeleaf tags (th:block). It is working but I get warnings in STS that say: Unkown tag (th:block). How can i fix this warning?

Since I cannot add comment, I will write it here:
Check three things:
Does maven contain thymeleaf dependencies?
something like this.
Do you have Thymeleaf resolver properly set:
This is annotation example:
#Bean
public ThymeleafViewResolver viewResolver() {
ThymeleafViewResolver thymeleafViewResolver = new ThymeleafViewResolver();
thymeleafViewResolver.setTemplateEngine(templateEngine());
thymeleafViewResolver.setCharacterEncoding("UTF-8");
return thymeleafViewResolver;
}
Does your view have proper html tag:
html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"

In case of HTML, DTD wan't be parsed.
Try using Eclipse plugin (remember to add Thymeleaf nature to project): https://github.com/thymeleaf/thymeleaf-extras-eclipse-plugin

Related

How can I translate strings in Blazor components and App.razor?

I want to localize strings of shared components like "NavMenu.razor" or the "App.razor" page.
I managed to translate content in my pages as described in the general .NET Core instruction and the more specific Blazor documentation:
Create a resource file with the right name (e.g. PageName.de.resx).
Inject localizer into Razor page with #inject Microsoft.Extensions.Localization.IStringLocalizer<PageName> _l10n.
Translate text inside the page with _l10n["Product name"] which gets translated correctly to "Produktname".
This approach did not work for neither "NavMenu.razor" nor "App.razor".
Please note: I use MatNavMenu from the MatBlazor UI lib for main navigation.
I cannot find it documented anywhere. Help is much appreciated.
Easy:
Install Microsoft.Extensions.Localization
in programs.cs
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
builder.Services.AddScoped<IStringLocalizer<App>,StringLocalizer<App>>();
Create a Resources folder in your client project. Add a resx file to
that for instance App.resx this will be your default resources. Then
add more files for each language you wish to support. App.fr.resx
App.es.resx ect.
Then in a component inject
#inject IStringLocalizer<App> L
#L["YourText"]
The localizer will use browsers language and look in, in my case, App.en-AU.resx, App.en.resx, App.resx order for the key. If not found it will use "YourText"
Here is a blazor WASM project repo

How can I override Request class?

I tried overriding the core classes but this one doesnt seem to work. I know I will need to update the application/config/app.php file to point to the new class. But when I do this the HTML redender stops at head tag.
I extended the Request Class from core to application/src, updated the app.php file, but it doest work and gives me a blank page. I will need this to use redirect url.
if your goal is to do something to the request before sending it back you might want to use a middleware instead of overriding the class.
A good example is the Centry portal package which you can find here: https://github.com/a3020/centry
Have a look at centry\Provider\CentryServiceProvider.php function registerMiddleware() to see how to register a middleware.
And then look at the 2 files in centry\Http\Middleware to see how it's used.
If you are using version 8 you will need to autoload your classes in the src folder.
In application/bootstrap/autoload.php
$classLoader = new \Symfony\Component\ClassLoader\Psr4ClassLoader();
$classLoader->addPrefix('Application\\Example', DIR_APPLICATION . '/' . DIRNAME_CLASSES . '/Example');
From here you will need to override the associated service provider. It's not entirely clear which class you are trying to override and which service provider this would require. Below is an example for overriding the \Concrete\Core\Http\HttpServiceProvider with class placed in application/Src/Example/HttpServiceProvider
return [
'providers' => [
'core_http' => 'Application\Example\HttpServiceProvider'
]
]
From the service provider you can extend classes and override the returned classes in a way the suits your use case scenario (It can be tedious if multiple classes have references but it's the only way I'm aware of to properly override core classes). Typically you can just extend existing classes overriding a single method or two and come up with an elegant solution.

#ResourceDependency with correct configuration does not find the resource

I have a javascript file under the following folder in my JAR component:
/src/main/resources/META-INF/resources/default/javascript/jquery.marquee.js
If I create a custom JSF component with the following #ResourceDependency annotation:
#ResourceDependency(library = "default", name = "javascript/jquery.marquee.js", target = "head")
The javascript file cannot be found, and in the browser I can see two weird URLs with undefined.css and undefined.js as part of the URL, and also referring the PrimeFaces library ??
http://localhost:8080/acio/javax.faces.resource/undefined/undefined.css.xhtml?ln=primefaces&v=5.3
http://localhost:8080/acio/javax.faces.resource/undefined/undefined.js.xhtml?ln=primefaces&v=5.3
However, if I manually include the script in a XHTML template as follows:
<h:outputScript library="default" name="javascript/jquery.marquee.js" />
Then everything works like a charm as expected, with the expected URL as follows:
http://localhost:8080/acio/javax.faces.resource/javascript/jquery.marquee.js.xhtml?ln=default
I'm completely puzzled about this.
Why, if I use the #ResourceDependency annotation, I get TWO wrong URL's, one about a CSS and another about the JS, related to the PrimeFaces resources, when I'm positively sure the placement of my own JS file is correct? (otherwise the h:outputScript would not work as well)
Tested with Mojarra 2.2.13.SP1 shipped with WildFly 10.1.0.Final, and Mojarra 2.2.12 shipped with WildFly 9.0.2.Final
Any help would be greatly appreaciated !
[UPDATE]
It looks like the the issue may be related to the way we handle page navigation. We are using a SPA approach, with a Facelet template that has a big panel group area inside, with a dynamic JSF include directive. Pages are XHTML fragments that are dynamically included in the template's panel group after an AJAX execution.
It appears that #ResourceDependency only renders the corresponding HTML resource link when a View is created the very first time. As we are using SPA, our View never changes, from the JSF point of view. We handle all the page navigation with AJAX fragment updates using the include directive.
As a test, I placed the tag of my component in the Facelet template itself, instead of a XHTML fragment... and the link is rendered as expected !
It would be great if someone can confirm this behaviour... and if there's any elegant solution to it.
So far, we have to manually include the needed HTML resources on the template definition.
It turns out that the problem goes away when upgrading to PrimeFaces 6.1. Probably Kukeltje is right, and the PF 5.3 Resource Renderer has some kind of bug.
In short, when developing your own JSF PrimeFaces components, PF 5.3 will not render the #ResourceDependency annotations of the JSF component in some situations, like the one described here: using an SPA approach with XHTML fragments.
Moving to PF 6.1 solves the problem. If upgrading is not possible, we have to manually include the needed JS / CSS resources in the fragment with outputScript tags.

Arabic Language Support for Spring MVC

I am researching on providing Arabic language support to my website.
I found that http://www.mkyong.com/spring-mvc/spring-mvc-internationalization-example/ in Spring MVC how can we can load the appropriate message bundles.
But for Arabic language we need a full mirror image of the screen.
I found some great info from http://www.nomensa.com/blog/2010/7-tips-and-techniques-for-multi-lingual-website-accessibility.
I am planning to use class for configuring styling.
My doubt is what is the best practice to achieve the following in page:
<set var = "currentLocale" value=${pageContext.response.locale}>
if(currentLocale== 'ar'){
<html lang="ar" dir="rtl">
}else if(currentLocale== 'en'){
<html lang="en">
}
if(currentLocale== 'ar'){
<body class="styleForArabic">
}else if(currentLocale== 'en'){
<body >
}
Can we get current locale in jsp OR do we need to set any variable from java and pass as modal.
Is there any dependency with Spring Security? I have implemented Spring Security in my app.
Is there any out of box support in Spring for handling these requirements.

Thymeleaf + Polymer

I'm trying to implement material design based on Polymer with Java Thymeleaf template engine. I started learning by this tutorial and got this exception:
Caused by: org.xml.sax.SAXParseException; Attribute name "unresolved" associated with an element type "body" must be followed by the ' = ' character.
As far as I can understand Thymeleaf, by default can't deal with web components/custom components. Is it possible to use Polymer in context of Thymeleaf template engine?
If you have something like:
<body unresolved touch-action="auto">
it will not work with Thymeleaf because Thymeleaf expects the markup to be valid XHTML and unresolved on its own is invalid XHTML markup. The following however should work:
<body unresolved="" touch-action="auto">
<body unresolved="unresolved" touch-action="auto">
The upcoming Thymeleaf 3.0 release will be able to deal with non-XHTML markup at lot better than Thymeleaf 2.1.
Have a look at
http://forum.thymeleaf.org/Thymeleaf-3-0-status-td4029243.html

Resources