JSF Backing bean code

Hi every body ,
I am creating one form , on that form I have created six tabs.On my entire application I have one backing bean .I have taken that backing bean in a session scope .
My question :
Can I create six different backing bean for each tab ?
A short example :
//MyBackingBean.java
//This is the main backing bean.
class MyBackingBean
        //for first tab
        private FirstTabBackingBean  firstTabBackingBean ;
        //for second tab
        private SecondTabBackingBean  secondTabBackingBean ;
        //for third tab
        private ThirdTabBackingBean  thirdTabBackingBean ;
        //for fourth tab
        private FourthTabBackingBean  fourthTabBackingBean ;
        //for fifth tab
        private FifthTabBackingBean  fifthTabBackingBean ;
        //for sixth tab
        private SixTabBackingBean  sixTabBackingBean ;
        //Simple getter and setter for each backing bean , such as :
       public FirstTabBackingBean getFirstTabBackingBean()
               if(this.firstTabBackingBean ==null)
                    this.firstTabBackingBean  = new FirstTabBackingBean();
               return this.firstTabBackingBean;
        public void setFirstTabBackingBean(FirstTabBackingBean firstTabBackingBean )
              this.firstTabBackingBean  =  firstTabBackingBean ;
        //Same for other remaining 5 beans.
//FirstTabBackingBean.java
class FirstTabBackingBean 
      //Here I am doing all actions related to button click & radio button click .........
}  my faces-config.xml is :
<managed-bean>
   <managed-bean-name>mainBackingBean</managed-bean-name>
      <managed-bean-class>
          com.myPkg.MyBackingBean
     </managed-bean-class>
   <managed-bean-scope>session</managed-bean-scope>
</managed-bean>my jsf is somthing like that :
<h:commandButton  action="#{mainBackingBean.firstTabBackingBean.previousAction }" value="Previous"/>It is working fine for my application.For code maintain purpose I just separate each tabs actions into different beans.
Is it the proper way ?
or is there any different way to write code ?
Thanks,
SB

Hi thanks for your suggestion , but the problem is in my app there are more than 60 operations(Actions) are going on , in different tabs , for that reason I just separated all operations & putted in different backing bean .If I use one backing bean it will give a lot of pain to maintain the code , because then only I have to write all action specific codes in that one backing bean .
Is there any other way out ?
regards,
SB

