java.lang.ClassNotFoundException: org.apache.xpath.VariableStack when use jstl xml - java

I have some code here.
<c:set var="songId" value="${param.songid}"/>
<c:import var="xml" url="WEB-INF/comment.xml" />
<x:parse var="doc" doc="${xml}" scope="session" />
<c:catch var="ex">
<x:forEach var="cmt" select="$doc//*[songId=$songId]" varStatus="counter">
<li>
<div class="avacmtSide">
</div>
<div class="ctcmtSide">
<x:out select="$cmt/uploader"/>
<div style="padding:10px;"><x:out select="$cmt/comment"/> </div>
</div>
<div class="clear"></div>
</li>
</x:forEach>
When I run it there is a error java.lang.ClassNotFoundException: org.apache.xpath.VariableStack.
When I search google for this error. People said there is missing xalan library. But I have added xalan-2.7.0.jar in my project and it doesn't work. Anyone who know it please help me. Thanks.

The variable syntax is incorrect:
[songId=$songId]
It should be this:
"$doc//*[#songId=${pageScope:songId}]"
Using JSTL Data as XPath Variables
Scoped variables can be used in XPath expressions ($implicitObject:variableName) similar to how they are used in EL (${implicitObject.variableName}). If the implicit object is omitted, scopes will be searched in standard order. Note that the “.” and “[]” notations cannot be used for accessing bean properties.
References
XPath: Variable Reference
JSTL - using variables in an xpath?
JSTL Quick Reference

Related

Struts2 tags inserting <br>

I am currently upgrading from Struts 2.0.11.1 to Struts 2.3.7, but I'm having a problem with the output of Struts tags (like <s:radio>and <s:textarea>. Before, the output of these tags were two <div>'s, one containing the label, and one containing the radiobuttons/textarea. But after I upgraded there is a <br>between the two <div>'s.
Before:
<div id="wwlbl_something_someString" class="wwlbl">
<label for="something_someString" class="desc">Some label</label>
</div>
<div id="wwctrl_something_someString" class="wwctrl">
<!--radiobuttons/textarea -->
</div>
After
<div id="wwlbl_something_someString" class="wwlbl">
<label for="something_someString" class="desc">Some label</label>
</div>
<!-- I don't want this.. -->
<br>
<!-- -->
<div id="wwctrl_something_someString" class="wwctrl">
<!--radiobuttons/textarea -->
</div>
The jsp:
<li class="wwgrp flowClear">
<h3 class="header"><s:text name="something.header"/></h3>
<ol class="nobullets">
<s:radio list="yesNoList"
label="%{getText('something.text.label')}"
name="something.someString"
value="something.some"
disabled="%{readOnly}"/>
</ol>
</li>
#Comment: There are a lot of things in this project that many have never seen before (not in a good way) ;)
Does anyone know if this is something that has changed in Struts, and if so, how to avoid creating the <br>'s?
I actually stumbled across the answer. As an answer to the last comment struts.ui.theme is set to css_xhtml.
http://depressedprogrammer.wordpress.com/2007/04/11/struts-2-form-control-templates/
One quick note, the xhtml_css theme also generates a very worthless <br/> tag between a label and the control which can throw of your entire look, do get rid of this you’ll have to do a .wwgrp br { display: none; } in your CSS stylesheeet.
So I assume doing this will solve the problem, it is something added by struts theme, probably changed when I updated Struts version.
Pointers on how this is usually set up/should be set up is welcomed, as I do not know anything about this.. :)

Conditionally displaying a block of HTML based on presence of resource bundle key

I'm using JSF, and I have to load a bundle called Extra.
<f:loadBundle basename="com.ni.lib.extra.delivery.ExtraBundle" var="extra" />
Inside that extra variable, there's a value called downtime_notice. Now, if that value is NOT empty, I have to show a css segment with the text contained within the downtime_notice value. Something like this (of course this doesn't work):
if(extra.donwtime_notice!=''){
<div class="pnx-msg pnx-msg-warning clearfix">
<i class="pnx-msg-icon pnx-icon-msg-warning"/>
<span class="pnx-msg-content"><h:outputText value="#{extra.downtime_notice}" escape="false"/></span>
</div>
</br>
}
I can use javascript, just in case.
Any ideas? Thanks!
You can use <ui:fragment> or <h:panelGroup> to conditionally render content. You can use the empty keyword in EL to check if a variable is not null or empty. So, all with all this should do:
<ui:fragment rendered="#{not empty extra.donwtime_notice}">
<div class="pnx-msg pnx-msg-warning clearfix">
<i class="pnx-msg-icon pnx-icon-msg-warning"/>
<span class="pnx-msg-content"><h:outputText value="#{extra.downtime_notice}" escape="false"/></span>
</div>
</ui:fragment>
Or, using <h:panelGroup layout="block"> which renders a <div> already:
<h:panelGroup layout="block" styleClass="pnx-msg pnx-msg-warning clearfix" rendered="#{not empty extra.donwtime_notice}">
<i class="pnx-msg-icon pnx-icon-msg-warning"/>
<span class="pnx-msg-content"><h:outputText value="#{extra.downtime_notice}" escape="false"/></span>
</h:panelGroup>
Note that some may opt to use <f:verbatim> for the job, but this tag is deprecated since JSF2.
See also:
Conditionally displaying JSF components
Alternative to ui:fragment in JSF
Unrelated to the concrete problem, the </br> tag is invalid HTML, so I omitted it form the examples.

