This is my arraylist for index 17
In this code may have data list or may not. Data is dispay when there are records. Not handled for no records
Java code:
//To avoid arrayindexoutofbound exception length checked
if (resultList.length >17) {
statisticsDetails.setqNames(resultList[17]);
//System.out.println(resultList[17]);
String[] qName=resultList[17].split("\\^");
List<StatisticsDetails> statisticsDetailsList = new ArrayList<StatisticsDetails>();
for (String queueName:qName ){
StatisticsDetails details = new StatisticsDetails();
String[] splitQueues = queueName.split("=");
details.setqKey(splitQueues[0]);
details.setqCount(splitQueues[1]);
statisticsDetailsList.add(details);
}
statisticsDetails.setqNamesList(statisticsDetailsList);
}
Jsp code:
<logic:iterate id="iteratorId" name="statistics.statisticsDetails" property="qNamesList">
<tr>
<td class="col-sm-6 col-md-6 col-lg-6"><bean:write name="iteratorId" property="qKey" /></td>
<td class="col-sm-6 col-md-6 col-lg-6"><bean:write name="iteratorId" property="qCount" /></td>
</tr>
</logic:iterate>
how to avoid arraybound error and JSP to handle when no data found
Use a null check using JSTL(Do not forget to import the tag library):
import core library:
<%# taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
and then use:
<c:if test="${not empty statistics.statisticsDetails}">
//keep your code here to iterate the list
</c:if>
Or use:
<%# taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
and then:
<c:if test="${fn:length(statistics.statisticsDetails) > 0}">
//keep your code here to iterate the list
</c:if>
Please check all mapping is correct or not in the struts-config.xml. In my case, i found incorrect type was mentioned for form and then it was giving the error. Type means package name for the form. in tag.
I have the following line of code in a JSP File in my web app t
<% if (!maintenance) { %>
<customTag:DialogEntry entry="<%=new com.presentation.generic.session.DialogEntry("dialog1","225px","true","true",new String[]{"authentification.Login.action.logInApplicationLabel"},new String[]{"logInApplication()"}) %>"/>
<% } else { %>
<customTag:DialogEntry entry="<%=new com.presentation.generic.session.DialogEntry("dialog1","225px","true","true",new String[]{},new String[]{}) %>"/>
<% } %>
The error message that I get is:
/WEB-INF/tags/DialogEntry.tag According to the TLD , the value
attribute accepts no expression
How do I resolve this problem?
DialogEntry.tag:
<%# attribute name="entry" rtexprvalue="true" type="com.presentation.generic.session.DialogEntry" %>
<%# taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<%# taglib uri="http://struts.apache.org/tags-html-el" prefix="html" %>
<%# taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean" %>
<%# taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%# taglib uri="http://struts.apache.org/tags-logic-el" prefix="logic" %>
<script type="text/javascript">
//confirm("<c:out value="${entry.id}" /> début");
var <c:out value="${entry.id}" /> = new YAHOO.widget.Dialog("<c:out value="${entry.id}" />",
{
width: "<c:out value="${entry.size}" />",
<c:if test="${\"\" != entry.visible}">
visible:true,
</c:if>
<c:if test="${\"\" == entry.visible}">
visible:false,
</c:if>
close:false,
draggable :false
<c:if test="${\"\" != entry.effect}">
,effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}
} );
</c:if>
<c:if test="${\"\" == entry.effect}">
} );
</c:if>
<c:if test="${\"false\" != entry.hasButtons}">
var myButtons = [
<c:forEach var="button" items="${entry.buttons}" varStatus="ind">
{ text:"<bean:message key="${button}"/>", handler:function() {<c:out value="${entry.functions[ind.index]}" />;}, isDefault:true }
<c:if test="${!empty entry.buttons[ind.index+1]}">
,
</c:if>
</c:forEach>
];
<c:out value="${entry.id}" />.cfg.queueProperty("buttons", myButtons);
</c:if>
// confirm("<c:out value="${entry.id}" /> fin - debut script");
if($.browser.msie && $('#header').size() > 0 ){
// confirm("<c:out value="${entry.id}" /> fin - debut script IE");
var menuWidth = $("div#menu").get(0).clientWidth;
var headerHeight = $("div#header").get(0).clientHeight;
var width = document.body.clientWidth;
var contentWidthConnected = width - menuWidth;
if( $('div#content_onglets').size() > 0){
// confirm("<c:out value="${entry.id}" /> fin - debut script IE Onglet");
<c:out value="${entry.id}" />.cfg.queueProperty("x", 50);
<c:out value="${entry.id}" />.cfg.queueProperty("y", 0);
}
else{
// confirm("<c:out value="${entry.id}" /> fin - debut script IE Pas Onglet");
<c:out value="${entry.id}" />.cfg.queueProperty("x", menuWidth + 50);
<c:out value="${entry.id}" />.cfg.queueProperty("y", headerHeight );
}
// confirm("<c:out value="${entry.id}" /> fin - FIN script IE");
}
else{
<c:out value="${entry.id}" />.cfg.queueProperty("fixedcenter", true);
}
// confirm("<c:out value="${entry.id}" /> fin script");
<c:out value="${entry.id}" />.render();
// confirm("<c:out value="${entry.id}" /> fin script 2");
</script>
Either escape your inner quotes:
<% if (!maintenance) { %>
<customTag:DialogEntry entry="<%=new com.presentation.generic.session.DialogEntry(\"dialog1\",\"225px\",\"true\",\"true\",new String[]{\"authentification.Login.action.logInApplicationLabel\"},new String[]{\"logInApplication()\"}) %>"/>
<% } else { %>
<customTag:DialogEntry entry="<%=new com.presentation.generic.session.DialogEntry(\"dialog1\",\"225px\",\"true\",\"true\",new String[]{},new String[]{}) %>"/>
<% } %>
Or use single quotes:
<% if (!maintenance) { %>
<customTag:DialogEntry entry='<%=new com.presentation.generic.session.DialogEntry("dialog1","225px","true","true",new String[]{"authentification.Login.action.logInApplicationLabel"},new String[]{"logInApplication()"}) %>'/>
<% } else { %>
<customTag:DialogEntry entry='<%=new com.presentation.generic.session.DialogEntry("dialog1","225px","true","true",new String[]{},new String[]{}) %>'/>
<% } %>
Reading the error message is quoted with " which must be escaped when used within the value you see that having " inside your text is the cause. Hence, either your text is not defined with " (the second solution, where you use ') or the " inside the text have a \ to escape them and make them actual characters in the text.
Escape all " with \" inside your block:
entry=""
I define a class of Clue :
Class Clue{
...
String text;
..
getter/setter method
}
I want to get ${clue.text} from jsp to use in the scope "<%...%>" to just show subSequence(0, 10),like this:
<c:forEach items="${clues}" var = "clue">
<tr>
<td>${clue.weibo.user.name}</td>
<td>
<%
String str = ${clue.weibo.text};
%>
<%=str.subSequence(0, 10) %>
</td>
</tr>
</c:forEach>
How can I do?
To access A JSTL variable in a scriplet:
<%
String str = (String)pageContext.getAttribute("clue.weibo.text", PageContext.REQUEST_SCOPE);
%>
However, a better way is to use JSTL functions to manipulate the string.
<%# taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:forEach items="${clues}" var = "clue">
<tr>
<td>${clue.weibo.user.name}</td>
<td>
${fn:substring(clue.weibo.text, 0, 10)}
</td>
</tr>
</c:forEach>
How can I use session for facelets ?
What's the syntax...?
I would put a code like this
<% String loginSession = (String)session.getAttribute("login"); %>
<% if(loginSession != null){ %>
Welcome <%= session.getAttribute("firstName") %> !
<% }else{ %>
Guest
<% } %>
Thanks
#{sessionScope.login}
You can't have if-s in JSF (you can with JSTL, but it has complications). Instead you can choose to render or not a component:
<h:outputText value="Guest" rendered="#{sessionScope.login != null}" />
I have the following in my jsp page (assume that client is an object )
<%
if( client == null)
%>
NO client
<%
else
%>
<a href='page.jsp?aid=<%=client.getID()%>'> and his name is <%=client.getName()%>
thanks
You're missing the brackets:
<% if( client == null) { %>
NO client
<% } else { %>
<a href='page.jsp?aid=<%=client.getID()%>'> and his name is <%=client.getName()%>
<% } %>
That said, this is an example of bad JSP code. Consider using JSTL tags / expressions instead of scriptlets.
in jstl it would be something similar to
<c:choose>
<c:when test="${client is null}">
NO client
</c:when>
<c:otherwise>
<A href="<c:url value="page.jsp" >
<c:param name="aid" value="${client.ID}" />
</c:url>"
> and his name is <c:out value="${client.name}"/>
</c:otherwise>