File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes JSF with EL notation throwing ReferenceSyntaxException PLEASE HELP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF with EL notation throwing ReferenceSyntaxException PLEASE HELP" Watch "JSF with EL notation throwing ReferenceSyntaxException PLEASE HELP" New topic
Author

JSF with EL notation throwing ReferenceSyntaxException PLEASE HELP

nena tamari
Greenhorn

Joined: Sep 21, 2011
Posts: 8
Hi Everyone,

I have some very simple code like the following (JSF):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=windows-1252"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<f:view>
<%@ include file="/includes/header.jspf" %>

<html>
<head>
<title>Welcome</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="expires" content="0">
<script src="scripts/js_scripts.js" type="text/javascript">
</script>

</head>

<body bgcolor="#FFFFFF" background="images/til_2000.jpg"
text="#000000" link="#000099" vlink="#330099" alink="#FF0000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top">
<td width="88%" valign="top">
<div align="left">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20" height="247"><img src="images/trans.gif" width="20" height="20"></td>
<td valign="top" height="247">
<p align="left"><img src="images/hd1_grpadm.jpg" width="299" height="190"></p>
<ul>
<li><font face="Arial, Helvetica, sans-serif" size="-1" color="#3333CC">
<b>
<font color="#333399">
<h:commandLink action='#{facesContext.externalContext.request.contextPath}/faces/success.jsp' value="Sign in"/>
</font></b></font>
<font face="Arial, Helvetica, sans-serif" size="-1">— if you have already successfully registered for site access.</font></li>
</ul>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<!-- start of footer.inc -->
<%@ include file="/includes/footer.inc" %>
<!-- start of footer.inc -->
</body>
</html>
</f:view>

BUT - whenever I try to access this page - I get the following ERROR:

javax.faces.el.ReferenceSyntaxException: #{facesContext.externalContext.request.contextPath}/gap/loginsuccess.jsp
at com.sun.faces.el.MethodBindingImpl.<init>(MethodBindingImpl.java:77)
at com.sun.faces.application.ApplicationImpl.createMethodBinding(ApplicationImpl.java:281)
at com.sun.faces.taglib.html_basic.CommandLinkTag.setProperties(CommandLinkTag.java:220)
at javax.faces.webapp.UIComponentTag.createComponent(UIComponentTag.java:1027)
at javax.faces.webapp.UIComponentTag.createChild(UIComponentTag.java:1046)
Truncated. see log file for complete stacktrace

I can't understand why - because I think the syntax is valid? Please help - any feedback would be greatly appreciated!!

Nena
Dave Salter
Ranch Hand

Joined: Jul 20, 2005
Posts: 292

How are you accessing the page? Are you going via the faces mapping or are you going directly to the jsp, e.g.

/faces/page.jsp or
/page.jsf
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15956
    
  19

Welcome to the JavaRanch, Nena!

The first thing you shouldn't have done is write your own login page. Spend time in this forum and you'll see one of my favorite topics to rail against are custom security systems. Because despite the fact that almost every J2EE book ever published has some sort of "login handler" demo in it, in the Real World, custom security systems aren't secure.

The second thing you shouldn't have done is to treat the JSF View definition like it's an old-style JSP with scriptlets. JSF views don't compile into servlets like "real" JSPs do - they're templates, and they shouldn't have logic in them. And, in the case of a commandLink tag, specifically, the commandLink action must be the name of a method in a JSF backing bean, not a URL.

I'm afraid, in fact, that there are so many dodgy practices in your sample that the best thing to do would be to stop coding, get a good introductory book on JSF, and do some serious reading. JSF is very different than other J2EE platforms and the traditional servler/jsp approach doesn't work.


Customer surveys are for companies who didn't pay proper attention to begin with.
nena tamari
Greenhorn

Joined: Sep 21, 2011
Posts: 8
Dave - Yes, I am using faces - ie, faces/success.jsp

