Discussions

General J2EE: Generic managed bean with JSF

  1. Generic managed bean with JSF (2 messages)

    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)

  2. 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.
    Use facelets ui:composition tag. Allow you to set the managed bean as a parameter.
  3. Use map[ Go to top ]

    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.