• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can a JSP Have More Than One jsp:useBean Tag?

 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can a JSP have more than one <jsp:useBean> tag? In other words, can I use more than one Bean in a JSP? With one HTML Form, you don�t even need an �ACTION=� attribute since the bean in the <jsp:useBean> will be automatically used and its �setter� methods called for every <INPUT> element present in the Form.
Suppose I have two HTML Forms in the JSP. Can I associate one Form with one bean (<jsp:useBean> tag) and another Form with another bean tag? How? It may not be allowed (at least in JSP 1.0).
No one at work knows and Sun�s documentation doesn�t say. The only thing that it does say in its JSP tutorial is that �ACTION=� can point to ANOTHER JSP. That�s one (indirect) way of doing the multi-form �thing� that I ask� Maybe.
In the meantime I may write some code to try�
 
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
The problem you will have with 2 forms on a page with each form being associated with a bean is that each page must be 'submitted' to itself for the bean's setter methods to be processed. There isn't any way to submit two forms with a single button click. So if you click on submit 1 (that is defined in form 1) then only the name/value pairs from that form are sent along the 'queryString for GET / body stream for POST' the other form will never be processed, so, the associated setter methods will never be 'fired' off.
You can also associate more than one bean in a a JSP. One could be to repreent the form (and hence use the "*" getParameter tag to get all info from the form) and the other could be a custom 'bean' you made for your database or something like that.
Hope this helps.
 
Tony Alicea
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I experimented today and found out that I can use as many useBean tags (with "*" for the setProperty tag), and every one of those beans that has a setter method for the NAME attributes of the INPUT tag will be called with the value in the VALUE attribute of the INPUT field of the FORM.
And if you want the page to "remember" what happened in the previous FORM submission, one has to use
scope="session" in the useBean tag.
 
John Bateman
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Okay I want to clarify.
If I have two diffrent forms that call the same servlet. You are telling me that the bean will populate (call setter methods) and set the fields to the value passed from the form?
I would have to say that this would kick a$$.
Just today I was trying to process multiple forms on a page with one ASP and only the form that is passed by the submit buttom pressed is sent.
If Servlets can handle this it would be Darn cool!
Thanks for the info.
 
Tony Alicea
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don�t know ASP (nor have any interest; we are a Sun �IBM Java shop) but with JSP, if you have different beans defined at the top of the page with the useBean tag, then when you submit a form, all the names that match setter methods in ANY and all beans, will get set to whatever the VALUE is.
And if one bean does NOT have one property in the FORM but has another, it will just set this last one and will not complain about the others it doesn�t know about.
 
reply
    Bookmark Topic Watch Topic
  • New Topic