JSTL: c:if Not Found in Build Path - maven

I recently migrated an ANT project to Maven. After doing all the dependecnies and getting the project error free. I see this warning on in Eclipse:
The tag handler class for "c:if" (org.apache.taglibs.standard.tag.rt.core.IfTag) was not found on the Java Build Path
I see the same warnings for c:import, c:out c:set as well.
I do have the tag:
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
added in the JSP. And I have the JSTL 1.2 dependency added in the pom file. Can you tell me how to get rid of these warnings?

I had the same error. To fix it, I just added and saved the following in my pom.xml.
<!-- https://mvnrepository.com/artifact/org.apache.taglibs/taglibs-standard-impl -->
<dependency>
<groupId>org.apache.taglibs</groupId>
<artifactId>taglibs-standard-impl</artifactId>
<version>1.2.1</version>
</dependency>
In some older Eclipse versions, you may need to modify the "<c:if..." line of code, remove a character or more, save it then put it back as it was and save the file again. This in some case get rid of the warning.
My code used <c:set and <c:if as the following example. No warning displays. Perhaps, you may need to update your Eclipse. My Eclipse is IDE for Enterprise Java Developers Version: 2019-09 R (4.13.0).
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<%# attribute name="normalPrice" fragment="true" %>
<%# attribute name="onSale" fragment="true" %>
<%# variable name-given="name" %>
<%# variable name-given="price" %>
<%# variable name-given="origPrice" %>
<%# variable name-given="salePrice" %>
<head>
<title>Tag Example</title>
</head>
<table border="1">
<tr>
<td>
<c:set var="name" value="Hand-held Color PDA"/>
<c:set var="price" value="$298.86"/>
<jsp:invoke fragment="normalPrice"/>
</td>
<td>
<c:set var="name" value="4-Pack 150 Watt Light Bulbs"/>
<c:set var="origPrice" value="$2.98"/>
<c:set var="salePrice" value="$2.32"/>
<jsp:invoke fragment="onSale"/>
</td>
<td>
<c:set var="name" value="Digital Cellular Phone"/>
<c:set var="price" value="$68.74"/>
<jsp:invoke fragment="normalPrice"/>
</td>
<td>
<c:set var="name" value="Baby Grand Piano"/>
<c:set var="price" value="$10,800.00"/>
<jsp:invoke fragment="normalPrice"/>
</td>
<td>
<c:set var="name" value="Luxury Car w/ Leather Seats"/>
<c:set var="origPrice" value="$23,980.00"/>
<c:set var="salePrice" value="$21,070.00"/>
<jsp:invoke fragment="onSale"/>
</td>
</tr>
</table>
<body>
<c:set var = "salary" scope = "session" value = "${2000*2}"/>
<c:if test = "${salary > 2000}">
<p>My salary is: <c:out value = "${salary}"/><p>
</c:if>
</body>

If the tag works actually fine, it is just a false negative from Eclipse. In that case you could force a new check editing the tag name and then setting it back to the right name.
So, for instance, click on your "c:if" tag, remove a single character and then re-enter it (exactly as it was before). Save it. In my case that was enough to get rid of the warning.

Related

c:forEach does not print anything

