File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes <h:commandLink> is not working in JSF 2.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "<h:commandLink> is not working in JSF 2.0" Watch "<h:commandLink> is not working in JSF 2.0" New topic
Author

<h:commandLink> is not working in JSF 2.0

Pawan Komaram
Ranch Hand

Joined: Dec 08, 2009
Posts: 91
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

Joined: Dec 08, 2009
Posts: 91
Hi,

is there anyone who knows anything about this?

Thanks
Bharat Kasodariya
Ranch Hand

Joined: Aug 19, 2011
Posts: 36
Make sure your component is inside <form>.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16065
    
  21

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.


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

Joined: Dec 08, 2009
Posts: 91
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

Joined: Dec 08, 2009
Posts: 91
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

Joined: Jun 25, 2001
Posts: 16065
    
  21

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

Joined: Dec 08, 2009
Posts: 91
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

Joined: Dec 08, 2009
Posts: 91
Hi,


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


Thanks,
Deva
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: <h:commandLink> is not working in JSF 2.0