aspose file tools*
The moose likes JSF and the fly likes jstl c:if problem  - surely this is impossible? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "jstl c:if problem  - surely this is impossible?" Watch "jstl c:if problem  - surely this is impossible?" New topic
Author

jstl c:if problem - surely this is impossible?

Brendan Healey
Ranch Hand

Joined: May 12, 2009
Posts: 218
After a year working with JSF I did not expect to be encountering problems like this - but then I don't
use jstl much so perhaps I'm just missing the blindingly obvious!

I can run this code with the backing bean property teamCreateView.countryIsSet set to true and get
the output:

true Output 2 Output 4 true

When I run is with teamCreateView.countryIsSet set to false, I get the output:

false Output 2 Output 4 false





Can anyone shed any light on what I'm doing wrong here, or is time to run CPU diagnostics?

Thanks,
Brendan.
Brendan Healey
Ranch Hand

Joined: May 12, 2009
Posts: 218
It seems that JSTL doesn't work with view scoped beans. Although I tried it with a request scoped bean
and this didn't work either. Have to use rendered= blah blah blah. Another JSF productivity nightmare.
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
I don't understand. Why not put the "application" logic in your backing bean. You don't need JSTL for that.


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Brendan Healey
Ranch Hand

Joined: May 12, 2009
Posts: 218

All I was trying to do was set focus to a particular input field depending upon whether or not
a certain field could be defaulted or not. The only way to do this with the component I was using
was either with c:if or using the rendered attribute.

You should be able to use JSTL or not. The Core JSF book and JSF 2 complete reference all refer
to using JSTL (and the authors are on the expert group) as does the Java EE 6 tutorial. I mean,
can you use it or not? end of story.
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
I've done some reading and seen some examples that you could combine them. I personally don't have any experience with that and I don't believe it's practical, but that's my opinion you could have a different one. So maybe someone else is able to help you with combining the two.

Your problem with the focus I mostly solve this with javascript, because I consider this a client problem and not a problem of the server.

You could also try s:focus.

It worked for me.

Good luck.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

Brendan Healey wrote:
You should be able to use JSTL or not. The Core JSF book and JSF 2 complete reference all refer
to using JSTL (and the authors are on the expert group) as does the Java EE 6 tutorial. I mean,
can you use it or not? end of story.


I don't have copies of these works myself, but I do know that darn near every J2EE book out there should how to write a "login system" in J2EE despite the fact that user-defined security systems are a total nightmare (pet peeve of mine). So just because it's in a book doesn't mean you should do it.

Given a choice between JSTL and an equivalent JSF solution, go with the JSF one. The 2 products come from 2 different places, and the integration across products is never going to be as tight as integration between products.

To tell the truth, I've been working with JSF since 1986 on more projects than I can count (some of them quite ambitious) and have never found a single case where JSTL was necessary.


Customer surveys are for companies who didn't pay proper attention to begin with.
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
Tim,

I agree with you. There is a difference between possible and practical.

So I helped him with some options within JSF.

1986. I thought that JSF framework was a bit younger.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

Remko Strating wrote:

1986. I thought that JSF framework was a bit younger.



I keep doing that. I don't know why, unless it's because that's the year I started selling C++.

Would you believe 2006?
Brendan Healey
Ranch Hand

Joined: May 12, 2009
Posts: 218
When I finally realised that this code doesn't work I fixed the problem in 2 minutes using the
p:focus primefaces method which much to my surprise does have a rendered attribute.

The problem was that I frankly found it totally and utterly astonishing that you could have a
few lines of code where the value of a backing bean property is written out to the screen,
then tested using an apparently supported taglib function and the results are inconsistent.

My reaction was to assume that I must have been doing something wrong and this led to 5-6
hours of messing about rather than achieving the goals that I had set for myself for the day.
This is not an isolated incident. The imense fragility and the pitfalls of working with JSF
continue to amaze me.

The people writing the specs for this need to be put on hold until the developers can make
this stuff work properly. There are far too many authors out there writing hello world
applications, the minute you start to do anything serious it all starts going wrong.

Regards,
Brendan.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

One of the reasons why JSTL and JSF intermix poorly is that JSTL was designed for JSP-style processing. A JSP is converted line-by-line into a servlet and the servlet is executed at need, line-by-line (with a few diversions).

JSF on the other hand uses "JSPs" as View Templates. A Servlet is logic. a Template is not. The template is compiled into a hierarchical data structure and the nodes of that structure are processed by the Controller. It's a 2-dimensional process as opposed to the one-dimensional approach of a servlet/JSP. So expectations of linear behavior on JSPs may not always be met.

JSF 1.0 was even worse. When you mixed HTML tags with JSF tags, the HTML didn't compile into proper JSF nodes and they'd pop out in all the wrong places. You had to use the "f:verbatim" tag to wrap them.
Brendan Healey
Ranch Hand

Joined: May 12, 2009
Posts: 218

Thanks for the explanation, it's good to hear that things have improved. I have read a little
about the history and can see how JSF is a step forwards on the MVC front.
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
Tim,

Would you believe 2006?


I believe 2006. I just started then following javaranch and I believe I saw your name already in the JSF forum :-)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: jstl c:if problem - surely this is impossible?