-
Generic managed bean with JSF (2 messages)
- Posted by: Jerome Sarda
- Posted on: June 09 2006 03:25 EDT
Hello all, I'm currently working on a project that needs to use and define generic managed bean in JSF. My problem is that I want to reuse "dynamically" jsp pages with different beans. Here is a small description of my problem. This tag is present in a foo.jsp file, and uses a reference to a managed bean named "iMenuModel". I'm looking for any solution that allows me to define dynamically the real backing bean of these pages. As a fist, solution I think about something like that: And public class Model { public String id; public String getId() { return id; } public void setId(String aId) { id = aId; } public String getTitle() { return MyFactory.getMenuModel(id).getTitle(); } public String setTitle(String aTitle) { return MyFactory.getMenuModel(id).setTitle(aTitle); } } This solution allows me to reuse the same managed bean that delegates its methods to another java object. Unfortunately, I’m not confident with this fist "maybe dirty" solution and I will appreciate some advices. Thanks in advance.Threaded Messages (2)
- Re: Generic managed bean with JSF by Alexandre Poitras on June 09 2006 08:28 EDT
- Use map by Ruben Trancoso on August 19 2007 23:04 EDT
-
Re: Generic managed bean with JSF[ Go to top ]
- Posted by: Alexandre Poitras
- Posted on: June 09 2006 08:28 EDT
- in response to Jerome Sarda
Hello all,
Use facelets ui:composition tag. Allow you to set the managed bean as a parameter.
I'm currently working on a project that needs to use and define generic managed bean in JSF. My problem is that I want to reuse "dynamically" jsp pages with different beans.
Here is a small description of my problem.
This tag is present in a foo.jsp file, and uses a reference to a managed bean named "iMenuModel".
I'm looking for any solution that allows me to define dynamically the real backing bean of these pages. As a fist, solution I think about something like that:
And
public class Model {
public String id;
public String getId() {
return id;
}
public void setId(String aId) {
id = aId;
}
public String getTitle() {
return MyFactory.getMenuModel(id).getTitle();
}
public String setTitle(String aTitle) {
return MyFactory.getMenuModel(id).setTitle(aTitle);
}
}
This solution allows me to reuse the same managed bean that delegates its methods to another java object.
Unfortunately, I’m not confident with this fist "maybe dirty" solution and I will appreciate some advices.
Thanks in advance. -
Use map[ Go to top ]
- Posted by: Ruben Trancoso
- Posted on: August 19 2007 23:04 EDT
- in response to Jerome Sarda
You just need to put a hashmap wich key are the names you need to access on JSF. HashMap map = new HashMap(); map.put("class_" + className, o); req.setAttribute("map", map); inport the jsp in your page with parameters you need: Then you can get the field you want.