i18 in Spring Boot (URL Issue) - spring-boot

I have a problem about fixing url in my Spring Boot App.
When I run the app, it automatically opens main page in that url address (http://localhost:8080/businessAdmin/)
When I try ot change the langauge , its shows the url like this (http://localhost:8080/businessAdmin/?lang=en)
Here is my code snippet shown below.
<li class="nav-item">
<a class="nav-link"
th:with="urlBuilder=${T(org.springframework.web.servlet.support.ServletUriComponentsBuilder).fromCurrentRequest()}"
th:href="${urlBuilder.replaceQueryParam('lang', 'en').toUriString()}">
<img th:src="#{/images/english.png}" width="30">
</a>
</li>
<li class="nav-item">
<a class="nav-link"
th:with="urlBuilder=${T(org.springframework.web.servlet.support.ServletUriComponentsBuilder).fromCurrentRequest()}"
th:href="${urlBuilder.replaceQueryParam('lang', 'de').toUriString()}">
<img th:src="#{/images/deutsch.png}" width="30">
</a>
</li>
How can I fix it like this?

Related

Weird behaviour with controller name in ASP.NET Core 6.0 MVC

I'm not a developer by trade so please go easy. I expect I'm missing something obvious but this is what I'm experiencing.
A new ASP.NET Core 6.0 MVC project just started in VS 2022, in nav items one the menu one of the links isn't being generated correctly.
These are the nav items I'm generating:
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Technical" asp-action="Monitoring">Monitoring</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Admin" asp-action="Index">Admin</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Finance" asp-action="Telephony">Finance</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Financ" asp-action="Telephony">Finance</a>
</li>
In my controllers I have a Admin, Finance, Home and Technical controllers.
This is what is being generated:
<li b-fcse4o214h class="nav-item">
<a class="nav-link text-dark" href="/">Home</a>
</li>
<li b-fcse4o214h class="nav-item">
<a class="nav-link text-dark" href="/Technical/Monitoring">Monitoring</a>
</li>
<li b-fcse4o214h class="nav-item">
<a class="nav-link text-dark" href="/Admin">Admin</a>
</li>
<li b-fcse4o214h class="nav-item">
<a class="nav-link text-dark" href="/Telephony">Finance</a>
</li>
<li b-fcse4o214h class="nav-item">
<a class="nav-link text-dark" href="/Financ/Telephony">Finance</a>
</li>
The first 3 links work fine, the fifth one doesn't work as I have intentionally mis-spelled the controller name to test this, but the fourth link doesn't have the "Finance" included in the href
Could someone shed some light on what I might have got wrong please?
Sorted it. I used https://code-maze.com/file-upload-aspnetcore-mvc/ for reference for adding a file upload, the controller code on that page had [HttpPost("FileUpload")] removing the ("FileUpload") to leave [HttpPost] resolved it for me.
Given that it allowed me to put any junk in the controller name to test it, I was surprised that it behaved like this.
Anyway, thank you to Okan Karadag for making me look further in to the controller code.

Using Boostrap 4 in an Angular 11 project

I'm trying to use Boostrap 4 in an Angulat 11 project.
In my asests/styles.scss I've added
#import "~bootstrap/scss/bootstrap.scss";
and in my angular.json I've added
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"
]
Now I'm trying to make a dropdown in the nav bar
<ul *ngIf="isAuthenticated" class="navbar-nav nav nav-pills nav-fill">
<li class="nav-item dropdown" title="Manage system.">
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" href='target="_self"'>><i class="fas fa-tools"></i> System</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" routerLink="/system"><i class="fas fa-tools"></i> System summary</a></li>
<li><a class="dropdown-item" routerLink="/system/users"><i class="fas fa-user"></i> Users</a></li>
<li><a class="dropdown-item" routerLink="/system/groups"><i class="fas fa-users"></i> API Groups</a></li>
<li><a class="dropdown-item" routerLink="/system/roles"><i class="fas fa-tasks"></i> API Roles</a></li>
</ul>
However, when I click the nav item the dropdown does not appear and indstead the browser navigates to /. Is it possible to get Boostrap to work with Angular?
I know it's possible to use Boostrap and Angular at the same time. But personnaly, I prefer to use ng-bootstrap which is designed for Angular system.
Ng-bootstrap isn't using the last version of bootstrap but a lot of content is available and it's easier to install.

Sidebar menu hide from users using laravel

I am a beginner at laravel and I have Hidden sidebar menu from users it's successfully working but when logout from admin then I face error how to fix it thanks. please see error https://flareapp.io/share/NPL9bz7w
Html view
<!-- Sidebar Menu -->
<nav class="mt-2">
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview"
role="menu" data-accordion="false">
<!-- Add icons to the links using the .nav-icon class
with font-awesome or any other icon font library -->
<!--Admin sidebar menu -->
#if(Auth::user()->type == "admin")
<li class="nav-item">
<a href="{{url('admin')}}" class="nav-link">
<i class="fas fa-comments"></i>
<p>Users Permission</p>
</a>
</li>
<li class="nav-item">
<a href="{{url('manage_users')}}" class="nav-link">
<i class="fas fa-comments"></i>
<p>Manage Users</p>
</a>
</li>
<li class="nav-item">
<a href="{{url('register')}}" class="nav-link">
<i class="fas fa-comments"></i>
<p> User Register</p>
</a>
</li>
<!-- end Admin sidebar menu -->
<!-- User sidebar menu -->
#else
<li class="nav-item">
<a href="{{url('viewprofile')}}" class="nav-link">
<i class="fas fa-user"> </i>
<p>View Profile</p>
</a>
</li>
<li class="nav-item">
<a href="{{url('DashBoard')}}" class="nav-link">
<i class="fas fa-comments"></i>
<p>Chat Room</p>
</a>
</li>
#endif
</ul>
</nav>
<!-- /.sidebar-menu -->
The problem is, you are checking #if(Auth::user()->type == "admin") for check the logged in admin. If the admin is logged out then there is no Auth::user(). I think this is the problem you are facing. So change the condition like this
#if(Auth::check() && Auth::user()->type == "admin")
// Admin menu bar
#elseif (Auth::check())
// User menu bar
#endif
I think this will solve the issue.
Since the user is logged out, the Auth::user() is null.
Because of which, when you try to get its type, it is throwing
Trying to get property 'type' of non-object
You need to check whether the user is logged in, and then check its type.
#if(Auth::check() && Auth::user()->type == "admin")
Auth::check() will return true if the user is logged in
first check if user logged in then check that if user is admin or not:
<!-- Sidebar Menu -->
<nav class="mt-2">
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview"
role="menu" data-accordion="false">
<!-- Add icons to the links using the .nav-icon class
with font-awesome or any other icon font library -->
<!--Admin sidebar menu -->
#auth
#if(Auth::user()->type == "admin")
<li class="nav-item">
<a href="{{url('admin')}}" class="nav-link">
<i class="fas fa-comments"></i>
<p>Users Permission</p>
</a>
</li>
<li class="nav-item">
<a href="{{url('manage_users')}}" class="nav-link">
<i class="fas fa-comments"></i>
<p>Manage Users</p>
</a>
</li>
<li class="nav-item">
<a href="{{url('register')}}" class="nav-link">
<i class="fas fa-comments"></i>
<p> User Register</p>
</a>
</li>
<!-- end Admin sidebar menu -->
<!-- User sidebar menu -->
#else
<li class="nav-item">
<a href="{{url('viewprofile')}}" class="nav-link">
<i class="fas fa-user"> </i>
<p>View Profile</p>
</a>
</li>
<li class="nav-item">
<a href="{{url('DashBoard')}}" class="nav-link">
<i class="fas fa-comments"></i>
<p>Chat Room</p>
</a>
</li>
#endif
#endauth
</ul>
use isset method
#if(isset(Auth::user()->type) && Auth::user()->type== "admin")
you can also use Auth::check()
#if(Auth::check() && Auth::user()->type== "admin")

I need to hide an specific element of a navbar depending on a rol

I have a navbar and I have 2 elements outside the login option, the thing is that I need that a certain element stays with a certain role and when I'm not logged in...
Here is my code
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#services"><i class="fa fa-search"></i> Buscar</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#about">Explorar cursos</a>
</li>
#if (Route::has('login'))
#auth
#role('Alumno')
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#about">Explorar cursos</a>
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="{{route('miscursos')}}"> Mis cursos</a>
</li>
#endrole
#role('Administrador')
<li class="nav-item dropdown">
<a class="nav-link" href="{{ route('home') }}" >
{{ __('Tablero')}}
</a>
</li>
#endrole
The second element on the list is the one I'm having problem with because I want it when I'm browsing in the page but NOT logged in and I need when I'm logged in with an 'Alumno' role
The thing is that I don't wanna see it when I'm logged in as an administrator
You can use :
Auth::guest() for conditional when user it not logged in. So if I am getting it right, in your second list element :
<?php
#if(Auth::guest() || Auth::user()->role != 'Administrator)
// Only visible if user is NOT logged in OR logged in but not an administrator
#endif

A weird thing of Magento breadcrumbs?

<ul>
<li class="home">
<a title="Go to Home Page" href="#">Home</a>
<span>/ </span>
</li>
<li class="category3">New Arrival<span>/ </span>
</li>
<li class="cms_page"><strong></strong>
</li>
</ul>
Above is the html code of site breadcrumbs. Why do my template breadcrumbs add this code <li class="cms_page"><strong></strong></li>? All the code in the breadcrumbs.phtml of the base template are the same when i change the theme to default. There is no
<li class="cms_page"><strong></strong>
</li>
What's wrong with my template? thank you
are you sure you are editing the right template? To verify that turn on template hints from system > configuration > developer

Resources