Issue with Thymeleaf th:href, the link seems not to be created and thus not clickable - spring

I have a simple html page, "index.html". I'm testing server.servlet.context-path=/test and i'm testing on the webpage the redirection on itself, nothing more. For some reason that I can't understand, even with the docs about thymeleaf https://www.thymeleaf.org/doc/articles/standardurlsyntax.html
<a th:href="#{/index.html}">Reload page</a>
It's just displaying "Reload page" and I can't even click on it. My goal is to be able to click on it and to be redirected to /test/index.html, as I thought this would be the accurate method.
Feel free to give me any advice on how to do so, or why isn't it working the way it's supposed to be.
Thanks you very much for your time !
EDIT : Here are the dependencies thymeleaf-related I'm using :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head>
<title>Test page</title>
</head>
<body>
<a th:href=#{/index.html}>Reload page</a>
</body>
</html>
This is the exact page I'm using. If I remove the xmlns in the html tag, the th:ref is marked as "Undefined attribute name (th:href)." Which made me think that when I have the xmlns (as it is right now) the attribute is correctly defined.

Related

Not able to load .obj and .mtl

Not able to render the .obj and .mtl file on web using A-Frame
I've gone through the Docs and tried what's mentioned. When I inspected, the HTML was loading but it didn't render on screen.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello, WebVR! • A-Frame</title>
<meta name="description" content="Hello, WebVR! • A-Frame">
<script src="https://aframe.io/releases/0.9.0/aframe.min.js"></script>
</head>
<body>
<a-scene background="color: #ECECEC">
<a-assets>
<!-- <a-asset-item id="tree-obj" src="assets/BisonPlains.obj"></a-asset-item> -->
<!-- <a-asset-item id="tree-mtl" src="assets/BisonPlains.mtl"></a-asset-item> -->
</a-assets>
<a-obj-model src="assets/BisonPlains.obj" mtl="assets/BisonPlain.mtl"></a-obj-model>
</a-scene>
</body>
</html>
Two issues after first look:
URLs are incorrect. Go to the glitch assets panel to get the proper URLs. Corrected glitch:
https://glitch.com/edit/#!/sunny-ceramic?path=index.html:15:101
The texture images is missing BisonPlains_BaseColor.png
First thing I recommend is checking at the browser network panel and look for 404 errors. Make sure that all files load as expected before investigating further.

how to map Spring controllers to their thymeleaf views(intellij14)

I am trying to configure spring boot thymeleaf and intellij, and for the most part have nailed it, but I cant seem to be able to link controllers with their views, as intellij annoyingly keeps displaying the following message, and the auto-completing the system is not working:
Cannot Resolve 'varName'
my controller looks like this "main/java/..../controller.java"
#Controller
public class CardsController {
#RequestMapping(value="/card/{id}",method = RequestMethod.GET)
public String viewCardAction(#PathVariable("id") Card card,Model model){
model.addAttribute("card",card);
return "cards/view";
}
}
And this is my mockup view "main/resources/cards/view/cards/view":
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
<meta charset="UTF-8"/>
<title th:text="${card.name}"></title> <!-- this line shows the message -->
</head>
<body>
<div th:text="${card.name}"></div> <!-- this line shows the message -->
</body>
</html>
is it that intelij, is still not working for this, or am I missing some configuration
NOTE: it works and compiles, just wanna enable autocomplete
Looks like this is a bug in Intellij.
Here's the youtrack link:
https://youtrack.jetbrains.com/issue/IDEA-132738
It hasn't gotten much attention from the JetBrains developers yet so you may want to add your comments or vote it up there.
Since it is still unresolved and people might come here by search, here is the workaround mentioned by zhao xinjing in the link posted in the accepted answer:
<!--/*--><!--#thymesVar id="loginFormBean" type="sample.system.login.LoginFormBean"--><!--*/-->
<form id="formMain" class="form-horizontal" action="#" data-th-action="#{/login}" data-th-object="${loginFormBean}" method="post"> as thymeleaf comment, nothing be left in html output
You can also use it to specify collections, e.g.
<!--/*--><!--#thymesVar id="names" type="List<String>"--><!--*/-->
<!--/*--><!--#thymesVar id="name" type="String"--><!--*/-->
<li th:each="name: ${names}" ... />

