aspose file tools*
The moose likes JSF and the fly likes How to access form data after submit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to access form data after submit" Watch "How to access form data after submit" New topic
Author

How to access form data after submit

Tommaso Tama
Greenhorn

Joined: Oct 13, 2010
Posts: 11
Hi to all,

I have a problem that I am not able to solve.

Well, let's suppose that we are invoking a method (in a backing bean) from a webpage (maybe jsp, xhtml, portlet ...) pressing a button.


The form is submitted with its values.

Let's also suppose that we will get a problem (Exception) during the action process.

I wrote (and registered) an ActionListener that will catch the Unhandled Exception (and that will do something to handle it):


It works great ... BUT ... I need to know data that are (was?) in the submitted form.

How can I get this information? I would like a generic method, since the error can happen everywhere in the application (I don't really know the clientId or other peculiar information about objects).

It's also ok to get ALL posted data and write them down in the database: I will analyze data later!!

Unfortunately, we're still at JSF 1.2.

Any ideas?

Many thanks! Tommaso
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

You're thinking in terms of the trees and losing sight of the forest. JSF isn't about HTML and J2EE tricks, it's a semi-abstract framework with its own set of rules.

Your "form" is in the backing bean properties that are referenced by input controls within that form.

If you're thinking about doing some sort of dissection of the raw HTML form submit itself, well, good luck, but JSF makes its own contributions to the submission.

Customer surveys are for companies who didn't pay proper attention to begin with.
Tommaso Tama
Greenhorn

Joined: Oct 13, 2010
Posts: 11
Dear Tim,

I know what you mean, I know what a framework is ... the problem is that I'm not experiences with jsf as well as struts, for example.

I have no fear of rules ... so, let's face them!

I do not want to dissect RAW html, it's not my intention: I wrote an extension of ActionListenerImpl class ...

My question is: how can I catch that damned form?

I can get the caller component using event.getComponent(), but from this point on, how can I catch and dump form data to my DB?

Many thanks for your help.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

The point is, JSF isn't about forms. It's a Model/View/Controller framework. The end result of a JSF request is supposed to be that a form is validated, the backing bean(s) are updated, then an action is taken on a backing bean that (usually) takes the updated bean(s) and does something with that data. The only real "form" aspect to it, is that the forms delimit what particular objects are affected when an action is fired.

So first of all, there's more than one type of error. If the data doesn't pass validation, then effectively speaking, it isn't captured at all. if there's a failure in the action processor, the action processor hopefully has a better idea of what to do about it than some external generic logic.

It's a very common failing for JSF beginners to start throwing around lots of calls to arcane JSF functions and constructs. JSF is designed on Alan Kay's principle of "Simple things should be simple and complex things should be possible". Meaning, that except for the JSF model classes, most JSF code should be POJO code. If you've got a complex solution there's a very good chance you're overlooking the simple ones.

Truthfully, it's not wise in any endeavor to try and use all the complex functions when you're not familiar with the basics. Not that I'm innocent on that count, but JSF really is a platform that's supposed to make solutions simple.
Tommaso Tama
Greenhorn

Joined: Oct 13, 2010
Posts: 11
Ok, I'm with you. I completly agree with you ... but ...

I worked for many years with struts, I know very well MVC ... so, maybe I'm in the wrong way now.

JSF is a simple (easy to use) framework you can make great things with.

I will explain my problem from another point of view, maybe you can give me a solution.
I have to trace user activity and in particular use input (legal stuff ... sorry cannot say more).

"Trace" means that I have to catch pages (it is easy), pressed button (easy) and user input. I'm not supposed to modify and bind each jsf object with a listener to save data when changed. So I thought I could create a "global" listener to do that dirty job for me.

Maybe I have to consider to create a super bean with a method that can dump the content of extended beans.

Tomorrow I will try and I will let you know.

Thanks again
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

I see. Well, I've worked in a number of high-security applications and auditability has often been an issue. Normally, however, what we worried about was who was trying to do what. If someone made a questionable move with the context of the application, typically I'd throw a specific exception that reported what the offense was and let the upstream processors log, alert, and/or fire off warheads as appropriate. It was less a concern what specifically they were trying to do as that they were doing it at all and the response was predicated based on the nature of the offense, rather than trying to make it generic.

If you really need to know byte-for-byte what was going on, you're probably actually better just logging the raw network traffic instead of trying to pick the guts of JSF apart (only to have it all break when they do their next architectural revision). That can be done either at the OS level using something the the tcpdump utility or inside the appserver. Tomcat's Valve mechanism is used for things like that.

Oh yeah, speaking of MVC, it's a bit hazardous to say "submit a page" in JSF, since unlike most web frameworks, the URL is a tracking handle more than it is an absolute page locator. Which has been an annoyance to many of us, but that's how it works. Also, you don't "call a method" from a View (notice I avoid the term "page"). You fire an action. JSF isn't like servlets and JSPs where the View is translated into code.
 
Don't get me started about those stupid light bulbs.
 
subject: How to access form data after submit