I currently have a Jsp called menu-container that loads a base menu that should appear on each of my pages, but each page will add options to that menu, those options go in a specific place, so I would like to know how I can send the Content to the menu-container (which is a Jsp) from another, here is the menu-container:
<ul id="menu">
<!-- Modificar las authorities segun la aplicacion -->
<div class="navbar navbar-default menu">
<div class="navbar-header" >
<button type="button" class="navbar-toggle collapsed"
data-toggle="collapse" data-target="#menu-colapse" aria-
expanded="false"
aria-controls="navbar">
<span class="sr-only">Menú</span> <span class="icon-bar">
</span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
</button>
</div>
<!-- Menu colapse -->
<div id="menu-colapse" class="navbar-collapse collapse">
<!-- Menu usuario - para opciones de control del usuario-->
<ul class="nav navbar-nav navbar-right">
<li class="dropdown user-options">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-cog"></i>
<!--[if IE 7]>
Opciones <span class="caret"></span>
<![endif]-->
</a>
<!-- En este dropdown van las opciones que se necesiten en la aplicacion -->
<ul class="dropdown-menu">
<!-- Nombre del usuario, recuperado por spring -->
<li>
<a href="#" class="a-no-link">
<!--[if !IE 7]><!-->
<i class="fa fa-user fa-padding-6 fix-right-menu" aria-hidden="true"></i>
<!--<![endif]-->
<sec:authentication property="principal" />
</a>
</li>
<!-- Logout -->
<li>
<div class="form-inline" style="color: white !important; height: 23px;">
<!--[if !IE 7]><!-->
<i class="fa fa-sign-out fa-padding-6" aria-hidden="true" style="margin-left: 16px;"></i>
<!--<![endif]-->
<spring:message code="menuPpal.salir"/>
</div>
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown user-options">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<i class="fa fa-language"></i>
</a>
<ul class="dropdown-menu">
<li><a class="a-link" href="configuracionInicio?idioma=en&pagina=inicio" title="English">English</a></li>
<li><a class="a-link" href="configuracionInicio?idioma=es&pagina=inicio" title="Español">Español</a></li>
<li><a class="a-link" href="configuracionInicio?idioma=fr&pagina=inicio" title="Français">Français</a></li>
</ul>
</li>
</ul>
<!-- /Menu usuario -->
<ul class="nav navbar-nav navbar-right" aria-expanded="false" id="main-menu">
//This is the place for the Li Items
//One or more items to add
</ul>
Now the invoking Jsp has something like this:
<jsp:include page="comun/menu-container.jsp" />
But as I must send it from the jsp that invokes the items (from which it invokes because it is in that they are distinguished from each other of course), but I do not know how to do it, suppose I put them in a new Jsp, that I call it and then How do I pass it to the container? And how do you receive it?
Thanks for taking the time any help is welcome, regards!
Pdta: what I want to avoid is having to have muuuchas classes menu that only change in what they add because it makes me very bad practice.
You can pass extra menu item as parameters from invoking JSP.
menu-container.jsp
<ul id="main-menu">
${param.menuItems}
</ul>
invoking_jsp.jsp
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Invoking JSP</title>
</head>
<body>
<jsp:include page="menu-container.jsp">
<jsp:param name="menuItems" value="<li>Special menu item 1</li><li>Special menu item 2</li>"/>
</jsp:include>
</body>
</html>
Edit : if you want to keep the menu items in a separate jsp page, as you suggest in the comments, you can just pass the jsp page name as the parameter as below.
menu-container.jsp
<ul id="main-menu">
<jsp:include page="${param.menuItems}"/>
</ul>
invoking_jsp.jsp
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Invoking JSP</title>
</head>
<body>
<jsp:include page="menu-container.jsp">
<jsp:param name="menuItems" value="menuPrincipal.jsp"/>
</jsp:include>
</body>
</html>
Related
I am trying to get info from a input bar and use the value for a modal. Currently I am using Thymeleaf and I am getting everything mixed up. I tried setting the attribute for href using jQuery. Though I believe since the th:href gets rendered on page load, my code does not work.
The end goal is to send the info from the input field, process it in Thymeleaf, and then show the results in the modal. I can so far only accomplish it when I hard code everything. I am looking for a more dynamic way. Any help will be appreciated.
HTML:
<!DOCTYPE html>
<html xml="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="ISO-8859-1">
<title>Application</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/landing-page.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<ul class="nav nav-tabs ">
<li class="nav-item">
<a class="nav-link active" href="#">Home</a>
</li>
<li class="nav-item">
<!-- <a class="nav-link" href="create.html">Create</a> -->
<a class="nav-link" href="/addTyler">Create</a>
</li>
<li class="nav-item dropdown ml-md-auto">
<a class="nav-link dropdown-toggle" href="http://example.com" id="navbarDropdownMenuLink" data-toggle="dropdown">Account</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Settings</a>
<div class="dropdown-divider">
</div> <a class="dropdown-item" href="#">Log out</a>
</div>
</li>
</ul>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h3 class="text-center">
Taddm Mapping
</h3>
</div>
</div>
<div class="row" id="search-row">
<div class="col-md-8">
<div class="filter-search">
<input class="form-control" id="myInput" type="text" placeholder="Search..">
<div class="list-group" id="myList">
<div th:each="plants : ${plants}">
</div>
</div>
</div>
</div>
<div class="col-md-4">
<span class="input-group-btn">
<a class="btn btn-primary eBtn">View</a>
<!-- <a th:href="#{findOne/(appcode=01G)}" class="btn btn-primary eBtn">View</a> -->
</span>
</div>
<div class="myForm">
<form th:action="#{/save}" method="POST">
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Update or Create</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label for="appcode" class="col-form-label">AppCode:</label>
<input type="text" class="form-control" id="appcode" name="appcode" value=""/>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary" value="save"/>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
jQuery:
// Empty JS for your own code to be here
$(document).ready(function() {
$("#myList").toggle();
$("#myInput").on("focus", function() {
$("#myList").toggle();
});
$("#myInput").on("focusout", function() {
// Here, it'll wait 100 miliseconds to hide the list.
setTimeout(function() {
$("#myList").toggle();
}, 250);
});
$("#myInput").on("keyup", function() {
var value = $(this).val().toLowerCase();
$("#myList a").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
// This is the code to populate the field after selecting an option.
$("#myList a").on("click", function() {
var texto = $(this).text();
$("#myInput").val(texto);
});
$(".eBtn").on("click", function(event){
$("a").attr("href","#{findOne/(appcode='01G')}"); //Test
event.preventDefault();
var href = $(this).attr('href');
console.log(href);
$.get(href, function(appcode,status){
$("#appcode").val(appcode);
});
$("#exampleModal").modal();
});
});
Controller:
#RequestMapping("/findOne")
#ResponseBody
public String findOne(String appcode) {
System.out.println(mAppRepo.findById(appcode).get().getmAppName());
return mAppRepo.findById(appcode).get().getmAppName();
}
I'm trying to wrap my list with div, here is my Thymeleaf structure:
<th:block th:if="${predStatus.namePrem}">
<div class="Holder">
<ul id="holder" class="price-table__info">
<li>
<p class="exam1" th:text="#{exam2}"></p>
</li>
</ul>
</th:block>
<ul id="holder" class="price-table__info">
<li>
<p th:unless="${predStatus.kom}" class="top" th:text="#{usp}"></p>
<p th:if="${predStatus.kom}" class="top" th:text="#{usp1}"></p>
</li>
</ul>
</div>
What I trying to achieve is this structure
<div class="Holder">
<ul id="holder" class="price-table__info">
<li>
<p class="top">Title 1</p>
</li>
</ul>
<ul id="holder" class="price-table__info">
<li>
<p class="top">Title 2</p>
</li>
</ul>
</div>
Can anybody help me?
Can you try the following?
Just put the condition in the div
<div class="Holder" th:if="${predStatus.namePrem}">
<ul id="holder" class="price-table__info">
<li>
<p class="exam1" th:text="#{exam2}"></p>
</li>
</ul>
<ul id="holder" class="price-table__info">
<li>
<p th:unless="${predStatus.kom}" class="top" th:text="#{usp}"></p>
<p th:if="${predStatus.kom}" class="top" th:text="#{usp1}"></p>
</li>
</ul>
</div>
In the image below you will see that my navbar is at the top of the page however it is slightly covering the heading that is supposed to be beneath it. How do I fix this?
My code for the navigation bar:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-
toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="userProfile1">
<img alt="Brand"">
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>Profile</li>
<li class="dropdown">
Menu <span class="caret"></span>
<ul class="dropdown-menu">
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Logout</li>
</ul>
</div><!-- /.navbar-collapse -->
I added the following to my CSS file but it didn't change anything:
body {
padding-top: 60px;
}
#media (max-width: 979px) {
body {
padding-top: 0px;
}
}
You can always give your heading a DIV tag and give that div a margin-top.
CSS:
.heading-text {
margin-top: 100px;
}
HTML:
<div class="heading-text">
<h1>My Title</h1>
</div>
im 'developing' an application made using Spring Boot, i am not so sure how to manage templates.
I've tought two ways to do this:
Using custom tags and returning the value of the HTML/JSP file as a String and use it
Something like this
<th:header></th:header>
<!-- This would be the header (The implementation of this tag in Java) -->
<body>
Things that are not common
<th:footer></th:footer>
<!-- This would be the footer -->
</body>
The other way could be using includes, but im not so sure how to do it...
Not sure if theres another way of doing this using Spring. Hope that you could understand me.
Thanks you before hand :·).
You could use Thymeleaf. Then you can use
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/header :: common-header" />
<body>
<div th:replace="common/navbar :: common-navbar" />
<your content here>
</body
</html>
Then you would have the common-header and common-navbar thymeleaf fragments in separate files like so (note the th:fragment in the common files. Also note that these files are under a common folder):
<head th:fragment="common-header">
<title>DevOps Buddy</title>
<!-- Bootstrap core CSS -->
<link th:href="#{/webjars/bootstrap/3.3.6/css/bootstrap.min.css}"
rel="stylesheet" media="screen" />
<!-- Custom styles for this template -->
<link type="text/css" th:href="#{/css/styles.css}" rel="stylesheet" media="screen"/>
And so
<div th:fragment="common-navbar" class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a th:text="#{navbar.home.text}" href="/"></a></li>
<li><a th:text="#{navbar.about.text}" href="/about"></a></li>
<li><a th:text="#{navbar.contact.text}" href="/contact"></a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li th:if="${#authorization.expression('!isAuthenticated()')}">
<a th:href="#{/login}" th:text="#{navbar.login.text}" />
</li>
<li th:if="${#authorization.expression('isAuthenticated()')}">
<form id="f" th:action="#{/logout}" method="post" role="form" class="navbar-form">
<button type="submit" th:text="#{navbar.logout.text}" class="btn btn-primary" />
</form>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
Let's say, I want to achieve this with Struts iterator:
<div class="carousel-inner">
<div class="active item">
<div class="row-fluid">
<ul class="thumbnails">
<li class="span3"><img src="images/sample/clients/client1.png"></li>
<li class="span3"><img src="images/sample/clients/client2.png"></li>
<li class="span3"><img src="images/sample/clients/client3.png"></li>
<li class="span3"><img src="images/sample/clients/client4.png"></li>
</ul>
</div>
</div>
<div class="item">
<div class="row-fluid">
<ul class="thumbnails">
<li class="span3"><img src="images/sample/clients/client4.png"></li>
<li class="span3"><img src="images/sample/clients/client3.png"></li>
<li class="span3"><img src="images/sample/clients/client2.png"></li>
<li class="span3"><img src="images/sample/clients/client1.png"></li>
</ul>
</div>
</div>
<div class="item">
<div class="row-fluid">
<ul class="thumbnails">
<li class="span3"><img src="images/sample/clients/client1.png"></li>
<li class="span3"><img src="images/sample/clients/client2.png"></li>
<li class="span3"><img src="images/sample/clients/client3.png"></li>
<li class="span3"><img src="images/sample/clients/client4.png"></li>
</ul>
</div>
</div>
</div>
This is what I have tried:
<div class="carousel-inner">
<div class="active item">
<div class="row-fluid">
<ul class="thumbnails">
<s:iterator value="members" begin="0" end="3">
<li class="span3"><img src="<s:property value='imageUrlPrefix' /><s:property value='imageName'>" /></li>
</ul>
</div>
</div>
<div class="item">
<div class="row-fluid">
<ul class="thumbnails">
<s:iterator value="members" begin="3" end="7">
<li class="span3"><img src="<s:property value='imageUrlPrefix' /><s:property value='imageName'>" /></li>
</ul>
</div>
</div>
</div>
I want my struts iterator to create item classes with 4 list items each. Once a class is filled with 4 list items, the iterator must create another item class. How can I achieve this?
Thank you
You can achieve this pretty easily by using the module operator (as described in this answer):
<div class="carousel-inner">
<div class="active item">
<div class="row-fluid">
<ul class="thumbnails">
<s:iterator value="members" status="ctr" >
<li class="span3">
<a href="#">
<img src="<s:property value='imageUrlPrefix' />
<s:property value='imageName'>" />
</a>
</li>
<s:if test="%{#ctr.count % 4 == 0}" >
</ul>
</div>
</div>
<div class="item">
<div class="row-fluid">
<ul class="thumbnails">
</s:if>
</s:iterator>
</ul>
</div>
</div>
</div>
Note: to set the active class to the right item, use an <s:if> inside the iterator, and another one outside to check if it's the first element to be active.