Populating managed bean

Hi,
ok, with Bill Dudney's help I managed to figure out how to properly save a bean's state into a database. Now, I'm still lost about initializing the bean with database data to start with.
I thought I could use <managed-property> facility, but I need to be pulling data from a database based on a request parameter (employee id), so this method didn't quite work. Any recommendations?
Thanks
Dmitry

Hi Dmitri,
Glad I could help! Lets see if I can do it again. :-)
Ok the scenario that is in my head based on what I read in your question is this.
Form 1 has a place to type in your employee id (maybe not type but choose or whatever) and a submit button.
On Form 2 you want to display the data related to the employee.
I would approach this problem in this way.
Form 1's submit actionRef would point to an action that would get the data from a Business Delegate (the J2EE Core Pattern) then use that data to populate the Employee managed bean. I typically have each page of my application backed by a 'Page' class that has the data for the form to read and write to as well as actions that are invoked from the page. (BTW if you are in Chicago you can come see me present these ideas @ the nofluffjuststuff.com event next weekend).
Form 2's UIInput and/or UIOutput components valueRef's would referr to the EmployeePage managed bean's attributes to get the data that is would display.
So in your faces-config.xml file you would have something like this
  <managed-bean>
    <description>
      This page manages searching for employees (Form 1 from the discussion above)
    </description>
    <managed-bean-name> empSearchPage </managed-bean-name>
    <managed-bean-class> foo.baz.EmpSearchPage </managed-bean-class>
    <managed-bean-scope> session </managed-bean-scope>
  </managed-bean>
  <managed-bean>
    <description>
      This page manages showing employees (Form 2)
    </description>
    <managed-bean-name> empPage </managed-bean-name>
    <managed-bean-class> foo.baz.EmpPage </managed-bean-class>
    <managed-bean-scope> session </managed-bean-scope>
  </managed-bean>
...Then in your search page you would have something like this
  <h:input_text id="empId" size="32"
                        valueRef="empSearchPage.empId"/>
  <h:command_button id="submit" type="SUBMIT"
                                   label="Search" commandName="search"
                                   actionRef="empSearchPage.searchAction"/>
...Then your emp display page has something like this
  <h:output_text id="empName" size="32"
                          valueRef="empPage.empName"/>
...Then in your empSearchPage.searchAction you would get the data from the Biz Delegate and use that to populate the empPage.
I think this would be better explained with a picture but since I don't to ascii art... :-)
I hope this helps.
TTFN,
-bd-

