Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

How to use JSF like ASP.NET?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to JSF but I have worked a lot with ASP.NET and would like to ask a very simple question:

Is there a way to simulate or use a technology, which works like ascx files in.NET. I do not mean just including one JSP in another JSP, I mean the full functionality of ASCX + event handling model.

Actually I would like to achive something like this:

A WebPage (the main container) consists of 3 sub pages (ASCX in .NET): Header, Main and Footer. When I click on commandButton in the Header I would like to fire an event, which should be catched by the WebPage (the container). then I would like somehow to tell the Footer page (I do not hink it should go with event here) to change something in the footer.

In ASP.NET Terms I will have something like this:

WebPage.aspx which contains one Header.ascx, one Main.ascx and one Footer.ascx.

When I press the button in Header.ascx it triggers an event (through the delegate model in .NET) and the WebPage.aspx instance will be notified. Then I just have to access the Footer.ascx instance from the WebPage.aspx instance and voilla.

So, can anybody help me to achieve the same goal using JSF?
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it is doable. You have 3 pages right? main.jsp, header.jsp. footer.jsp. For each of this page, you can have three backing beans, which are similar to the code behind files in asp.net. These 3 beans control the behavior of the three pages. And by default, the beans are stored in the request scope. Every time the main.jsp(including the footer and header) is accessed, an instance of each of these three beans is created and stored in the request scope, ready serving that request. When you want to change the behavior of the footer when a button on main.jsp is clicked, just get the bean corresponding to your footer.jsp,namely footer.java, from the request scope, and there you goooooo.
 
Ivan Davidov
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please tell me what do you mean with this:

"..just get the bean corresponding to your footer.jsp,namely footer.java, from the request scope.."

In fact how do you suggest to get the bean from the request scope?

Let's say I have this:

in Header.java

1: public void blabla() {
2: Footer footer = (Footer) ??? // I'm lost here!
3: footer.changeSomething("a", "b", "c");
4: }
 
Saloon Keeper
Posts: 28056
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, all 3 sub-pages can share a single backing bean. Which, of course, means that if you change that bean in one sub-page, it will be reflected in the other sub-pages when the composite page is next rendered.
 
Yan Hu
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ivan:
Here is how you get your bean out of the request scope

Application app = facesContext.getApplication();

// Say you have an instance of Footer.java stored in the request scope under the name "footer"

Footer footer =(Footer)app.createValueBinding("#{requestScope.footer}").getValue(facesContext)
reply
    Bookmark Topic Watch Topic
  • New Topic