*
The moose likes JSF and the fly likes Why does not command button calls action listener? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Why does not command button calls action listener?" Watch "Why does not command button calls action listener?" New topic
Author

Why does not command button calls action listener?

Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Hello again!

I have embedded prettyfaces recently into my webapp and now I have really strange behaviour.
I have register form and command link within it:
<h:commandLink id="registerButton" class="registerButton" value="Register" type="submit" action="#{registerBacking.create}" />

Neither command link nor command button invokes action method which is registerBacking.create.
My registerBacking View-Scoped bean is created only when using page is loaded.
When I click this link I simply reload the page and registerBacking is created again, no validation and conversion error arises although there are many errors.
And this link and button is placed within h:form.
To prevent view-scoped bean to be recreated al time I set this in web.xml:




True person is moral, false is right!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

Try setting the onPostBack option to false. You shouldn't have to hack web.xml.


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

Joined: Mar 29, 2012
Posts: 505
    
    1

Hello Tim!

Unfortunately onPostback="false" does not make any difference. However if I remove mapping from pretty-config.xml all is working well as before
My mapping is simple

PrettyFaces documentation says that we should use onPostback="false" but not onPosBack="false". I tried both and they didn't work!
What is wrong here?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

You are specifying a resource path (.xhtml) for the view-id. The view-id should be a URI, just like in the faces-config,xml. Try "/register.jsf", instead.
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Hello Tim!

Bad news!

I have replaced FacesServlet maping to .jsf in web.xml and changed pretty faces mapping to:

Unfortunately it didn't make any difference! My action method is not called anyway!

Do you have another ideas?
By the way before embedding prettyfaces this was working well.

If I intentionally type wrong data I receive this notification from browser:
httpError: Http Transport returns a 0 transport code. This is usually the result of mixing ajax and full requests. This is usually undesired both for performance and data integrity reasons!

Thank you!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

I am very confused.

There are only 3 ways I can think of that prevent the action method from being invoked, and they are independent of prettyfaces.

1. If you have an improper rendering of the View containing the commandLink/Button. This can be diagnosed by using your browser's "View Page Source" feature. If the original "h:commandLink" is in the displayed source, the page wasn't rendered properly.

2. If the commandLink isn't part of a JSF form, it won't work. You must have it contained within a form.

3. If the commandLink is part of a form containing invalid control values, the JSF validation services will reject the action and bypass the action method.

To avoid case 3, add an "immediate="true"" attribute to your commandLink. That will keep the invalid control values from being submitted.
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Thank you for replies !!!

I have made sure that the problem is just in this mapping in pretty-config:


I commented out this mapping and my button is working as needed. My form is submitted and new user is created and it is stored in db.
But if I paste this mapping back into pretty-config.xml I have no response to clicking the same button from the same form.
You advised me to move to .jsf mapping for FacesServlet. Very interesting is that this caused my action method NOT to be invoked even if I removed that
cursed mapping from pretty-config.xml.
I am sure the problem is above mapping.

By the way I thought that this causes problems:

I deliberetely removed it and it didn't make any difference for button. It invokes action method when there is no that mapping in pretty-config.xml.
I keep javax.faces.FULL_STATE_SAVING_VIEW_IDS in order to prevent view scoped bean to be recreated all the time while I am filling the form.
And it works!

I posted this issue on ocpsoft/support and I still don't have reply!
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Thank you for replies!

httpError: Http Transport returns a 0 transport code. This is usually the result of mixing ajax and full requests. This is usually undesired both for performance and data integrity reasons!

This was happenning just because my ajax request was sent together with full request as I clicked submit button.
The same problem is very well described here http://weblogs.java.net/blog/driscoll/archive/2009/10/01/mixing-ajax-and-full-requests-jsf-20

As soon as I changed command button to
<h:commandButton id="registerButton" class="registerButton" value="Register" type="submit" action="#{registerBacking.create}">
<f:ajax render="@form" />
</h:commandButton>
All problems have gone away!
And now regardless of pretty-config mapping I am redirected to needed page and new user is persisted into database!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why does not command button calls action listener?
 
Similar Threads
Problem render whit trinidad
stylesheet messed up in richfaces JSF page
Managed beans aren't constructed running on JBoss 5.1.0 (works fine with Tomcat 6)
cant deploy my application,please help
JavaEE embedded security fails when using PrettyFaces.