I got a problem with some javascript code that I cant find a solution to and hope some of you can help me find a solution.
The problem seems to be with the if statment in the code below that says if(a>b)
. I get different errors depending on how I write the if statement end depending on where I look I get different errors.
Chrome's developer tool says:
Uncaught SyntaxError: Unexpected token ;
IE's developer tool says:
Uncaught SyntaxError: Unexpected token )
I get the same result if i write if(3>1)
so i don't Think its a or b that is the problem.
If i try if(b<a)
then glassfish throws an exception saying the error below where line 39 is the if statement
Error Traced[line: 39] The content of elements must consist of well-formed character data or markup.
if(1<3)
produces the same result as if(b<a)
now if i write if(3===1)
or if(3===3)
it works fine and the code runs perfectly and produces the expected result for using "===" signs, but now I need to be able to use <
or >
.
This code worked fine before upgrading glassfish to 4.1 and a lot of the packages to the latest version.
I have recompiled it many times and restarted the server but so far no success.
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:cc="http://java.sun.com/jsf/composite" xmlns:tp="http://java.sun.com/jsf/composite/components" xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<cc:interface>
<cc:attribute name="text" type="java.lang.String" required="true" />
<cc:attribute name="maxsize" type="java.lang.Integer" required="true" />
<cc:attribute name="style" type="java.lang.String" required="false" />
</cc:interface>
<cc:implementation>
<p id="par#{component.clientId}" style="#{cc.attrs.style}">
<span id="span#{component.clientId}"><h:outputText value="#{cc.attrs.text}" /></span>
</p>
<script>
var span = $("[id='span#{component.clientId}']");
var linkShow = $("<a/>");
linkShow.attr("id", "linkShow#{component.clientId}");
linkShow.attr("style", "color: #07A0DD;");
linkShow.text("Visa mer");
linkShow.hide();
var linkHide = $("<a/>");
linkHide.attr("id", "linkHide#{component.clientId}");
linkHide.attr("style", "color: #07A0DD;");
linkHide.text("Visa mindre");
linkHide.hide();
var a = "#{cc.attrs.text}".length;
var b = #{cc.attrs.maxsize};
if (a > b) {
span.text("#{cc.attrs.text}".substring(0, # {
cc.attrs.maxsize
}) + "... ");
$("[id='par#{component.clientId}']").append(span);
$("[id='par#{component.clientId}']").append(linkShow);
$("[id='par#{component.clientId}']").append(linkHide);
$("[id='linkShow#{component.clientId}']").show();
$("[id='linkShow#{component.clientId}']").click(function() {
$("[id='span#{component.clientId}']").text("#{cc.attrs.text}");
$("[id='linkHide#{component.clientId}']").show();
$("[id='linkShow#{component.clientId}']").hide();
});
$("[id='linkHide#{component.clientId}']").click(function() {
$("[id='span#{component.clientId}']").text("#{cc.attrs.text}".substring(0, # { cc.attrs.maxsize}) + "... ");
$("[id='linkShow#{component.clientId}']").show();
$("[id='linkHide#{component.clientId}']").hide();
});
}
</script>
</cc:implementation>
</html>