Similar Messages

  • How to show popup from backing bean code immediately?

    Hi,
    I'm using JDeveloper 11.1.2.1.0 and have problems with showing popups. I have a button with an action on my page and a method in backing bean.
    I want to rise up few popups from this method in backing bean (for example just an anouncement that something will happen) or a dialog
    (for example a question if you want to continue).
    I understand how to get a dialog response to deal with it in code, but the problem is that the popup doesn't show up immediately, but only when
    this method called on button finishes. I'd like to handle dialog responses in the middle of the action and then the code to continue with the execution.
    Here is my backing bean code:
    private RichPopup popup;
    public String test() {
    //Some code...
    RichPopup.PopupHints hints = new RichPopup.PopupHints();
    popup.show(hints);
    //Here is the place for code which I want to be executed after popup closes,
    //but is executed before the popup shows...
    return null;
    And here is part of my jssf:
    <af:commandButton text="Test" id="cb1"
    action="#{popupBean.test}"/>
    <af:popup id="popup" binding="#{popupBean.popup}">
    <af:dialog id="dialog" type="yesNo"
    title="Dialog"
    dialogListener="#{popupBean.onDialogAction}"
    binding="#{popupBean.dialog}" clientComponent="true">
    <af:outputText value="Do you want to continue?" id="ot1"/>
    <af:clientListener method="onDialogCancel" type="dialog"/>
    <af:serverListener type="DialogCancelHandlerEvent" method="#{popupBean.onDialogCancel}"/>
    </af:dialog>
    </af:popup>
    Can someone give me some answer how to show the popup from backing bean code immediately?
    Thanks in advance,
    Tina

    If you want to execute code after popup closes, then put this code in PopupCanceledListener or in DialogListener(you can't block method execution).
    Dario

  • JSF Backing bean / JSP interaction questions

    A few questions about JSF beans and JSP page interactions. Bear in mind that I'm new to both JSP and JSF, so a solution that might be obvious to the rest of the world may be new to me.
    1. Can I pass a parameter to the backing bean method from an "action" attribute:
    <h:commandLink action="#{TableData.SortRec}">
    <h:outputText value="#{msgs.selectedHeader}"/>
    </h:commandLink>
    I'd like to call the same method from several controls, but pass it a parameter to determine which field to sort on.
    2) Is there a way for a backing bean method to determine which control invoked it?
    3) Is there a way to access JSF backing bean methods from JSP tags. I'd like to do some conditional page assembly based on a JSF bean property... JSF doesn't appear to have a conditional like JSP's <c:if>, but I could use JSP's if it could access the JSF bean.

    Could you pl tell me how to pass parameter thru CommandButton
    I have the following situation
    1) greetingList.faces which list the Ids & greeting Text
    Id Text
    1 Hello World
    2 Hello World
    2) Pl note Ids are h:commandLink. A click on the Id will render greetingForm.faces with data pertaining to that Id and with Update h:CommandButton
    3) When i click Update button it results in the following error
    javax.faces.FacesException: Error calling action method of component with id greetingForm:_id4
    Caused by: javax.faces.el.EvaluationException: Exception while invoking expression #{greetingForm.update}
    Caused by: java.lang.NullPointerException
    So i verified with h:message that Id is passed as Null when click on Update button. I also checked greetingForm.faces has a not null value by printing <h:outputText value="#{greetingForm.message.id}"/>
    So i guess the Id value is overwriteen with null. Also i have defined Id as property in managed bean
    <managed-bean-name>greetingForm</managed-bean-name>
    <managed-bean-class>com.mycompany.GreetingForm</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    <managed-property>
    <property-name>id</property-name>
    <value>#{param.id}</value>
    </managed-property>
    Any pointers/suggestions at the earliest on how to pass the value of Id on a click of update button from greetingForm.faces to greetingForm.java will be highly appreciated
    I am willing to upload my war file
    Regards
    Bansi

  • Turning off automatic backing bean code generation

    Hi,
    When I created my JSP page using the wizard I selected to automatically expose UI components in a new managed bean. Is there any way I can now turn this off so that I can just enter the backing code that I want.
    Thanks,
    Dave

    Hi Grant,
    Sorry I don't think I explained my problem very well.
    I've already created the JSP page and don't really want to create the whole thing again with the flag not set. I can remove any code that is already added that I don't want but I was wondering if there is a property I can change so it will no longer automatically add backing bean code whenever I add any new controls to the page.
    Thanks for your help,
    Dave

  • Open URL in a new browser from a JSF backing bean

    I want to use commandButton action in jsf to launch a new browser instead of using commandLink.
    How do you launch url in a new browser window by firing up a method in backing bean?
    So far I am able to launch a URL within the same browser window. Here is my code:
    In jsp file:
    <h:commandButton rendered="#{openDataList.valueModifiable}" value="link" action="#{openDataList.link}" />
    In backing bean:
    public void link()
         try{
         FacesContext faces = FacesContext.getCurrentInstance();
         faces.responseComplete();
         ExternalContext context = faces.getExternalContext();
         context.redirect("http://www....");      }
         catch(java.io.IOException e)
    ...

    with a commandButton i dont belive you can
    well there are ways you can use javascript window.open
    or you can use a commanLink ans set the target
    but from my understanding there is no way to open a new browser from the backing beans ( this is because this is a client function and your backing beans are on the sever )

  • Calling from an EJB into a JSF Backing Bean

    Hello all,
    I'm looking for some help in making calls from an EJB into a Backing Bean (the converse is fairly straightforward). My basic question is: what is regarded as the best way to do this?
    However, for anybody who's interested, I'll describe what I've been trying...
    Here's my situation (I'm working with OC4J 10.1.3.2). I have a simple application-scoped backing bean:
       public class BackingBean implements SimpleInterface, Serializable {
           private String greeting = "Hello, World";
           private SessionEJBRemote blBeanRemote = null;
           public BackingBean() {
               // get hold of EJB
               // [ ... code to obtain EJB's remote interface snipped ... ]
               // set the callback with the EJB       
               try {
                   blBeanRemote.setCallback(this);
               } catch (Exception ex) {
                   ex.printStackTrace();
           // methods to manipulate the greeting string
           public String getGreeting() {
               return greeting;
           public void setGreeting(String greeting) {
               this.greeting = greeting;
       }SimpleInterface, which my Backing Bean implements is, well, a simple interface:
       public interface SimpleInterface {
           public void setGreeting(String greeting);
       }And my EJB is also pretty straightforward:
       @Stateful(name="SessionEJB")
       public class SessionEJBBean implements SessionEJBRemote, SessionEJBLocal {
           private SimpleInterface callback = null;
           public void setCallback(SimpleInterface callback) {
               this.callback = callback;
               callback.setGreeting("Goodbye, World");
       }Now, by using SimpleInterface, my intention was to ensure a one-way dependency: i.e. the JSF-level code would depend on the EJB-level code, but not vice versa.
    However, my experimentation has shown that when I make the call to blBeanRemote.setCallback, the parameter appears to be passed by value rather than by reference. This means firstly that, at runtime, by EJB needs to have access to my backing bean class and secondly, that the call to callback.setGreeting has no effect.
    Can anybody suggest how to work around this? Is it possible to pass the backing bean by reference? Is there a better way to achieve this callback? I appreciate that these questions might be more general Java/AppServer queries rather than JSF-specific ones - but hopefully this is something that all you JSF experts have encountered before.
    (Incidentally, I realise that what I'm doing in this example is pointless - what I'm building towards is using the ICEFaces framework to have the EJBs prod a backing bean which will in turn cause a user's browser to rerender.)
    Many thanks - any help very much appreciated!
    Alistair.

    Hi Raymond - yes, you've pretty much got that spot on: an event occurs (say receipt of a JMS message - which is spontaneous, as far as the users are concerned). As a result of that event, the client's view (in their browser) needs to be re-rendered.
    ICEFaces uses the AJAX technique to allow server-pushes, and rather than refreshing the whole page it uses "Direct-to-DOM" rendering to maninpulate the page components. If you've not come across it, and you're interested, then there are some pretty interesting demos here: http://www.icefaces.org/main/demos/ - the "chat" feature of the Auction Monitor demo (if you open it up in two browsers) is the nearest to the effect I'm looking for.
    The Auction Monitor demo uses a number of session-scoped beans, each implementing the ICEFaces "Renderable" interface, and each of which registers itself with an application-scoped bean. The application-scoped bean can thus iterate through each of the session-scoped beans and cause the corresponding browser to refresh.
    Unfortunately, in the Auction Monitor demo, the entry point is always from a browser - albeit the result is then mirrored across all connected browsers. I haven't found any examples of this processing being driven by an external event, hence my experimentation in this area!

  • JSF backing bean accessibility from external class

    I am using JSF in my application. Consider i am assigning a value of the inputtext field to a string in my managed bean. This bean has the getters and setters for the string.
    Now my requirement is to get the value of the string i.e. the string value entered in the input text field in another class file. If "A" is a backing bean, I want a class B to access the values(in this case the inputtext value) from A.
    Thanks in Advance.

    Below is the code where i am using the inputtext tag in the JSP page
    <h:inputText value="#{person.name}" />
    "person" is the backing bean which is declared in the faces-config.xml
    PersonBean code:*
    package jsfExample;
    public class PersonBean {
         private String name;
    public void setName(String name) {
              this.name = name;
    public String getName() {
              return this.name;
    Now i have another class in the same package as shown below.
    package jsfExample;
    public class worker extends PersonBean{
    //this function should use the variable name present in the backing bean//
         public void access(){
         PersonBean person= new PersonBean();
         String str=person.getName();
         System.out.println(str);
    //I am getting null value in the str variable inside here//
    but if i print the variable inside the backing bean(*PersonBean*) it is working fine.

  • Best practice for initializing objects in a JSF backing bean?

    Hi,
    What is the best practice for initializing some objects in the JSF to-page backing bean before the to-page is displayed for the first time? The initialization would vary and depend upon a command link in the from-page.
    Regards,
    Al Malin

    f:view has two new attributes in 1.2: beforePhase and afterPhase
    which allows you to specify a phase listener method
    which will be called before and after the view is processed.

  • WebSphere Custering and JSF Backing Beans

    Hello All,
    Can anyone enlighten me on exactly how backing bean state is maintained by JSF?
    In what scope does JSF store the backing beans? (session perhaps)
    Does it make sense to use JSF without stateful backing beans?
    What would happen if a client post did not find its corresponding backing bean on the application server calling it?
    Background:
    In a clustered WebSphere Server environment, a client post may be directed to any one of the machines in the cluster. If the client post gets directed to a machine other then the machine that originally sent the client a response, the page will not find the corresponding page beans.
    It is possible to serialize session beans in WebSphere and have each machine share its memory with all the boxes in the cluster. However, this practice is not permitted in some environments.
    Any thoughts? Thanks in advance.

    I am probably not an expert on the subject. But here are some thoughts:
    1. A backing bean can have (application, session, request or None) as a scope.
    Less app or session scope beans the better (from server perspective). But
    There are practical reasons why you would want to use them in many cases.
    2. JSF supports Client State Saving mode. But keep in mind the overhead
    Involved (serialization, de-serialization, bandwidth,...).
    3. You probably need to read about WebSphere load balancing capability. From
    what I know it is somehow sophisticated. People typically use session affinity
    to force requests initiated by same session to be served by the same app
    server (enforced by network, hardware/software tools available to do so,...). Of
    course with failover mechanism to ensure high availability.
    Hope that helps!

  • JSF Backing Bean State Being Lost Prior to Submit

    ISSUE
    I have an attribute in a backing bean for a drop-down list in a JSF that loses its state before I submit the page, which causes data updates to the backing bean dependent upon its state to be ignored.
    CONTEXT
    The JSF in question has a selectOneMenu drop-down list that determines whether or not several inputText fields will be rendered. The selectOneMenu is bound to an enum in the backing bean, and there are conditional accessors allowing the JSF to determine which inputTexts should be included in the current view. The three valid values of the drop-down are "ALL", "RANGE" and "SINGLE". The page is request scoped, a requirement of this project.
    Here is the JSF tag for the selectOneMenu drop-down list:
    <h:selectOneMenu disabled="#{not backingBean.newEntry}"
        id="tCriteria"
        value="#{backingBean.tCriteria}"
        onchange="submit()">
        <f:selectItems value="#{backingBean.possibleTCriteria}" />
    </h:selectOneMenu>And here are the RANGE selection-specific inputText controls:
    <h:inputText disabled="#{not backingBean.newEntry}"
        rendered="#{backingBean.tRange}"
        id="startTIndex"
        value="#{backingBean.tIndex}" />
    <h:inputText disabled="#{not backingBean.newEntry}"
        rendered="#{backingBean.tRange}"
        id="endTIndex"
        value="#{backingBean.endTIndex}" />Here is how I initialize the backing bean for the drop-down list attribute:
    * The current "t" criteria.
    private TCriteria tCriteria = TCriteria.ALL;And there are basic accessor/mutator methods for it. All of this works pretty well, with one problem. If I select "RANGE" in the drop-down, the appropriate inputText fields appear in the view. When I submit the page with values in the inputText fields, the value of the drop-down in the backing bean has been reset to its default initial value ("ALL") without having been updated through its mutator. Thus, when values in the backing bean are updated from the JSF, the conditional inputText fields are ignored, as they appear to have been deemed irrelevant during the update phase by the invalid state of the backing bean for the drop-down.
    To test my theory, I changed the default value of the backing bean attribute for the drop-down to be "RANGE", and made it final. The page behaves perfectly in updating the backing bean with the values entered for the conditionally-displayed inputText controls. This tells me that the invalid state of the backing bean drop-down list attribute must be the problem. Furthermore, I have tried using "disabled=", "readonly=" and "rendered=" on the conditional inputText fields, and none of that seems to make a difference. I also tried using a ValueChangeHandler, but that didn't do anything about it.
    Note - the backing bean does realize that the correct state for the drop-down should be "RANGE", but only AFTER the backing bean has received its updated values from the page controls.
    Has anyone seen anything like this? I haven't read anything in previous posts about an issue like this, but it has to be something someone has seen before. Maybe related to using the enum type? Thanks.

    Hi,
    did your web.xml file had any parameter regarding explicitly indicating the way to save state?
    I mean something like
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
      </context-param>One last question: did you stay with request scope beans or session ones?
    Greetings.
    MogaRick

  • Can I catch the resulting TopLink query in the JSF backing bean?

    Hello!
    I'm using a JSF in my application. In my case, data on the JSF Pages is based on a TopLink queries, which usually have some parameters. Such a construction works fine except one moment.
    For export data purposes, I need to catch the generated text of query evidently, suppose, in a Page's backing bean.
    Is it possible to perform this action and how to?
    Thanks.

    generally speaking, you can just throw one exception a time. you can throw your own application but you can't throw both SQLException and your own.

  • Launch Listener Problems in Server Side Backing Bean Code.

    Hi All,
    I am construcing an Table of Rich Command Links in the backing bean.
    For each command Link i launch a dialog through the backing bean.
    I have added a Launch Listener for each Command Link.However i see that although the dialog gets launched the launch Listener doesnt get invoked . The invocation of the launch listener is critical for me to pass information to the child dialog.
    Here's the pseudo Code
    tableConstructor ()
    CommandLink.addActionListner (mylistener);
    CommandLink.addLaunchListener (mylaunch);
    CommandLink.setPartialSubmit (true);
    CommandLink.setUseWindow (true);
    richColumn.add (CommandLink)
    // Actual Code of listener
    mylistener (actionEvent) {
    // Set the properties for the window to be launched.
    Map winProps = new HashMap();
    winProps.put ("height" , "1000");
    winProps.put ("width" , "1000");
    // End of setting properties for the window to be launched
    FacesContext ctx = FacesContext.getCurrentInstance();
    ViewHandler viewHandler = ctx.getApplication().getViewHandler();
    UIViewRoot dialog = viewHandler.createView(ctx,
    "/A.jspx");
    Application app = ctx.getApplication();
    AdfFacesContext afContext = AdfFacesContext.getCurrentInstance();
    afContext.launchDialog(dialog, null,
    actionEvent.getComponent(), true, winProps);
    myLaunch () {
    System.out.println ("I Am here);
    I am here is not getting printed.. Any idea how to make the launchListener work in this scenario...
    Any help will be great.
    Thanks
    Karthik

    Hi,
    I can reproduce this. I am still not sure if this is supposed to work this way. However, since I don't know better, I filed a bug.
    Frank

  • Redirect from JSF backing bean to another application

    Hi,
    I need to open another (non-JSF) application in a new window from the backing bean of my JSF application.
    My JSF application is in frames. - heading, menu, content.
    I've a commandlink in the menu frame.
    I tried with
    FacesContext.getCurrentInstance().getExternalContext().redirect(loginUrl);
    This is opening in the menu frame itself.
    I tried using target="new" , but no result.
    I also need to pass the userId to the external application.
    Any ideas?
    ~Thanks.

    Thanks.
    Yes, GET works. I used a <h:outputLink and used target="new" and
    window.open("url?userId=someId")
    But i donot want to pass userid in GET in the url, since that is a sensitive information.
    Please let me know if there's any other way.
    Thanks,

  • How-to remove a jsf backing bean from session?

    How can I find the reference to a backing bean (with session scope) and then remove the bean?
    I may have painted myself into a corner. When most of my pages are navigated to, they get key info from session and then initially populate the page fields. I populate the fields in the constructor with values from the database based on the keys found in session. So the second time a particular page is called the values may be stale or completely unrelated to the page navigated from because the bean already exists and, naturally, the constructor is never called.
    I'm thinking if I could remove the backing bean, jsf wouldn't find it so it would be recreated on subsequent navigations. Since the constructor would be called with every navigation to the page, the values would not be stale or unrelated.
    Any help would be greatly appreciated.
    TIA,
    Al Malin

    //To reset session bean
    FacesContext
         .getCurrentInstance()
         .getApplication()
         .createValueBinding( "#{yourBeanName}").setValue(FacesContext.getCurrentInstance(), null );
    //To get session bean reference
    Object obj = FacesContext
              .getCurrentInstance()
              .getApplication()
              .createValueBinding("#{yourBeanName}")
              .getValue(FacesContext.getCurrentInstance());
    YourSessionBean bean = (YourSessionBean)obj;

  • How can fill javascript array from list in jsf backing bean

    Hello
    i have an array in javascript and i want to fill in from the list which is coming from the backing bean how can i do that.
    Regards

    Hi,
    using the ExtendedRenderkitService class you can send JavaScript calls from a managed bean to the client. So in your case you call a client side javaScript method and pass the array information as an argument. The way you pass the array data is up to you. You may just pass a character delimited list, or use JSON object notation in case the list shows objects. Note that this is for JDeveloper 11.In 10.1.3 there is no server side JavaScript API. Here you would have to add the JavaScript to the page when rendering it.
    Frank

Maybe you are looking for