Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting parameter from Link to create ManagedBean-Instance

 
Robert Richter
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i want to send a parameter with <h:outputlink> from one page (index.jsp) to another page (detail.jsp) and use this parameter on detail.jsp to create a instance of a ManagedBean.
Is this possible?
If this works, what do i have to do to read out the parameter on detail.jsp and how can create a new Instance of a managedbean with this initial parameter while loding detail.jsp?

here the code for my link

 
Tim Holloway
Saloon Keeper
Pie
Posts: 18164
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.

The essence of a ManagedBean is that JSF manages it. Construction and initialization of managed beans is done via (originally) faces-config.xml or the @ManagedProperty annotation (JSF2). The Managed property value is an EL expression, not a page parameter.

It is bad practice to pass parameters back and forth between pages and backing beans anyway. JSF's architectural basis is the Inversion of Control (IoC) paradigm, which says that outside agencies inject values into a bean, rather than passing them as parameters or making the bean use a Service Locator to pull values in.

In other words, the idea is that beans and bean construction properties are handled entirely within the server, not between server and client.
 
Robert Richter
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okey Thank you.
That´s my first application i want to build with jsf...so i´m really new here...maybe you can help me withe these problem.

Here is a short explanation what i want to do:
The first page shows a list of some journeys. The Information comes through a SQL-Statement into the journey-bean in a ArrayList. The View works fine with a <h:datatable>.
Then i want to click on one of that into the table and show a detail overview about the journey. (On a new Page)
Therefor I have to send a new SQL-Statement with the ID of the journey against the database. The ID is also stored into the ArrayList.

Have you an idea how i can realize that?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18164
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Google "JSF for nonbelievers" (IBM DeveloperWorks).

If you're just starting JSF, here's 2 bits of useful advice:

1. Excluding JSF model objects, the more "javax.faces" code and objects in your backing beans, the more likely you're doing things the hard way.

2. Likewise, the more your View Template (xhtml) looks like a program than a static template, same thing.

I guess I should mention another common thing. Newbies tend to overuse bindings and listeners. I think there's some stale JSF documentation out on the Internet that won't die relating to before more civilized techniques were developed.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic