• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

<h:commandLink> is not working in JSF 2.0

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am migrating my application from JSF 1.2 to JSF 2.0 where in I have the following scenario in my JSF application where I am using <h:commandLink> to provide the step by step registration which is not working properly.


I have mainRegistration.xhtml file which includes either step1.xhtml or step2.xhtml or step3.xhtml based on some if condition, each of these 3 xhtmls have one form and one <h:commandLink> tag which calls respective action method (continueStep1(),continueStep2(),continueStep3()) in the same mangedbean which is a request scoped when we click on the command Link.

My problem is : when I request mainRegistration.xhtml for the first time, it includes step1.xhtml which renders a form with commandLink, after filling up the form and click on the link it calls continueStep1 method in the bean and sends the response back to the same page (mainRegistration.xhtml) this time it includes the step2.xhtml which renders a form with commandLink till this point it is fine.

But After filling up the form and click on the link it doesn't call any method but constructor only instead of calling continueStep2 method in the bean and sends the response back to the same page (mainRegistration.xhtml) becuase of this it includes step1.xhtml again instead of including step3.xhtml. I am not sure why it is not calling the method, it is just ending after constructor execution. it was perfectly working with JSF 1.2.

Thanks in advance....

My bean must be request scoped, because there are several issues in changing it into session scope. The same scenario is perfectly working with JSF 1.2
 
Pawan Komaram
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

is there anyone who knows anything about this?

Thanks
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure your component is inside <form>.
 
Saloon Keeper
Posts: 28494
210
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
Also, request scope objects are completely destroyed between requests. So you cannot use them as conversational objects. If full Session scope isn't desirable and you're using JSF2, consider using View scope.
 
Pawan Komaram
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ViewScope is also not desirable because my object is very complex and it has got several class level variables and the ViewScope requires all of these should have implemented Serializable. I am not going to maintain any state of managed bean, I just wanted to call an action method, thats it.

All my commandLinks are inside form only......whenever it goes to second level same page is being rendered instead of calling an action method and render different view.
 
Pawan Komaram
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is the same behaviour even when I use<h:commandLink> for navigation. From initial page (first loaded page), it is going to any of the pages that are included in it without any problem, but from that page it is not going to any other page, it is not atleast calling the manged bean method, it is just re-loading the same page.

Overall it seems that - In JSF2, whenever I use same manged bean for all of my links(<h:commandLink>) and calling different methods for each link and my manged bean is in request scope then there is a problem with <h:commandLink>. is there any work around for this? As I already mentioned, I cannot make my manged bean to session and view scope because of its complecity. If make it to any of these scopes then it is working perfectly.
 
Tim Holloway
Saloon Keeper
Posts: 28494
210
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
In my experience, I usually end up regretting class-level variables except in the case of singleton classes. And occasionally even then.

You can use View scope without complaint from the server providing that you give the non-serializable attributes the "transient" attribute. Although it then becomes your job to ensure that these attributes are re-created at need. Just as you would in Request scope, actually, except that you have to be more mindful of it.

When an action method does not fire that means that something has caused the action phase of the JSF lifecycle to be bypassed. Most commonly that's because one or more controls in the form containing the command control contain invalid values. In cases where you don't care what the form control values are, you can use the "immediate" attribute on the commandLink/commandButton to cause the validation and update phases to be bypassed and thereby have the action method fired regardless of the validity of the form data.
 
Pawan Komaram
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is very difficult to give transient for all those variables at class level. It is not written from scratch, it is the existing class and there are so many classes like this. As I said, it is migration project from JSF 1.2 to 2.0. It have tried even using "immediate" but it doesn't help. It must be a common problem which must be encountered by so many JSF developers, but I could not find any resolution for it over the google. I am providing the code here for better understanding.

When I request maintestpage.jsf first time, it includes the testpage1.xhtml and displays the commandlink in it along with the content, when I click on that link, it calls method1 in TestBean class and returns the view id as maintestpage, this time it includes the testpage2.xhtml and displays commandlink in it alongwith content in it, when I click on that link, it is not calling method2 in TestBean, just reloading the mainttestpage.xhtml, because of this it is again including the testpage1.xhtml instead of tetpage3.xhtml.

maintespage.xhtml

testpage1.xhtml

testpage2.xhtml


testpage3.xhtml

TestBean.java

 
Pawan Komaram
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


Any resolution? Did anyone encounter the same problem with JSF 2.0?


Thanks,
Deva
 
Space pants. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic