• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do i get this jsf page to work properly?  RSS feed

 
Victor Ade
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have multiple <p:panel/> which are bound to the same managed bean for a simple 'save inputted text from <p:editor/> to database. however, when I load my page to test if data would save to DB I realize only the first <p:panel/>  saves to database.  The other with id="basic2" wouldn't even trigger any action.

why is this?

could it be that I can't use a single managed  bean for multiple view component? 
 
I'm thinking of defining multiple instances of commentEntityController bean in faces-config.xml. would this be an appropriate solution my problem?

any suggestion would do please, thanks.





Here i have commentEntityController managed bean to work with the view:



 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I usually don't look too closely at examples that are too long to fit on my screen, but I'm pretty sure that what I saw was that each panel had its own form.

When you submit a form, you're submitting only that form. No data from any other form or any other place on the webpage is submitted. Also, forms cannot contain other forms (no form nesting).

This is not a JSF restriction, this is how HTML forms work. JSF merely inherited the behavior. It's actually useful in some cases - such as when there's a little corner of the screen with a "search" or "login" form separate from the main body form(s).

You could put the entire panel in a single form if you wanted to, though.
 
Victor Ade
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I do this?? I have over 6 forms on this page I'm working on and they are all for different purposes. I have a search bar primarily of  form.  Is there a chance there might be a way around this?
Tried you suggestion and removed form from both panel components but the behavior still continue. What should I do now?
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said, the restriction comes from HTML itself, not from Java or JSF. When you submit a form, EVERYTHING within that form is submitted and NOTHING outside of that form is submitted. And you cannot submit anything entered into input controls unless those controls are contained within a form.

That, in fact, is what a form is. It's not a display element, it's a logical container for all of the data that will be posted to the server in a single request. You simply cannot submit more than one form in a given request/response cycle. You'd have to re-invent the Web itself to do otherwise.

And backing beans are not Controllers. I don't care what Netbeans names them. Backing beans are always Models. In JSF, the Controllers are all built into JSF and you never code your own Controllers.
 
Victor Ade
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Controller not for http request to my webapp but for interaction between my facelet view and ejb and persistence. One of the fundedmentals you'd need to know as a new jsf developer isn't it? Thanks for pointing that out. However, I already have that in my pocket.
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The usual term for a persistence interface is "service". In my apps, the persistence services are a separate layer of classes. Depending on complexity, I either put business logic in action methods (which some people would condemn) or I have my backing beans invoke a business layer and that's what in turn invokes the persistence services.

"Controller" is usually used to mean that part of the Model/View/Controller subsystem that transfers changes in the Model to the View and changes to the View into the Model. The persistence services normally don't limit themselves to GUI (View) connections and they're usually one-way - changes to the database don't automatically reflect back up through the persistence services - you have to explicitly ask the service for them. At which time the persistence service will query the database.
 
Victor Ade
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:The usual term for a persistence interface is "service". In my apps, the persistence services are a separate layer of classes. Depending on complexity, I either put business logic in action methods (which some people would condemn) or I have my backing beans invoke a business layer and that's what in turn invokes the persistence services.

"Controller" is usually used to mean that part of the Model/View/Controller subsystem that transfers changes in the Model to the View and changes to the View into the Model. The persistence services normally don't limit themselves to GUI (View) connections and they're usually one-way - changes to the database don't automatically reflect back up through the persistence services - you have to explicitly ask the service for them. At which time the persistence service will query the database.





Few things I want to ask, tim, what exactly is business logic? I hear this often and I'm confused. I also want to beleive the business layer is ejb isn't it?
For a small app that just allow users comment, like, share et al  on some random content, what could the 'business logic' be?
Do most apps even have one?
I'm building what could be considered toy app by big guns like you but I must say I'm really cracked up.

I'm still battling with the issue behind this thread and I'd like to know if you can take a look at my facelet code and tell me why I'm still having this issue. Maybe point out some things im doing wrong. Its a personal project so no big deal. If you wish I'll send them to you directly. If you wish.
 
Victor Ade
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Victor Ade wrote:I have multiple <p:panel/> which are bound to the same managed bean for a simple 'save inputted text from <p:editor/> to database. however, when I load my page to test if data would save to DB I realize only the first <p:panel/>  saves to database.  The other with id="basic2" wouldn't even trigger any action.

why is this?

could it be that I can't use a single managed  bean for multiple view component? 
 
I'm thinking of defining multiple instances of commentEntityController bean in faces-config.xml. would this be an appropriate solution my problem?

any suggestion would do please, thanks.





Here i have commentEntityController managed bean to work with the view:





Done with this one.
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Business logic" is the term that's applied to mean computational work as opposed to simply reading and writing to GUIs, databases, or talking to services like message queues or email.

Business logic validates data, assembles it into bundles that might be transferred to some other stage, computes things like totals, averages, and so forth and just does the "thinking" part of the system.

While there are apps and parts of apps which do nothing more than bring data up for editing/display and then write it back (CRUD), many systems are more complex. That's what the business logic is for.

You seem to have quoted your original question and I can only give you my original answer. Your problem is not in Java and it's not in JSF. It's in the World Wide Web itself.

No matter how many or few JSF backing beans you have, a form can only submit data that's within that form. If you want to submit data from multiple forms on a page, that's going to require multiple submits, because only one form can be submitted per request/response cycle. Otherwise, you'll have to expand things so that everything's on one form.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!