I'm exploring spring mvc and I'm trying to print a list in a jsp file. Here the relevant parts of the code:
Controller
#Transactional
#RequestMapping("/homepage")
public String getHomePage(HttpServletRequest request, Model model) {
List<ProfessoreDAO> professori = (List<ProfessoreDAO>) sessionFactory
.getCurrentSession()
.createQuery("from ProfessoreDAO", ProfessoreDAO.class)
.getResultList();
System.out.println("Recuperati professori: " + professori);
model.addAttribute("professori", professori);
return "homepage";
}
jsp file:
<c:forEach var="professore" items="${professori}">
<tr>
<td>
${professore.nome}
</td>
<td>
<c:out value="${professore.cognome}" />
</td>
<td>
<c:out value="${professore.materia}" />
</td>
</tr>
</c:forEach>
At the moment I cannot debug on the server, but from what I see opening Firefox:
<c:foreach items="[Mario-Rossi]" var="professore">
</c:foreach>
It seems that the property is well defined ("Mario-Rossi" is just the toString implementation result of the only object present in the list) I've tried with both
<td> ${professore.nome} </td>
and
<td> <c:out value="${professore.cognome}" /> </td>
as you can see, but I've no results
as stated in the answer above I had forgotten to import the jstl support. To achieve this (I'm using tomcat 9, solution can slightly change depending on the tomcat version) I did:
pom.xml
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jakarta.servlet.jsp.jstl</artifactId>
<version>1.2.6</version>
</dependency>
jsp file
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

Dynamic select list in a Liferay MVCPortlet

You can create a select list with static options in Liferay MVCPortlet JSP page like this:
<%# taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<aui:form>
<aui:select name="items">
<aui:option value="item1">Item1</aui:option>
<aui:option value="item2">Item2</aui:option>
</aui:select>
</aui:form>
What is the recommended way of creating the options dynamically for a list of objects stored in portlet session?
Use a foreach tag:
https://www.tutorialspoint.com/jsp/jstl_core_foreach_tag.htm
<%# taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<%# taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<aui:form>
<aui:select name="items">
<c:forEach items="<%=yourList%>" var="yourlistItem">
<aui:option value="${yourlistItem.value}">${yourlistItem.name}</aui:option>
</c:forEach>
</aui:select>
</aui:form>

Output not visible jstl c:out not showing on browser

Problem: When I open page view source this data is shown on browser
Hello there jsp
<c:forEach var="student" items="2abcnullmca">
<c:out value= ""/>
</c:forEach>
<c:out value= "abc" />
And on browser it does not show c:out value in spring I have used model.addAttribute() to show data
Actually I forgot to include jstl tag thanks for looking into it but.
Here is the Tag -
<%# taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>

Type [java.lang.String] is not valid for option items upon migrating from Spring 3.0.6 to 3.2.3

I am working on migrating a dynamic web project from Spring 3.0.6 to 3.2.3. Prior to this migration, we had no issue with our dropdowns. However, after migrating, we get the following error:
Exception created : com.ibm.websphere.servlet.error.ServletErrorReport: javax.servlet.jsp.JspException: Type [java.lang.String] is not valid for option items
I've removed all the code to isolate the issue, so below is the relevant code. Please let me know if any further information is needed. The thing that puzzles me is that the List isn't even String based. I realize that the JSP will treat the values as String for the options, but my understanding is that there is a built-in PropertyEditor that would do this translation.
Controller:
#RequestMapping("/reports-menu.html")
public String showReportsHome(#ModelAttribute("reportForm")ReportForm reportForm, Model model, HttpSession session, HttpServletResponse response, HttpServletRequest request) {
List<Integer> intList = new ArrayList<Integer>();
intList.add(1);
intList.add(2);
intList.add(3);
model.addAttribute("intList", intList);
return "reports-home-int";
}
JSP:
<%# taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%# taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%# taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%# taglib uri="/WEB-INF/tld/sbp.tld" prefix="sbp" %>
<form:form name="report_form" method="POST" modelAttribute="reportForm" action="reports-menu.html" id="report_form">
<form:hidden path="download" id="form_download"/>
<form:hidden path="sortDirection" />
<form:hidden path="sortBy"/>
<input type="hidden" name="reset"/>
<div align="left">
<table border="0">
<tr>
<td><b>Mailer Name</b></td>
<td>
<form:select path="mailerCond">
<form:options items="${intList}" />
</form:select>
</td>
</tr>
</table>
</div>
</form:form>

JSTL tags don't evaluate if I import

I use dynamic include on a page:
<div class="top">
<jsp:include page="Header.jsp"/>
</div>
This is the important part in the Header.jsp:
<H4>
JSTL TAG Test: </br>
<c:if test="${sessionScope.username != null}" >
<c:out value="Hello, ${sessionScope.username}"/>
</c:if>
</h4>
The result on my main page source is:
<H4>
JSTL TAG Test: </br>
<c:if test=Swank != null >
<c:out value="Hello, Swank"/>
</c:if>
</h4>
I use this: <%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> in the main page.
Does anybody know how can I use JSTL if I import it from another page?
Thanks, Zoltán
Add the same declaration
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
into your Header.jsp file.
I agree with the given answer, just with a slight modification:
<#include file="Header.jsp" %>
Notice the '%' to close the directive.
You can solve the problem by using JSP include directive
<%# include file="Header.jsp" %>
Because the content of the file given in the include directive is pasted as it is, in the place where the JSP include directive is used.
But in include action <jsp:include> At runtime, the included file will be ‘executed’ and the result content will be included with the soure JSP page.
Updated:
In JSTL condition should be written inside double quotes.
<c:if test="${sessionScope.username} != null"></c:if>
Add double quotes in your condition.

Resources