• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Still struggling to get started with JSF.

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Been working with it on and off for a couple months now. No problem doing "reporting" type apps, but just can't seem to get any actions to fire so I can do interactive apps. I've followed some of the examples and it seems very straightforward, but when I do it myself I can't get anything to happen when buttons are clicked. It appears that my code is never called. Are there some common rookie action mistakes I should be checking into?
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I am a rookie, too

what are the scope of your bean?

do you have immediate="true" attribute in your button?
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you misspell or mis-capitalize the name of an action method, it won't be called and you won't see any error messages about it.

Likewise, if the action method's signature isn't "public String xxxxx()" - where "xxxxx" is the method name used on the JSF view, it won't be called and you won't see any error messages about it.

Finally, if there are validation errors for fields on the form, the lifecycle processor won't fire off the "do action" phase, since not only is the action bypassed, but also so is bean updating.. You'll see error messages, but ONLY if you code a message display tag on that view. It's a good idea to place an "<h:messages/>" on the page just to make sure you see all the messages.
 
Brian Knoblauch
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Davie Lin wrote:Yes, I am a rookie, too

what are the scope of your bean?

do you have immediate="true" attribute in your button?



Bean scope is currently set as request. Have tried other options in the past with no change.

Have tried with and without immediate="true" attribute, no change.
 
Brian Knoblauch
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:If you misspell or mis-capitalize the name of an action method, it won't be called and you won't see any error messages about it.

Likewise, if the action method's signature isn't "public String xxxxx()" - where "xxxxx" is the method name used on the JSF view, it won't be called and you won't see any error messages about it.

Finally, if there are validation errors for fields on the form, the lifecycle processor won't fire off the "do action" phase, since not only is the action bypassed, but also so is bean updating.. You'll see error messages, but ONLY if you code a message display tag on that view. It's a good idea to place an "<h:messages/>" on the page just to make sure you see all the messages.



OK, it is a public String () method. Spelling/caps are the same. Added the messages tag to the page now, nothing new showing up.

Really lost here. I look at samples online and I'm doing exactly the same thing, but with a different bean name and it just doesn't seem to work. Obviously missing something picky somewhere. My guess is that it's some config option in some XML file somewhere.

Tangential rant: The online tutorials I've found so far really aren't very helpful at all. Books marginally more helpful. There seems to be an assumption that people doing JSF are hardcore HTML/XML developers who have never seen Java before. Unfortunately, I have a lot more current Java experience than HTML (been doing Java for the last few years, but haven't done web stuff since we used CGI interfaces to C code (1998 or so?)). So, I get bored reading everything I already know about Java, and they never cover any of the HTML/XML stuff that I'm NOT current on!
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I can see where that might be a problem. JSF was designed to cut down on the Java code required and allow more declarative programming, such as in the page view. In fact, a big problem is that a lot of people seem to feel upset that JSF doesn't require more Java programming, so they use a lot of low-level grungy stuff that they really shouldn't so that they can do in code what can often be done much simpler using view tags and simple functions such as basic action processors.

Did you define the backing bean containing the action method in faces-config.xml? If the bean isn't locatable by the EL processor, the action method won't be fired, and there won't be an error.

You can post snippets of your View and backing bean for us to examine. Just use the "code" button so that the formatting will be preserved.
 
Brian Knoblauch
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:
Did you define the backing bean containing the action method in faces-config.xml? If the bean isn't locatable by the EL processor, the action method won't be fired, and there won't be an error.

You can post snippets of your View and backing bean for us to examine. Just use the "code" button so that the formatting will be preserved.



Backing bean is defined in faces-config.xml. I'm successfully driving a datatable off of it.

I made a new project as simple as possible that duplicates the issue (but does not have the datatable, so could *potentially* have an additional error that the main project does not have, since I don't have anything pulling from the bean :-) ). Using a simple print that should go into the glassfish logs to check for the button press here. Tested that on my other project during the datatable load, so I know where sout goes:

index.xhtml


MyBean.java


faces-config.xml
 
Brian Knoblauch
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, since I'm using JSF 2.0, how could I use annotations instead of the faces config file? I've been googling trying to figure out what the annotations are, but I haven't found anything useful yet.
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
change your entry in faces like



and in your xhtml
 
Brian Knoblauch
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nitin pokhriyal wrote:change your entry in faces like
...



Still doesn't work. :-(
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've long advised people not to start bean names with uppercase letters. When you use JSF2 and annotations, that becomes even more important, because the "@ManagedBean" annotation catalogs the object under a name which is the same as that bean's classname, except that the first letter of that name will be folded to lower case, unless you explicitly override it.

Basically, what we're saying is that upper/lower case is critical in JSF, just as it is for Java object in general, so do make sure everything's being defined and referenced properly.
 
Brian Knoblauch
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:
Basically, what we're saying is that upper/lower case is critical in JSF, just as it is for Java object in general, so do make sure everything's being defined and referenced properly.



In my large app at least, I believe that it's referenced properly as my getters (that display the datatable) work just fine from the same bean. Yet, for some reason, actions fail to fire. :-( I just threw together that sample to demonstrate the issue in as simple a manner as possible.

Any more ideas I can look into?
 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you post your web.xml also.
 
Brian Knoblauch
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nitin pokhriyal wrote:can you post your web.xml also.



 
Brian Knoblauch
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my real project, the capitalization, etc all match up fine (and I can read from the bean, just can't fire events). Played with that in the sample I posted and it also doesn't fire events. So, if there's nothing else obviously wrong that jumps out at anyone here...

Can someone share some easy sample code on a working button & action, so I can have something "known good" to test with?

Thanks,
Brian
 
Brian Knoblauch
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it. Didn't realize I needed to wrap commandButtons inside a form element... :-)

Also, thanks for the tips on capitalization, etc. The next thing I did was switch from XML to annotations in my real project and that broke things due to the automatic lower caseing...

There's a ton of voodoo that goes on, hidden behind the scenes, in JSF. It's like you put in one thing and 12 different unexpected side effects happen too. Taking awhile to catalog all that, so I know what to do, and what NOT to do in order to get my desired effect!
 
I am not a spy. Definitely. Definitely not a spy. Not me. No way. But this tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic