In my jsp page i am adding title attribute dynamically in anchor using this code.
<c:set var="titleAttributeValue" value="${(anchorListfields[3] != '') ? 'title=${anchorListfields[3]}' : ''}" scope="page" />
but rather than showing the value of title attribute in anchor it showing like this <span><span>Start my Business</span><i></i></span>
how can i achieve this where is my error in syntax
You codes seems to be working.
Ensure you have JSTL library in your /WEB-INF/lib.
Add <%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> directive to your page.
I am using glassfish 4
Related
I am working with a JSTL and trying to implement a if tag
below is my code for file login.tag
<c:if test="${not empty param.error}">
//do something
</c:if>
My understanding is when I access this page
with path/index.jsp //the if tag is not executed
with path/index.jsp?error=wrongpassword //the if tag is executed
But what I am getting now is the if tag is always execute true, Please advice
If you want to use c:if tag you should use JSP taglib directive for JSTL core tag library. Use below code at the top of the JSP
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
You also need libraries for JSTL as dependencies to your project. See this answer to find maven dependencies.
An example will make this clearer!
The jsp file...
<%# taglib prefix ="jam" uri= "http://jam.tld" %>
<%# page language="java" contentType="text/html; charset=UTF-8" pageEncoding="ISO-8859-1"%>
<%
String targetPage = true ? "toast" : "bread";
%>
<jam:text onmousedown="movePage('<%=targetPage%>');" id="<%=targetPage%>"><%=targetPage%></jam:text>
Note - the taglib is not mine and I have no control over it. (it isn't really called jam either :).
This then creates this HTML...
<td onmousedown="movePage('<%=targetpage%>;');" id="toast">toast</td>
Which as you can see: the <%=targetPage%> was only replaced/parsed in the non-javascript bit?
The compiled jsp file looks like this:
jspx_th_jam_005ftext_005f2.setOnmousedown("movepage('<%=targetpage%>')");
Anyone know what is going on, or how to fix it?
Why is the <%=%> tag being ignored when it is part of JavaScript statement?
:)
Here's a bit of a cheat solution, you dont need the JSP tag in that JS call. In fact, it's tidier this way
<jam:text onmousedown="movePage(this.id);" id="<%=targetPage%>"><%=targetPage%></jam:text>
I am trying (and learning) to build a java web framework, and in the process of developing its' code generator based on the content of the database. In the view making process, I stumble in a difficulty, which I don't know how to solve it.
Firstly, I want all the pages to be created using the following index.jsp :
<body>
<%# include file="header.jsp" %>
<hr/>
<%# include file="body.jsp" %>
<hr/>
<%# include file="footer.jsp" %>
</body>
And, in the body.jsp, I want it to be like this :
<jsp:include page="${application_modul}" %>
Where application_modul is an attribute defined in its' controller this way :
request.setAttribute("application_modul","user_account\\view_user_account.jsp");
It can find the file correctly, but the processed jsp is not what I expected. Here :
<c:forEach items="[application.models.UserAccountModel#18a49e0, application.models.UserAccountModel#1f82982]" var="item" varStatus="status" >
<tr>
....
You can see the items attribute of jstl forEach, got its variable name (toString())...
Any Idea what the problem is????
I hope I describe my problem correctly
Many thanks!
PS :
I already create a quick fix for this, but not what I want it though. In the generated view_user_account.jsp, I do it like this :
<body>
<%# include file="header.jsp" %>
<hr/>
<c:forEach items="${row}" var="item" varStatus="status" >
<tr>
....
<hr/>
<%# include file="footer.jsp" %>
</body>
You can see that I create the whole file here...
EDITED:
PS : ${row} is an ArrayList populated with data from certain table
So, to summarize your problem in a single sentence, JSTL tags are not been parsed and they end up plain in generated HTML output?
You need to declare JSTL taglib in top of the JSP page where you're using JSTL tags to get them to run. For the JSTL core taglib, that'll be
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
I am not sure but, Try this...
index.jsp
<jsp:param name="parameterName" value="{parameterValue | <%= expression %>}" />
I followed THIS but had no luck.
My .jsp file has in head tag:
<s:head theme="ajax" />
and in body tag
<s:datetimepicker name="dateOfBirth" label="Format (yyyy-MM-dd)" displayFormat="yyyy-MM-dd"/>
But it is not showing, here is the picture:
My generated HTML source code contains all necessary lines like in example (script tags and other are generated....)
Any ideas?
EDIT:
Following Quaternion's answer:
I was using, struts2-core-2.0.12.jar which recognized <s:datetimepicker /> tag but wasn't showing in my jsp page. After replacing struts2-core-2.0.12 with newer one struts2-core-2.2.1.jar, <s:datetimepicker /> tag wasn't recognized.
After putting <%# taglib prefix="sx" uri="/struts-dojo-tags" %> in head of the file it wasn't recognized as my tag library. Based on THIS, you should download struts2-dojo-plugin-2.1.2.jar separately and add it into your WEB-INF/lib folder (you can downlad it here --> struts-2.1.2-lib.zip --> struts2-dojo-plugin-2.1.2.jar).
After that you just use sx tag for your datetimepicker.
IMPORTANT: Don't forger to put <sx:head/> in head tag of your jsp page --> examples here.
The later versions of struts2 require:
<%# taglib prefix="sx" uri="/struts-dojo-tags" %>
Then of course change the tag namespace, using:
<sx:datetimepicker name="dateOfBirth" label="Format (yyyy-MM-dd)" displayFormat="yyyy-MM-dd"/>
See Struts2 datetimepicker It's best if you consult struts.apache.org and ensure you are using the documentation at the correct version, things change!
use
sx:head tag in the head section of jsp.
Are you sure you have <%# taglib prefix="s" uri="/struts-tags" %> included? I miss that at times wondering why things do not show up.
How do I access a JSP tag's attribute value within a JSTL tag? In the code below, I would like to access the url attribute and test if it's empty. I am using the JSTL 1.0 specification.
<%# taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%# attribute name="url" required="false"%>
<c:if test="${!empty url}">
...
</c:if>
If you're creating tag files, then you're using at least JSP 2.0 - which means you should be using at least JSTL 1.1. At any rate, the attribute directive should create a page-scoped var with the same name as its name attribute (unless it's optional and not provided). So, can you provide any more detail on the errors and/or output you're observing?