Similar Messages

  • JSF best practice for managed bean population

    hi;
    consider a simple session scope managed bean with 1 attribute which is calculated dynamically.
    there seem to be 3 ways of populating that attribute (that i could think of):
    1. have the bean's get<attribute> get the data and populate it
    2. have the constructor of the bean get the data and populate it
    3. have an action get the data, and set it from the action code (maybe use a valueBinding to get the bean if the bean which needs population is not the same bean that holds the action) .
    option 1 seems ok for situations where i need my data to be calculated for every valueRef for that attribute but is an overhead for data that need not be calculated for every valueRef.
    option 2 will ensure that te data is calculated only once per session. but it still looks kinda strange to do it
    with option 3, it seems you should populate the dynamic content of the next page and its intuitive but some places in the page might be common content with dynamic data and this has nothing to do with navigation and the next page to be displayed.
    is there a best practice of how to populate a managed bean data?
    are different cases fit different ways?
    any thoughts are appriciated.

    I think it should be either Option 2 or Option 3.
    Option 2 would be necessary if the bean data depends on some request parameters.
    (Example: Getting customer bean for a particular customer id)
    Otherwise Option 3 seems the reasonable approach.
    But, I am also pondering on this issue. The above are just my initial thoughts.

  • How to access all rows one by one of a ADF table through managed bean

    Hi Experts,
    Hi i am new in ADF.
    Could someone help me for solving the below case?
    Scenario - I have table called Test_T1 which have 4 columns C1,C2,C3,C4. Have created EO,VO and AM for test_t1.
    At the time of ADF page creation i selected the option 'Automatically Exposed UI components in New managed bean' (mynewmanagedbean.java).
    From Data control drag and drop Test_T1 table in the page as a ADF table.
    Set the properties for C1,C2,C3 is read only and C4 is an input text.
    Have add after the table and attathed button action on the managed bean mynewmanagedbean.java.
    At the time of running the page Test_T1 populated with some no. of rows (like 9).
    How can i access all the above rows through pressing the button without selection of any of them.
    Actually i want to print all the table rows in log file at the time of pressing the button.
    Thanks in advance.

    Hi Timo,
    Thanks a lot for your reply.
    I am using the JDeveloper 11.1.2.1.0.
    As previously said I am totally new in this framework. So if you explain the solution given by you then it will be help full for me.
    Don't know r you agree or not for this ?
    When i put your resolution in the command button bean JDeveloper said TestDataRow type not found.
    What will be the type and TestDataRow and what is missing in below code or how i will declare that in below code?
    Also Could please mentioned the missing thing ?
    package createrow.view.pagecreation.bean;
    import oracle.adf.model.binding.DCBindingContainer;
    import oracle.adf.model.binding.DCIteratorBinding;
    import org.apache.myfaces.trinidad.model.RowKeySet;
    import oracle.adf.model.BindingContext;
    import java.util.Iterator;
    import java.util.List;
    import oracle.adf.model.bean.DCDataRow;
    import oracle.jbo.Key;
    import oracle.jbo.Row;
    import oracle.jbo.RowSet;
    import oracle.jbo.RowSetIterator;
    import oracle.jbo.ViewObject;
    public class OrdCreationWithManagedBean {
    public String cb1_action() {
    // Add event code here...
    DCBindingContainer bindings =
    (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    DCIteratorBinding dcIteratorBindings =
    bindings.findIteratorBinding("TestOrderItemAllocationVO1Iterator");
    // Get all the rows of a iterator
    Row[] rows = dcIteratorBindings.getAllRowsInRange();
    TestDataRow dataRow = null;
    for (Row row : rows) {
    dataRow = (TestDataRow)((DCDataRow)row).getDataProvider();
    // work with the row...
    return null;
    My page bindings like below
    <?xml version="1.0" encoding="UTF-8" ?>
    <pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel" version="11.1.2.60.81"
    id="OrdCreationWithManagedBeanPageDef" Package="createrow.view.pageDefs">
    <parameters/>
    <executables>
    <variableIterator id="variables"/>
    <iterator Binds="TestOrderItemAllocationVO1" RangeSize="25" DataControl="MainAppModuleDataControl"
    id="TestOrderItemAllocationVO1Iterator"/>
    <iterator Binds="TestOrderItemsEOView1" RangeSize="25" DataControl="MainAppModuleDataControl"
    id="TestOrderItemsEOView1Iterator"/>
    </executables>
    <bindings>
    <tree IterBinding="TestOrderItemAllocationVO1Iterator" id="TestOrderItemAllocationVO1">
    <nodeDefinition DefName="createrow.view.TestOrderItemAllocationVO" Name="TestOrderItemAllocationVO10">
    <AttrNames>
    <Item Value="AllocationId"/>
    <Item Value="AlocationSequence"/>
    <Item Value="ProductName"/>
    <Item Value="AllocationPercentage"/>
    </AttrNames>
    </nodeDefinition>
    </tree>
    <tree IterBinding="TestOrderItemsEOView1Iterator" id="TestOrderItemsEOView1">
    <nodeDefinition DefName="createrow.view.TestOrderItemsEOView" Name="TestOrderItemsEOView10">
    <AttrNames>
    <Item Value="OrderId"/>
    <Item Value="AllocationId"/>
    <Item Value="ProductName"/>
    <Item Value="OrderItemsQty"/>
    </AttrNames>
    </nodeDefinition>
    </tree>
    </bindings>
    </pageDefinition>
    Thanks In Advance

  • Managed Bean "Name" Access  with in the Managed Bean

    Hi,
    I have faces-config.xml in which I have registered a managed bean
    and I have a base class for all the managed bean.
    The JSP's invoke the action/method defined in the base bean and I want to remove the managed bean from session upon a particular event.
    To remove the managed bean from session, as far as I know - we need to know the managed-bean-name in the faces config.
    I wanted to know if there is any way to get the name of the managed bean in the faces-config.xml at run time?.
    Thanks,

    Thanks for your recommendations. The issue that I get stuck on is how to call this method that retrives employee data. When I had the code in the constructor, it executed when I accessed the view.jsp page. Then I populated the fields from the Employee class fields. But once I create non-constructor method, how do I invoke it from my JSF page.

  • The Managed Bean in the faces-config.xml File

    I am still very new to JSF. I am confused about the managed bean.
    For example, I have a button in my web page. A click on this button invokes an action; say, ListAction.java.
    In this ListAction class, I instantiate a business delegate; say, ListPersonnel.java and call a method in this business delegate to return an ArrayList: personnel. Of course, this business delegate goes through facade, DAO, etc. to populate the ArrayList. This ArrayList is a collecation of a JavaBean called PersonnelBean that gets and sets a number of personnel information; such as ssn, name, etc.
    Upon this ArrayList is successfully populated and received by the ListAction class, I am going to display a web page with a table. In JSF, it is <h:dataTable ...>.
    My questions are regarding the managed bean in the faces-config.xml file.
    1. Which one is my <managed-bean-class>? packageName.ListAction? or packageName.PersonnelBean? or something else?
    2. What should be my <managed-bean-name>? I guess that I can give a name I like. Is it right? What about xyz?
    3. Then, how do I specify the "value" attribute of my <h:dataTable ...> tag when I display a web page to show the data table? Is it correct to specify value="#{xyz.personnel}"? What is the correct specification if it is wrong?
    4. I guess that I can give any name to the "var" attribute in the <h:dataTable ...> tag. Is it right?

    1. Which one is my <managed-bean-class>?
    packageName.ListAction? or
    packageName.PersonnelBean? or something else?ListAction
    2. What should be my <managed-bean-name>? I guess
    that I can give a name I like. Is it right? What
    about xyz?Anything you like. xyz is OK.
    3. Then, how do I specify the "value" attribute of my
    <h:dataTable ...> tag when I display a web page to
    show the data table? Is it correct to specify
    value="#{xyz.personnel}"? What is the correct
    specification if it is wrong?xyz.personnel is OK assuming that ListAction class has a public
    method getPersonnel() which returns the ArrayList of PersonnellBeans.
    4. I guess that I can give any name to the "var"
    attribute in the <h:dataTable ...> tag. Is it right?Yes, you can give any name you like.

  • How can I load the data of Manager Beans into an Array?

    Hi all!
    I have a problem when use the ADF model layer (JDeveloper 10g). I want to load the data of a Manager Bean into Array(such as: Array in JavaScript).But I don't know any ways to do.
    Are there any ways to do that?
    Please, help me!
    Thanks so much!

    Hi,
    there is a fundamental difference between an array in Java and an array in JavaScript as the latter is added to the output page while the first sits in a Java class on the server.
    Populating a Java array from a managed bean is straight froward: Just create the Array, loop through the source of the data - ADF binding or the ADF Faces table component - and fill it.
    For a JavaScript Array I would suggest to write the array into a js file and reference it from the web page (which might cause concurrency issues).
    Frank

  • How to pass a value from jspx page to the managed bean

    hi,
    i have created a jspx page and manages bean with page flow scope..
    in my jspx page i am searching a employee record from the data base . and getting entire employee details including 'status' as a search result.
    here i want to pass the value of 'status ' field to the managed bean variable called 'stval'.
    can anybody suggest any solution?.......

    As per the details provided in the post above, when the user clicks on the search in the af:query, the results are populated in the table. And you are interested in getting the value of particular column. This could be done by having the custom row selection listener to get the value of the current row (selected row in the table).
    1) Have a custom selection listener:
    <af:table value="#{bindings.EmpDeptVO.collectionModel}" var="row"
    rows="#{bindings.EmpDeptVO.rangeSize}"
    emptyText="#{bindings.EmpDeptVO.viewable ? 'No data to display.' : 'Access Denied.'}"
    fetchSize="#{bindings.EmpDeptVO.rangeSize}"
    rowBandingInterval="0"
    rowSelection="single" id="t1"
    partialTriggers=":::qryId1 ::ctb1 ::commandToolbarButton1"
    columnStretching="column:c1"
    styleClass="AFStretchWidth" columnSelection="multiple"
    first="0" contentDelivery="immediate" autoHeightRows="10"
    binding="#{pageFlowScope.ExampleBean.searchResultsTable}"
    *selectionListener="#{pageFlowScope.ExampleBean.rowSelected}">*
    2) In the method, set the current row programmatically:
    ADFUtil.invokeEL("#{bindings.EmpDeptVO.collectionModel.makeCurrent}",
    new Class[] { SelectionEvent.class },
    new Object[] { selectionEvent });
    3) Get the current row and get the required attribute values and set it in any of the variables in the managed bean:
    Row selectedRow =
    (Row)ADFUtil.evaluateEL("#{bindings.EmpDeptVOIterator.currentRow}");
    String status = selectedRow.getAttribute("Status");
    Thanks,
    Navaneeth

  • How to pass js variable to be used in managed bean constractor?

    Hi,
    I got a list of items that i present in <h:selectOneMenu on my page (the first page the user sees)
    the labels that are shown in the ><h:selectOneMenu are date + time , and the time itself is stored in the db in UTC without any + or - timezone offset (e.g UTC +2)
    In order to show the correct time in the labels of the ><h:selectOneMenu I'm adding the needed offset of the user timezone
    the problem is that the ><h:selectOneMenu is being populated from the managed bean before I'm passing the offset from the xhtml page itself using jQuery $.post(
    like this
    <h:head>
    <script type="text/javascript">
              jQuery(document).ready(function($) {
                   d = new Date();
                   var tz = -1 * d.getTimezoneOffset()/60;
                   $.post("/servlets/TimeZoneFromClientServlet",{timezone : tz});
           </script>
         </h:head>any ideas how can i pass the TimezoneOffset to the application before the managed bean is loaded?
    Thanks ahead!
    Daniel.

    You know, any website I've encountered so far ASKS for your timezone. Why do you think that is?
    In any case, if you really want to go ahead and do what you want, you need a single point of entry in your web application that sets the timezone in the session once so you can reuse it. It could be something as simple as doing it in a login page if you have one; just create a hidden input field that is prefilled with the timezone you find using Javascript; then simply submit it to the server and stick it in the session there. When the session times out the user would have to login again, which would give you the timezone value back.
    another option: is the managed bean session scoped? If so you can simply fetch it in your servlet and update the appropriate property of the managed bean. This one makes me feel some shame for suggesting it though.

  • To dynamically assosciate an iframe with a new managed bean instance

    I have a datatable populated with records.Each row consists of a checkbox and the corresponding row data. I need to select 2 rows to display the same in 2 different iframes rendered in the next page. I have one managed-bean (Display.java) registered in the faces-config.xml in the session scope. But I would like to assosciate each iframe with a different instance of Display.java. Is it possible?

    Now, I have each iframe assosciated with a different instance of managed bean.
    Also the requests are distinguished based on the rowId appended as a
    parameter to the querystring.
    eg:<IFRAME src="display.jsf?rowId=1">.
    The iframes are drawn dynamically based on the no of rows selected.
    But there is a mixup of data, i.e the first row data appears in both the iframes. Is it to do with rendering of iframes? How do i resolve this?

  • H:selectOneMenu value binding to managed bean property

    Please help. Cannot figure out why selectOneMenu value binding is not working...
    The main contents of my jsp:
         <h:form id="form1" rendered="true">
              <P>
                   <h:selectOneMenu value="#{MBListBoxExample.selectedProject}" rendered="true"
                        required="false">
                        <f:selectItems value="#{MBListBoxExample.items}" />
                   </h:selectOneMenu>
              </P>
              <h:commandButton value="ShowSelected" rendered="true" action="#{MBListBoxExample.showSelected}" />
         </h:form>I have a managed bean with a property that is basically a custom object:
    private Project selectedProject;The selectOneMenu gets populated with the following code in my managed bean:
         public List getItems() {
              try {
                   ArrayList projectList = new ArrayList ();
                   projectList.add(new Project(1, "Project 1"));
                   projectList.add(new Project(2, "Project 2"));
                   projectList.add(new Project(3, "Project 3"));
                   projectList.add(new Project(4, "Project 4"));
                   ArrayList itemList = new ArrayList();
                   for (int x=0; x<projectList.size(); x++) {
                        SelectItem tempItem = new SelectItem();
                        Project tempProj = (Project) projectList.get(x);
                        tempItem.setLabel(tempProj.getName());
                        tempItem.setValue(tempProj);
                        itemList.add(tempItem);
                   return itemList;
              } catch (Exception e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              return null;
         }The following code is tied to my command button to display some simple output when the button is clicked:
         public void showSelected() {
              System.out.println("The selected item is: " + selectedProject.getName());
         }If I set the value of the SelectItem (tempItem) above to a String and make the selectedProject variable of type String, the code works.
    My goal is to have the items in the list reference 'Project' objects and be able to get to the selected object when the user clicks the command button.
    Any help is greatly appreciated.

    The problem is that you're missing a converter. JSF needs to convert your values from Strings into Projects and vica verca.
    When you do the form submission the values are passed as strings along with the labels. JSF isn't smart enough to convert them automatically.

  • Identical view but different managed beans?

    Hi everyone,
    We have a situation where we have jsf code that is identical for 2 different pages, except that the managed bean(backing bean) is different. We are having to duplicate the jsf code just because of this. It would be much easier to maintain if we could share the jsf code between the two beans(and somehow have it use the backing bean that it needs to use at the right time). Is there a way to do this?
    Thanks in advance!
    -M

    This code is part of a component that allows users to input their address(add page). On another page(settings page), where the user sets defaults for the system, the exact same code is needed for them to set their default address.
    When the user goes to the add page, this default address is populated, the user can continue using the default or change it.
    Hope this makes sense. Thanks.

  • Enable/disable via managed bean

    Hi
    using jdev 11.1.1.3
    Can anyone tell me how to disable/enable a input textfield from a managed bean which should happen on a button click.
    The fields are already populated with data and is editable, and is part of a taskflow.
    any help will be helpfull
    thanks

    Hi bigchill,
    a possible solution could be:
    1. create a bean containing following methods & attributes
    public class MyBean
         // initial value
         private boolean disabled= true;
         public String doSomething()
              this.disabled= false;
              return null;
         public void setDisabled(boolean pDisabled)
              this.disabled= pDisabled;
         public boolean isDisabled()
              return disabled;
    }2. Create an instance of the bean on a certain scope (depending on your requirements)
    3. Link the disabled attribute of the input component with the disabled property of the bean and link the "doSomething" bean method with the action attribute of the commandButton:
    <af:inputText label="Some textfield" disabled="#{s_myBean.disabled}"/>
    <af:commandButton action="#{s_myBean.doSomething}"/>That's it.
    Kind regards,
    Koen Verhulst

  • Error while opening a popup from managed bean

    Hi,
    I am trying to open a popup from bean, after another popup is closed. When I open the second popup either through ActionListener(on first popup button) or DialogListener(on first popup), I am getting the below error on browser status bar(!); and the second popup doesn't open. There is no error in the log.
    *'AdfPage.PAGE.findComponent(...)' is null or not an object.*
    Although the popup id is there on the jspx page.
    <af:popup id="confirmationStatus" binding="#{MyBean1.confirmationStatus}">
    <af:dialog cancelVisible="false"
    closeIconVisible="false" binding="#{MyBean1.d2}"
    title="Appointment Confirmation Status">
    <af:outputText value="Appointment is successfully confirmed"/>
    </af:dialog>
    </af:popup>
    public void confirmAppointment_dialogListener(DialogEvent dialogEvent) {
    FacesContext context = FacesContext.getCurrentInstance();
    ExtendedRenderKitService service = Service.getRenderKitService(context, ExtendedRenderKitService.class);
    String popupId = "confirmationStatus";
    service.addScript(context,"AdfPage.PAGE.findComponent('" + popupId + "').show();");
    Please tell me why my popup is not getting open from the managed bean and I am getting an error in below line.
    service.addScript(context,"AdfPage.PAGE.findComponent('" + popupId + "').show();");

    To find out the right address of a component related to an other component, open your page select the component you want to add a partial trigger, go to the partial trigger property, select the down arrow at the right end and select 'Edit'. Now look for the popup in the component tree shown on the left side. When you have found the popup shuffle it the the selected side and click OK. The string you see in the field is the full address of the popup related to he component you've selected. Try the string you see there in your bean code. Remove the string from the partial trigger property, it's just to get the correct path.
    One other thing to check is that your popup has the ClientComponent property set to true.
    Next thing to try, is to use AdfPage.PAGE.findComponentByAbsoluteId(...)
    Timo

  • How to pop up a browser window from a managed bean?

    I have a user case like this:
    User login our home website. He/she clicks a button. Control flow goes to a managed bean (MB here after) to check some conditions. If conditions are met, instead of sending the user back to the home page, the user will be presented a new web site (e.g. forums.oracle.com) in a popup window on top of our home site.
    Can we invoke a website in a adf popup? If so, how to do that? If not, any idea on how to develop this use case?
    Any idea is appreciated.

    Sorry, I have updated the previous reply with the required inputs.
    For convenience, putting it again;
    if you need to check for some condition and then invoke the browser, you could use the following code in your managed bean for af:commandButton for Action.
    import javax.faces.context.FacesContext;
    import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
    import org.apache.myfaces.trinidad.util.Service;
    public class TestURLPageBean {
    public TestURLPageBean() {
    super();
    public String onClick() {
    *// Check for the condition here and invoke the browser only if it is true*
    if (true) {
    ExtendedRenderKitService erks =
    (ExtendedRenderKitService)Service.getRenderKitService(FacesContext.getCurrentInstance(),
    ExtendedRenderKitService.class);
    StringBuilder script = new StringBuilder();
    script.append("window.open('http://www.google.com');");
    erks.addScript(FacesContext.getCurrentInstance(),
    script.toString());
    return null;
    Thanks,
    Navaneeth

  • What is difference between Managed Bean and Backing Bean?

    What is difference between Managed Bean and Backing Bean? Please guide me how to create them and when to use them?
    Please post sample for both beans.

    Hi,
    managed beans and backing beans are quite the same in that the Java object is managed by the JavaServer Faces framework. Manage in this respect means instantiation. The difference is that backing beans contain component "binding" references, which managed beans usually don't. Do backing beans are page specific versions of managed beans.
    Managed beans are configured either in the faces-config.xml file, or using ADF Faces and ADFc, in the adfc-config.xml file
    Frank
    Edited by: Frank Nimphius on Jan 31, 2011 8:49 AM

Maybe you are looking for

  • Constraint takes long time to enable, other performance issues

    Hello and thanks for any suggestions. I have an instance that has 13 different schemas.  All schemas are working fine, but one.  This one schema, it appears to hang.  I am in the process of loading all 13 schemas with identical data.  12 loaded fine.

  • J2IUN only showing PLA Amount balance all NIL

    Hi, We are in the implementation phase. IN J2iun, only PLA amount is displayed wheras all others are showing 0.00 Can u suggest what cud be missing in that. I searched forum for similar posts and it says extract register from J2i5, and I did that but

  • GROUP EMAILING LIST: Is it possible to create a group list to email

    how would you go about setting up a group contact list to email people instead of having to click on each name.....????   like if you wanted to forward something onto others.......didn't know if it could be done.... Solved! Go to Solution.

  • Attributes / Variable assignment in Excel

    How do you create a variable assignment in Excel that passes the "test script coverage" report? We thought we were being clever when we put a list of our variable assignments in Excel. This allowed us to sort the assignments (something we could not d

  • I have updated my iphone 5 and lost all my music

    please can someone help i have just updated my iphone 5, has i have been told how amazing this new update is so, after i have saved all my music and photos, i updated the phone, when i switched it on, i noticed that none of the songs or the photos wa