And Tim, though your response is funny and you have some valid points, I am actually NOT posting a login page - this is just a welcome page that attempts to access a "protected" resource. Please don't make assumptions based on a comment in the code.

Now - I agree, the page IS poorly formatted - I am not the original developer and I am just working on migrating this code to a higher version of JSTL/JSF/JDeveloper - so therein lies my problem - stuff like the code below doesn't work and I'm actually not accustomed to working with just JSF alone (Richfaces/MyFAces/IceFAces)....

I will try your suggestion by replacing with just an <a href .... > tag and use the EL notation in there to see if it works - however, in my Core JSF book, apparently the "facesContext" should be available - it's a predefined object in EL.

Thanks for your input - if you have any other suggestions please feel free to comment.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15956
    
  19

Don't take it personally. I practically have this diatribe wired up to a macro key, since certain offences are so common.

Helping people with JSF carries certain unusual characteristics. People want to do it the way they did older technologies, people want it to be more complicated than it has to be, and - just to make things worse, a lot of stale documentation is still floating around from before JSF got cleaned up enough for everyday use and people use it in ways that are no longer really appropriate.

DIY security systems, however, offend me no matter what the platform, since J2EE is a very expensive technology. Cheap security may be fine for cheap tech, but if we're going to justify our higher costs, we have a certain obligation. So I tend to be touchy about that. Besides, the link DID say "sign in", and that usually means that it's leading to a DIY login screen, not a container-protected URL.

BTW, you can use the "Code" button on our message editor to wrap java code, XML, and other structured text and make it easier to read. I'm afraid that even so, long examples can be hard to read properly on-screen, but it helps.

That commandLink was all wrong from the get-go, though. Firstly, because it should have been referencing a backing bean action method, but even so, commandLinks already know the application context, so they don't need to go rummaging around in JSF internal objects to get it. Like I said, people want JSF to be more complicated than it really is. I've never referenced the FacesContext on a View definition, ever, and I've been working with JSF since before the standard was formally defined.

I had to look twice to see if the sample was even truly JSF, though. It's loaded with raw HTML, which in most cases could have been done simpler using JSF elements. I don't see an "h:form" element, which is mandatory for use of the h:commandLink element, since commandLink is a FORM control, not a hyperlink in the pure HTML (<a href=>) sense.

I wrote some pretty nasty stuff myself when I first started with JSF, so I'm not going to fault this kind of stuff TOO much. However, things can be done better now, and that's what we're here to help with.
nena tamari
Greenhorn

Joined: Sep 21, 2011
Posts: 8
Hi Tim,

Well the issue here is: the application is "auto-deployed" to JDev's integrated weblogic server - which automatically generates a context path when it does this type of deployment. This automatically generated context path will not match the context path of the application once I'm done developing ant build/deploy scripts - but for now, I just want it to compile and run successfully in the integrated server.

The issue, then - to re-iterate is that: if I use the following:

- this doesn't automatically put the context path in before the /faces/....

Conversely, this:



Throws the ReferenceSyntaxException - there are times when either request.contextPath OR (similarly) facesContext.externalContext.request.contextPath - might be needed to access a resource outside of the JSF container (for example) - can anyone tell me WHY the commandLink doesn't work?

Thanks in advance....
nena tamari
Greenhorn

Joined: Sep 21, 2011
Posts: 8
Update:

I was able to get my link working properly by using the following instead of h:commandLink



And now it works - thanks for all your tips....

Now I have a separate issue - which Tim touched on - what is industry accepted practice as far as JSF page formatting goes? OK to mix HTML with JSF/EL/JSTL?
 
 
subject: JSF with EL notation throwing ReferenceSyntaxException PLEASE HELP
 
Similar Threads
Problem with encoding type in the browser
logic:forward problem
Internationalization login thru to...
INCLUDES.DBconnection error
400,000 have downloaded the Army Game