Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Strange behavior switching from JSF to JSP2 EL  RSS feed

 
Prakita tarun
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am learning JSF and was trying to implement a small exercise on EL (with JSF page and JSP2). i found a strange behavior and completely clueless of the reason behind it. Please find my code below and scenario

MY JSP file



The above JSP file is giving the below output on IE

Accessing Bean Properties: JSP2_1 result
First Name
Second Name
ThirdName Name




Accessing Bean Properties
red
green
white
black
First Name = Tarun
Second Name = kumar
last Name =




Accessing Bean Properties: JSP2_2
red
green
white
black
First Name Tarun
Second Name kumar
ThirdName Name

Why is there a difference in output between Accessing Bean Properties: JSP2_1 & Accessing Bean Properties: JSP2_2 when the code written is the same. My Controller bean class below


 
Tim Holloway
Bartender
Posts: 18660
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Prakita!

There is a "Code" button on our message editor. You can use it to wrap sample Java code and XML so that the samples will not be visually distorted and made hard to read.

I notice a couple of things that you should look at.

The most important one is that in JSF2, there is no longer support for "JSP" view templating. In JSF2, only the xhtml form is recognized.

The second one is that (because JSF2 is not JSP-based), you should not attempt to use "snippets" on JSF View Templates. Plus, although Oracle examples would make you believe otherwise, mixing JSTL and JSF is not a good idea. View Templates define a 2-dimensional page rendering template, not a linear sequence of code the way that traditional JSPs did.

It's worth noting that JEE EL has 2 separate expression forms. The "$" form denotes an expression that is display-only. The "#" form indicates that the expression may be a method or propery reference (read/write). The "#" form essentially acts as a superset of the "$" form.

Finally, you do not write Controller code in JSF. All of the Controller logic is pre-written into the FacesServlet and the tag implementations. Backing beans are not Controllers, they are Models. Action methods are not Controller methods - they are external tie-ins to MVC, not part of the MVC paradigm itself.

Personally, I don't recommend putting raw HTML onto a View Template if you can avoid it. JSF has native constructs that can do the job better and in a more media-independent manner. For example, the h:panelGrid is analogous to the HTML TABLE and the h:dataTable can render a 2-dimensional row/column display with automatic row iteration.

I'd like to answer your actual question, but there's more code in it than I can easily read on-screen. Let me reformat it and see if that helps.

 
Tim Holloway
Bartender
Posts: 18660
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. I reformatted it.

At a rough guess, I'd say it's because the first example used "$" notation and that the "$" EL processor didn't cause the Managed Bean mechanism to trigger and create the backing bean on-demand the way "#" notation does.

It's best if you can reduce your examples to the minimum amount needed to display the problem. First, because we don't get paid for doing this, so we're not generally going to spend much time decoding stuff. Secondly because everyone wants computer terminals to be HDTV screens these days, and that means that my newer screen has more horizontal space and less vertical space than what I liked to have.
 
Prakita tarun
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:OK. I reformatted it.

At a rough guess, I'd say it's because the first example used "$" notation and that the "$" EL processor didn't cause the Managed Bean mechanism to trigger and create the backing bean on-demand the way "#" notation does.



I would start off by apologizing for explaining my query in an unprofessional way. New to forums, hence took some time in understanding the protocols. I have below summarized my query with a simpler example.

Backing bean class


Below is the snapshot of faces config xml which is required for this example
Faces config.xml



[b]JSP Code[b]


The output is as below:
{
Accessing Bean Properties using JSP 2 EL: version 1
First Name

Accessing Bean Properties using JSF 1.1 EL
First Name = Tarun

Accessing Bean Properties using JSF 1.1 with JSP2EL: version 2
First Name Tarun

}

With this the background below are my questions

Q1: I am trying to fetch a string from the backing bean using JSF 1 El and JSP 2 EL. I am trying to fetch the name using three expressions. First and 3rd one are JSP2 EL and the funny thing is that the first one is not able to fetch the name where as the third one (with the exactly same syntax is able to fetch the name. Using the SOP, I am getting the that first expression is unable to trigger the backing bean whereas the second and third one are doing it successfully. Why is such a scenario happening? Looking forward for your explanation.

Regards Tarun



 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!