How to define a namespace in spring

I've been working local on tomcat server 7, now I uploaded my project to a server but it has tomcat 6. So the following doesn't work:
model.addAttribute("category",cat);
<div class="span4">
<h2>
Category:
<c:out value="${category}" />
</h2>
<br />
<c:forEach items="${categoryList}" var="item">
<div class="alert alert-init">
<c:url value="/getInit/${item.getiID()}" var="url" />
<c:out value="${item.getTitle()}" />
</div>
</c:forEach>
</div>
It gives me following error code:
org.apache.jasper.JasperException: /WEB-INF/views/categoryinitiatives.jsp(34,5) The function iIDGetter must be used with a prefix when a default namespace is not specified
I've been searching all over the web to find a solution for this problem, but without success. Does anyone know how to fix this?
If you wanna access a property of a bean using EL, just write item.title instead of item.getTitle(). It will automatically call the getter and probably solve your problem.
Moreover, item.getiID() isn't a valid name. If you have a property iID in your bean, you have to name the getter getIID() to access it using EL. Have a look at the lowerCamelCase syntax.

JSF: conditionally render a list item (<li>)

I just inherited a project implemented in JSF. I have the following code which looks fine in Chrome, but Firefox renders the borders on the "empty" list items:
<ul>
<li><a href="/home">Home</li>
<li>
<s:link view="/signup.xhtml" rendered="#{someCondition}">Sign Up</s:link>
</li>
<!-- etc... -->
</ul>
Which ends up looking like:
Is there a JSF tag to conditionally render the <li> ?
If you do it as in #CoolBeans example, you will get a <span> around your <li>. In some cases it might disrupt your layout, besides you don't really want an extra tag under <ul>. To get rid of it, use <ui:fragment rendered="#{condition}" /> around your item instead of <h:panelGroup>.
Also you can use style attribute to hide an item:
<li style="display: #{condition ? 'list-item' : 'none'};" />
No li is vanilla html, not a jsf component.
You can hack it by putting a <h:panelGroup /> around the li element and setting the rendered property on it.
ie.
<h:panelGroup rendered="#{someCondition}">
<li>
<s:link view="/signup.xhtml">Sign Up</s:link>
</li>
</h:panelGroup>
Another option is to use <f:verbatim rendered="#{someCondition}" >, but keep in mind that it has been deprecated in JSF 2.0.
You could also use the core JSTL library:
<c:if test="#{someCondition}">
<li>
<s:link view="/signup.xhtml">Sign Up</s:link>
</li>
</c:if>
I think using this core tag makes the code easier to understand than using the panelGroup tag.

Scriptlet variable doesn't get evaluated inside an attribute of a custom JSP tag

I am trying to have a JavaScript function called when I click a link. This JavaScript function is definied in an attribute of a JSP tag and I am trying to pass a scriptlet variable to the function. However, it doesn't get evaluated. The relevant part of the code is:
<span>
<mysecurity:secure_link id='<%="editButton_"+commentUUID%>' entitlement=""
actionOnClick="editComment('<%= commentUUID %>');return false;"
isSurroundedByBrackets="true" enableTitle="" disableLink="<%=disableLink%>">
<span style="color:#0033BB; font:8pt arial;">
<bean:message key="button.edit" />
</span>
</mysecurity:secure_link>
</span>
IE8 mentions a JavaScript error in the bottom left corner. When I right click and view source, the generated HTML is:
onclick="editComment('<%= commentUUID %>');return false;"
So, the <%=commentUUID%> is not been evaluated in the actionOnClick attribute, but it's successfully been evaluated in id attribute.
How is this caused and how can I fix it?
I'm not sure whether the <mysecurity:secure_link> is a custom or an existing 3rd party JSP tag library. Modern JSP tags usually do not evaluate legacy scriptlet expressions. You should rather be using EL (Expression Language) instead.
First ensure that commentUUID variable is been stored as an attribute of the page or request scope so that it's available to EL, like as the following example in a preprocessing servlet:
request.setAttribute("commentUUID", commentUUID);
or using another scriptlet in JSP:
<% request.setAttribute("commentUUID", commentUUID); %>
or using JSTL's <c:set> in JSP:
<c:set var="commentUUID"><%=commentUUID%></c:set>
then you can access it as follows in EL:
<mysecurity:secure_link actionOnClick="editComment('${commentUUID}');return false;" />
What finally worked for me, with the #BalusC 's advice was to use editcomment(this.id.split('_')[1]). The correct working code is as follows:
<span>
<mysecurity:secure_link id='<%="editButton_"+commentUUID%>' entitlement=""
actionOnClick="javascript:editComment(this.id.split('_')[1]);return false;"
isSurroundedByBrackets="true" enableTitle="" disableLink="<%=disableLink%>">
<span style="color:#0033BB; font:8pt arial;">
<bean:message key="button.edit" />
</span>
</mysecurity:secure_link>
</span>

Categories