Empty page in Webmatrix

I wrote (copied) a first program in WebMatrix. I selected EmptySite template and in Page.cshtml I typed 2 lines. Finaly, the code in Page.cshtml looks like this:
#{
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<h1>Welcome to the WebMatrix!</h1>
<p>I began to become a web developer on #DateTime.Now.ToString()</p>
</body>
</html>
I pressed "Run" but I got an empty web-page. Nothing is written on it. I received no error message.
Well, what's wrong ?
Thanx,
Eb_Cj
You seem to be going to the default document rather than your page. You can solve this in two ways: either right click on the Page.cshtml node in the project explorer within WebMatrix and select Launch in browser or manually change the URL in your browser to localhost:25776/Page.

How can I have a dynamic image show when someone clicks the Facebook Like button and Posts to Facebook?

Currently, when someone 'likes' a link and creates a Facebook post (via the like button), it will only grab the one image that I specify in the meta tag (via the og:image property).
What is the best way to allow people to post a dynamic image with dynamic description? In my case, I have several items (with image & description) listed on a page that the user should be able to 'like' and post on their wall. Any advice would be much appreciated.
Thanks!
Change the meta tag on click: use this example and modify it to your needs.
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<title>Title Of Page</title>
</head>
<body>
<input type="button" value="Click Me" onclick='$("title").html("Changed Dynamically");'/>
</body>
</html>

My HTML tags gets tampered with

I have an Umbraco 5 MVC3 project where i discovered that there where white spaces here and there. When investigating i discovered that my HTML looked really bad when "viewing generated source" in firefox web developer tool. For example it removes my doctype declaration and moves my meta-tags and stuff out of the head. Simplified code:
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>#ViewBag.Title</title>
<link rel="stylesheet" href="#Url.Content("~/Content/Styles/style.css")"/>
</head>
<body id="" class="default">
<div id="wrapper">
<header id="banner" class="body">
<a class="ir logo" href="/"><h1>Christian </h1></a>
<ul class="share">
<li id="facebook"><a class="ir" href="http://www.facebook.com/sharer.php?u=#Request.Url.AbsoluteUri">Facebook</a></li>
<li id="twitter"><a class="ir" href="http://twitter.com/share?text=Christian">Twitter</a></li>
</ul>
#Html.Partial("nav")
</header>
<section id="content" class="body">
#RenderBody()
</section>
</div>
<script src="#Url.Content("~/Scripts/plugins.js")"></script>
<script src="#Url.Content("~/Scripts/script.js")"></script>
</body>
</html>
And the output begins like this
<html class="no-js" lang="en"><head></head><body id="" class="default">
If you want to check on the HTML generated by your server, you should use View source (CTRL + U).
Generated source is more like a reconstruction of the HTML based on the DOM and includes for example nodes created on the client side with javascript, once the page is loaded.
Alright, i solved it. Took me a while. After Marapet suggested not to use "generated source" i tried normal "view source" in a bunch of browsers and got different results in all of them. When i tried to validate my source i got some weird complaints:
Non-space characters found without seeing a doctype first. Expected <!DOCTYPE html>.
Element head is missing a required instance of child element title.
And my personal favourite
Cannot recover after last error. Any further errors will be ignored.
Looked like there was something up with the doctype. Opened up notepad and pasted in there to "wash" the code from metadata, the way i do sometimes when pasting stuff in to tinyMCE. The text got formatted weird even in notepad. The doctype declaration had a smaller font size then the rest of the html.
So i opened it in notepad++ too and there i got a bunch of questionmarks in front of the declaration. I removed them and copied it back in to Visual Studio, saved and now everything works.
I think the reason i got this problem was that i copied snippets directly from the HTML5 Boilerplate on github.
// Sherlock

Resources