0

We all know we can get any Bean name in Java class Get JSF managed bean by name in any Servlet related class

Now my question is I have 3 Bean with 3 different JSF/XHTMl page and all 3 JSF/XHTML pages open a popup Modal Window with same component inside it right now we used 3 different popup and its working

But i want to use only one popup should be use so here issue is that I have to call some method from Popup to corresponding Parent Bean.

So for this i will want to pass bean name as a argument in the action attribute . Now for this how i would know Which bean class is parent of Popup Window.

<h:commandButton value="button" action="#{popupbean.someMethod(Parentbeanname)}"

and in my Popupbean.java i have wrote this code if i will get bean name as a string

public void addFeature(String beanName){
        Bean bean = (Bean) request.getSession().getAttribute("beanName");
    }

or I will get class name

public void addFeature(object className) {
    if (classname instanceof Abean) {
        ABean abean = (Abean) classname;
        abean.callSomeMethod();
    } else if (classname instanceof Bbean) {
        BBean abean = (Bbean) classname;
        bbean.callSomeMethod();
    }
Community
  • 1
  • 1
Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
  • This question is confusing. It should work just fine. What problem exactly are you facing when doing so? Or is your concrete problem that you already don't know the bean name in first place? – BalusC Aug 06 '15 at 11:47
  • Do you mean something like `action="#{deleteUser(user)}"`, where `user` is an object? – alexander Aug 06 '15 at 12:26
  • @BalusC i have edited my question – Subodh Joshi Aug 06 '15 at 12:54
  • 2
    Why not pass the bean reference in as a param to the include?. No need to pass the bean name in and resolve it. Does http://stackoverflow.com/questions/16842912/passing-the-backing-bean-as-a-parameter-to-a-facelet-include feel like an answer?(duplicate then) – Kukeltje Aug 06 '15 at 13:01
  • Kukeltje is right. You're approaching this problem from the wrong side on. – BalusC Aug 06 '15 at 13:07
  • @BalusC If i am passing like this `` in that case `ParameterBean` should be a `String` or `Object` – Subodh Joshi Aug 06 '15 at 13:09
  • Got it its a `object` not `String` – Subodh Joshi Aug 06 '15 at 14:19

0 Answers0