permaculture playing cards*
The moose likes JSF and the fly likes Multiple Actions issue in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Multiple Actions issue in JSF" Watch "Multiple Actions issue in JSF" New topic
Author

Multiple Actions issue in JSF

Anil Vupputuri
Ranch Hand

Joined: Oct 31, 2000
Posts: 527
Hi,

Observed Multiple Action issue in JSF page,

1. I have a h:commandLink (called "fileAttachmentLink") in my JSF page (approveFiles.jsp)
2. if I click the commandlink it will download a PDF file and display the prompt to open or save. Everything works fine until this point.
3. Now if I go to my JSF page (approveFiles.jsp) and try to do other action (clicking on "rejectButton" button), the corresponding onclick event is triggered (opening new pop-up window) and when the submit button in pop-up page is clicked (onclick event "checkRejectReason()" is called), it again shows up the save/open prompt again (triggers {approveFilesBean.getFileAttachmentContent} again).

I could not understand what the problem is. Could you please find out the issue. Thanks.

Following is partial approveFiles.jsp (Main page)




Following is rejectPopUp.jsp (Pop-up window page, triggered from above page)



SCJP 1.5, SCEA, ICED (287,484,486)
Bart Kummel
author
Ranch Hand

Joined: Nov 30, 2007
Posts: 81
Hi Anil,

It is hard to determine what the problem is. Some things are missing:
1. You didn't tell exactly what you want to happen and why the current behavior is wrong.
2. You didn't provide any details about your beans.
If you want people to help you solving this problem, the best thing to do is to create a really small example application that just reproduces your problem and ask someone to look at it.

However, I doubt if you should want to solve this problem. What I see in your code is that you are doing a lot of work yourself. You are writing JavaScript to create popups and to do some sort of validation. And you write your own HTML tags. The main idea behind a component based framework such as JSF is to let the components do the hard work for you. That way you as a Java EE developer don't have to know all sorts of details about client side view technologies such as HTML, CSS and JavaScript.

That said, the standard JSF components are bare bones. They're just provided as a starting point. JSF was designed with the idea in mind that third parties could create more versatile component sets, and that idea seems to work pretty well, given the large amount of commercial and open source JSF component sets available nowadays. So whenever you encounter a UI specification, you shouldn't ask yourself what HTML, JavaScript and CSS is needed to realize it. Instead you should start looking for one or more JSF components that implement the needed functionality.

So, how can we implement your popup without the need to write HTML and JavaScript? One possibility is to use Apache MyFaces Trinidad's dialog framework. The dialog framework gives you the opportunity to create popups without writing JavaScript or HTML code. You just use the right Trinidad components and create the right navigation cases. The dialog framework also offers easy to use solutions to return values from the dialog to the main page. The provided links point to some basic documentation. The dialog framework is also covered in the Advanced Trinidad chapter of the Apache MyFaces 1.2 Web Application Development book.

I hope this will help you to get the most out of JSF and MyFaces.

Best regards,
Bart


SCJP 1.4 | SCJD 1.6 | Visit my website | Author of the book Apache MyFaces 1.2 Web Application Development
Anil Vupputuri
Ranch Hand

Joined: Oct 31, 2000
Posts: 527
Thanks Bart for your detailed explanation, now I got an idea what can be used and what not w.r.t JSF. Actually we inherited this project to support so we can't do major refactoring overhaul to the existing codebase. And there is a new requirement to add a link to download the PDF (or anyother MS format) file, and this is the only change we are trying to make otherwise the code has been running fine (that includes pop-up window).So, only the new change made to the page is adding new CommandLink to download PDF file,



And corresponding method in Backing Bean is,



Sorry if I wasn't clear before. What I want to happen is, by clicking on Submit button on pop-up, it should trigger javascript method, "checkRejectReason()" and this method should do assign the value of TextArea (id=rejectReason) to hidden variable called rejectReason in approveFiles.jsp and then action, "#{approveFilesBean.reject}" should be called.
But what's happening now is the action, "#{approveFilesBean.getFileAttachmentContent}" is called again and again eventhough Submit button on pop-up pointing to "reject" method for action, it is not calling "#{approveFilesBean.reject}" at all.


So, let me see if we can fix the problem without introducing Trinidad framework.
Bart Kummel
author
Ranch Hand

Joined: Nov 30, 2007
Posts: 81
Hi Anil,

I had a look at your code snippets again. I see your #{approveFilesBean.reject} expression is inside a JavaScript function. I suppose your idea is to dynamically change the action of the form by JavaScript. However, this is not possible. JavaScript code is executed inside the browser, i.o.w. at the client side. JSF Expression Language (EL) only works at the client side. And since you are using JSP as view technology, EL only works in attributes of JSF components. I understand this might be a difficult concept, especially as HTML and JSF tags are mixed together in a single file. You should realize that JSF components get processed at the server side and are translated ("rendered" in JSF terms) into HTML tags at the server side. So the client side never gets to see the JSF tags nor the JSF EL expressions. To verify this, open a page of your application in your browser and do a "View page source" in the browser. You'll see only HTML (and JavaScript and CSS), but no JSF components.

So, how to solve this problem? There are multiple approaches. I guess the easiest is to rely on one single action method. In the action method, you can get the value of your hidden field and you can use a Java if statement to perform different actions, depending on the value. It is useful to know that an action method can return a String value that identifies the navigation case that should be executed. So you can navigate to different pages by returning different Strings.

I hope this helps you to get on the right track. If you still have questions, don't hesitate to ask them!

Best regards,
Bart
Anil Vupputuri
Ranch Hand

Joined: Oct 31, 2000
Posts: 527
Hi Bart,


I resolved this issue by seperating the actions into multiple forms in applicationForm.jsp, I don't know whether I hijacked the JSF lifecycle by introducing JavaScript but it worked.

Form #1,



Form #2,


Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Multiple Actions issue in JSF
 
Similar Threads
DataTable inside a DataTable
Component ID frm1_window viewid has already been found in the view
Problem with column sort in myFaces dataTable
radio button not working with panelgrid
EL Syntax exception - javax faces el ReferenceSyntaxException