Binding af:selectOneChoice to value in managed bean

Hi all,
I am trying to create a simple screen that has a selectOneChoice that allows the user to change the value of a property in a session-scoped managed bean. I've got a View Object that will display the values for the user to select. I can easilly set the value on my managed bean in an actionlistener when the user clicks "OK"
However, I have these problems:
1). I can't find any way to put an af:selectOneChoice on the screen without binding it to something. I want to bind it to a value in a managed bean - how to do this?
2). I tried creating a "dummy" view object (select :bindVariable from dual) and then put an executeWithParams in the executable of my page to set the bind variable to the backing bean value. I then bound the selectOneChoice to that field from the VO. This worked fine the first time, but the second time I tried to call it in the same session, it bombed with JBO errors. This also seems like a very inefficient and round-about way to accomplish this task.
Can anyone provide any pointers as to how I might accomplish this? If it would help, my use case is this: a user is logged on with "super-user" athority and can review information from any of the field offices. The field office ID that the user is currently looking at is stored in the session-scoped bean. I need a way for the user to change what field office they are reviewing.
Thanks and regards,
John

Wow - this is harder than I thought....
I have got something working in a rudimentary fashion, although I'm not completely satisfied yet. What I did was to create my own List binding in the page definiton that looks like this:
<list ListOperMode="1" IterBinding="LKUP_OfficeViewIterator" id="OfficeId">
      <AttrNames>
        <Item Value="OfficeName"/>
        <Item Value="OfficeId"/>
      </AttrNames>
    </list>
</list>I then dropped a selectOneChoice from the component pallette (not the data control pallette) on to my page. The f:SelectItems component inside the af:SelectOneChoice, I bound the value property to "#{bindings.OfficeId.items}" I could not find any documentation on this, but it seems to work. The only issue is that my list shows both the office name and the id (I'd like to show the name and hide the id).
Then, in my backing bean action listener bound to the OK button, I do:
    JUCtrlListBinding o = (JUCtrlListBinding) JSFUtils.resolveExpression("#{bindings.HotelId}");
    // list is bound to my af:SelectOneChoice
    Row r = (Row) o.getValueList()[((Integer)list.getValue()).intValue()];
    Integer officeID = (Integer) r.getAttribute(0);
    String officelName = (String) r.getAttribute(1);
   // getUserInfo gets my session-scoped bean
    super.getUserInfo().setOfficeInformation(officeID, officeName);
     AdfFacesContext.getCurrentInstance().returnFromDialog("ChangeOffice:OK", null);My 2 problems with this approach:
1). How do I get the list to just show the office name (but still make the ID available)?
2). No matter what I put for the value of the af:SelectOneChoice, I can't seem to make it have the current value from userInfo.getOfficeID selected in the list. Even when I hard-code a number in the list, nothing is selected. When I bind the value to an EL property referring to userInfo.officeID, the selectOneChoice doesn't even render!
Regards,
John

Similar Messages

  • How to set ADF table cell value in managed bean

    Hi all,
    I have an ADF table on my page, let's assume with three columns with Input text box: col A, col B and col C where column C is hidden, when I click on Submit is possible to set in managed bean the value of column C for each rows?
    Thk in advance.
    L-

    Hi,
    you can create a button with an ActionListener. In the ActionListener you can iterate over the rows (using the iterator) and set the value on the attribute. If you need to save the changes you can call the commit operation binding.
    Linda

  • How to set hidden value in managed bean?

    Hi
    I have the following :
                           <a4j:commandButton
                                          id="commandButton3"
                                          action="#{backing_CustSearchBean.serchCustomer}"
                                          image="images/btn_search.gif"
                                          style="position: relative; margin-right: 5px;"
                                          actionListener="#{backing_CustSearchBean.checkText}"
                                          immediate="true"
                                          status="wait"
                                          oncomplete="showQuickCreate()"
                                          >  
                                <h:inputHidden id="jsfHidden" binding="#{backing_CustSearchBean.jsfHidden}" />
                                  <a4j:status id="wait">
                                    <f:facet name="start" >
                                      <h:graphicImage url="images/SpinGear2.gif" style="position: absolute; left: 378px; top: 216px; width: 19px; height: 18px;"/>
                                    </f:facet>
                                  </a4j:status>
                     </a4j:commandButton>when the action goes in the managed bean I want to set the value of hidden parameter "jsfHidden" in managed bean and catch it in showQuickCreate (oncomplete="showQuickCreate()" ) javascript function on return to the page.
    Please help, how should I do it?

    I know nothing about a4j, but if you want to pass new parameters from JSF to the backing bean, then use f:param for commandlinks or f:attribute for commandbuttons.
    The h:inputHidden just saves backing bean properties from request to request. You can't set or change it from within the JSF.
    Not sure if the f:attribute will work for the a4j commandbutton (check if they have a support forum at their website?)
    Also see http://balusc.xs4all.nl/srv/dev-jep-com.html about passing parameters and accessing objects and beans in the facescontext.

  • How to get ADF UI Component value in managed bean

    JDev version 11.1.1.1.3.0
    I have written a managed bean method and calling that method on valueChangeEvent of a Select boolean Checkbox ADF Component.
    I want to retreive the value of some other component located in the same page as the checkbox. I need the value of the component into the manged bean. I know how to get the value of the checkbox eg:
    public void selectCheckBoxListener(ValueChangeEvent evt){ 
    boolean selectedValue = (Boolean)evt.getNewValue();
    String oldvalue = (String)evt.getOldValue();
    How can I access the value of an input text component in the above managed bean ? Can someone help on this?

    Hi Sackam,
    String selectedRowId = (String)(evt.getComponent().findComponent("rowId")).getAttributes().get("value");
    The above coding will work fine
    but wht u have specified rowId???? whether the "value" field is inside a af:table????? if so i have doubt on the above code's working.....
    Regards,
    Suganth.G

  • Access session values in Managed Bean

    I want to acces session attribute values in my Managed Bean class.
    This is my code in SecurityPhaseListener.java class,
    HttpSession session = (HttpSession)facesContext.getCurrentInstance().getExternalContext().getSession(true);
    String isAuthorized = "false";
    session.setAttribute(isAuthorized, isAuthorized);
    This is my configuration for My managed bean in faces-config.xml class
    <managed-bean>
    <managed-bean-name>setNewDayBean</managed-bean-name>
    <managed-bean-class>com.hli.vipstar.uswm.setnewday.managedbean.SetNewDayBean</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
    Now i want to access the attribute "isAuthorized" in my managed bean SetNewDayBean.java.
    How to do this?
    Any one help me...........

    The same way, but then using getAttribute() instead of setAttribute().
    Another -more clean- way is to use the ExternalContext#getSessionMap(). It will make your code independent from the session implementation used. You may find this article useful as well: http://balusc.blogspot.com/2006/06/communication-in-jsf.html

  • ADF Faces: Managed Beans

    Hi All,
    I have a situation where i need to pass the value to managed bean at runtime which inturn changes the values of menubar,menulist please can any one help me out.
    Regards
    Manasa Chanda

    What you probably want to do is expose the menubar.menulist component to your managed bean. This is fairly easy to do by editing the "Binding" property of the component. This will let you specify a Managed Bean, and a Property, or you can press a New button to create the bean, and/or the Property. Once you've exposed the component, the properties of the component are available through EL, including being able to change those properties from other components.

  • Re:How to get the vo from managed bean

    Hi all,
    I am using Jdev11.1.2.3.0
    My requirement is : I have one jspx page.In that page i have created one form,so i need to get the values from managed bean.here i wont create by using data control view instance.so finally i have to get the table values from managed bean.so how can i get it.can anyone help me please.
    Thanks,
    G.Shilpa

    So you're not using ADF BC at all, right ?
    From JSF point of view, it does not matter how you provide UI control values.
    What you can do, for example, is to use pure JDBC in order to get and display the database values.
    What you need in your backing bean, is appropriate properties (setter/getter method pairs).
    In the getter, you can obtain DB values by using JDBC
    Take a look at:
    JSF 2.0 + JDBC integration example
    JSF JDBC Integration
    JDBC in JSF - YouTube

  • Accessing Managed Bean Variables in Entity Impl Class

    How can I access managed bean variables in the entity Impl class .
    While inserting a new record in DB , i want to set few entity properties values . The values of those properties are available in the managed bean .
    How can i access those values from Managed Bean and set them the entity Impl class to override the create method.
    Or is there any better recommended approaches ?
    Jdev - 11.1.1.5

    >
    While inserting a new record in DB , i want to set few entity properties values .
    >
    you can user CreateWithparams
    http://www.oracle.com/technetwork/developer-tools/adf/learnmore/13-create-with-params-169140.pdf
    http://andrejusb.blogspot.com/2011/02/createwithparams-operation-for-oracle.html

  • Simple Applicaiton without Managed Beans in ADF? [SOLVED]

    I have a simple problem and coming from the SpringFramework world it isn't so simple in ADF. I am using JDeveloper 11g preview and all the examples I have seen require usage of a manged bean to do the following:
    Given:
    1. I have a service class (EmployeeService) that has two methods: findEmployees() and findEmployee(String uuid)
    2. I have two pages: listEmployees.jspx and viewEmployee.jspx
    Objective:
    1. I would like to list all the employees returned by findEmployees() in the listEmployees.jspx.
    2. I would like to create a commandLink in the listEmployees.jspx for each employee such that when the commandLink for a particular employee it takes you to the viewEmployee.jspx passing to it the selected employee's uuid.
    3. I would like to have viewEmployee.jspx page call the findEmployee(String uuid) using the passed in uuid.
    Any help you can give me would be appreciated.
    Message was edited by:
    user592491

    What you need here is an action method binding, ie a method in the managed bean that gets the current row id and calls the right method to retrieve the data.
    The ADF Tutorial, Chapter 7 shows you how (http://www.oracle.com/technology/obe/ADF_tutorial_1013/10131/index.htm)
    --olaf                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Managing beans based on URL query parameters

    I was just reading this thread with interest, but it didn't come to the conclusion that I need.
    http://forum.java.sun.com/thread.jsp?forum=427&thread=441432
    In that thread, there were two screens: a table of links to employees and an "edit employee" page. The solution was to use the command_action on the list create an "employee data" bean, which could then be edited on the "edit employee" page.
    My problem is that I need to create some session beans based on query parameters in the URL. Using the example above, I'd have something like: http://localhost/app/editEmployee?empNo=38
    Why? Because the user can bookmark the edit employee page, have two
    browser windows open (which would require two seperate employee data beans), etc... and we need to handle that. It looks like
    that means I can't use the solution in the above thread.
    My current thought is to create a managed-bean with request scope and have it create the EmployeeData bean.
    Another idea is to somehow initialize the bean with managed-properties
    <managed-bean>
        <managed-bean-name>EmpBean</managed-bean-name>
        <managed-bean-class>com.mycompany.EmpBean</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
        <managed-property>
            <property-name>employeeID</property-name>
            <value-ref>queryParamBean</value-ref>
        </managed-property>
    </managed-bean>
    <!--
      just returns FacesContext.getCurrentInstance().getServletRequest().getParameter("id")
    -->
    <managed-bean>
        <managed-bean-name>queryParamBean</managed-bean-name>
        <managed-bean-class>com.mycompany.QueryParamBean</managed-bean-class>
        <managed-bean-scope>none</managed-bean-scope>but that seems kinda hacky. Any other ideas?

    Excellent, using requestScope gets rid of the queryParamBean hack from my first post. For some reason I thought value-ref evaluatations only resolved against stuff the VariableResolver can see. That's not the case. Thanks.
    Unfortunately, this bean really wants to be cached on the session, not the request. I suppose it would be possible to have EmpBean delegate to a bean which is actually cached on the session, but that feels like a hack too (and is a lot of glue code).
    So, I think I'm back to the factory, which can handle creating the bean from the query params, caching it, and putting it on the servlet request. I also got a visit from Captain Obvious and realized that the factory could just be a scriplet.
    <% BeanCreator.createBean("com.company.EmpBean", request.getParameter("id")); %>which also isn't great, but is perhaps easier to understand than the BeanCreator from above. I looked into using EL Functions in the variable resolver for the factory, but it doesn't look like that's possible. It's probably possible to extend VariableResolver to add factory methods for managed-beans, which might be the cleanest solution. I'm thinking something like
    <managed-bean>
      <managed-bean-name>Emp</managed-bean-name>
      <managed-bean-factory>
         <factory-name>com.company.BeanFactory.getBean</factory-name>
         <bean-class>com.company.EmpBean</bean-class>
         <arg-value-ref>sessionScope.id</arg-value-ref>
      </managed-bean-factory>But for now, the current two hacks are:
    #1: to create a URL use plain html <href>.
    #2: use a factory method (varying implementions) to create the bean, cache it, and put it on the servlet request

  • Can I set the value of a list binding in my managed bean?

    Dear All,
    This is just an exercise for me and I just wanted to experiment on the bindings of ADF for me to understand it further.
    I wanted to create a custom Model Driven LOV with my data control listed below
    Countries
         -CountryId
         -CountryName..but I wanted to display the label similar to this
    1 - USA
    2 - England
    n - France..so I thought of manipulating the select items in a bean
    <af:selectOneChoice id="soc1" value="#{bindings.Countries.inputValue}">
      <f:selectItems value="#{pageFlowScope.MyBean.countries}" id="si1" valuePassThru="true"/>
    </af:selectOneChoice>..and the code similar to this
    public class MyBean{
         public List<SelectItem> getCountries(){
              //countryMap points to accessing the iterator binding
              //BindingsHelper is a utility class that sets the value
              for(...){
                   SelectItem item = new SelectItem();
                   item.setLabel(countryMap.get("CountryId") + " - " + countryMap.get("CountryName"));
                   item.setValue(countryMap.get("CountryId"));
                   list.add(item);
              //set the item to the first row
              BindingsHelper.setExpressionValue("#{bindings.Countries.inputValue}",
                                     list.get(0).getValue());
              return list;
    }...on the last part I wanted to set the value to the first item but I am encountering numberformatexception when setting the list binding.
    I know I can do this declaratively also by removing the unselected item but as I have said I am experimenting on the bindings.
    Is this not possible?
    Thanks.
    JDev 11G PS5

    Hi ,
    I understand that , you want to show select one choice (dropdown) with label (countyid - country name) and value is (countryid).
    and these informnation is coming from ADf Model ( may be a VO).
    in the UI page you used this list is coming from MyBean
    <af:selectOneChoice id="soc1" value="#{bindings.Countries.inputValue}">
    <f:selectItems value="#{pageFlowScope.MyBean.countries}" id="si1" valuePassThru="true"/>
    </af:selectOneChoice>
    so ,
    The Managed Bean code should be ,
    private List<SelectItem> countries;
    ///setter method
    public void setCountries(List<SelectItem> countries) {
    this.countries= countries;
    // getter method
    public List<SelectItem> getQuoteStatusList() {
    quoteStatusList =
    selectItemsForIterator("countriesVOIterator",
    "countryId", "countryName");
    return quoteStatusList;
    public static List<SelectItem> selectItemsForIterator(String iteratorName, String valueAttrName, String displayAttrName) {
    return selectItemsForIterator(findIterator(iteratorName), valueAttrName, displayAttrName);
    public static DCIteratorBinding findIterator(String name) {
    DCIteratorBinding iter = getDCBindingContainer().findIteratorBinding(name);
    if (iter == null) {
    throw new RuntimeException("Iterator '" + name + "' not found");
    return iter;
    public static List<SelectItem> selectItemsForIterator(DCIteratorBinding iter, String valueAttrName, String displayAttrName) {
    List<SelectItem> selectItems = new ArrayList<SelectItem>();
    for (Row r : iter.getAllRowsInRange()) {
    string labelValue = (String)r.getAttribute(valueAttrName) +"-"+ (String)r.getAttribute(displayAttrName);
    selectItems.add(new SelectItem(r.getAttribute(valueAttrName),labelValue ));
    return selectItems;
    this will give you what you except in the ui
    when you try to get the value form that seclecOneChoice value in MyBean what user selects , you can simply get the value of this selectOneChoice.

  • 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.

  • How to get iterator values from a managed bean ?

    Due to a bug in selectOneChoice i'm not able to get the label list i want to display directly from an iterator when the value binding is a managed bean.
    To solve the problem i would like to create a managed bean that contains that list and use it as the selectItems to display.
    I would like that the values in that managed bean loaded from the a data control iterator.
    My question is :
    1) is it possible to access the iterator values from a managed bean, i mean without any reference to a page definition
    2) how to do ? is it documented somewhere ? any example ?
    Thank you

    I got it also with this code:
    package view.managedBeans;
    import classification.bean.ClassificationDocument;
    import classification.castor.ClassificationLanguage;
    import java.io.FileNotFoundException;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Hashtable;
    import java.util.List;
    import java.util.Locale;
    import javax.faces.context.FacesContext;
    import javax.faces.el.ValueBinding;
    import javax.faces.model.SelectItem;
    import oracle.adf.model.generic.DCGenericDataControl;
    import org.exolab.castor.xml.MarshalException;
    import org.exolab.castor.xml.ValidationException;
    public class ClassificationLanguageList {
    private java.util.List<SelectItem> supportedLanguages = new ArrayList();
    public ClassificationLanguageList() throws FileNotFoundException,
    MarshalException,
    ValidationException {
    FacesContext ctx = FacesContext.getCurrentInstance();
    ValueBinding vb = ctx.getApplication().createValueBinding("#{data.ClassificationDocumentDataControl}");
    DCGenericDataControl classificationDocumentDataControl = (DCGenericDataControl)vb.getValue(ctx);
    ClassificationDocument classificationDocument = (ClassificationDocument)classificationDocumentDataControl.getDataProvider();
    ClassificationLanguage[] classificationLanguage = classificationDocument.getClassification().getClassificationLanguageList().getClassificationLanguage();
    for (int counter = 1; counter < classificationLanguage.length; counter++) {
    SelectItem language = new SelectItem();
    language.setValue(classificationLanguage[counter].getClassificationLanguageCode());
    language.setLabel(classificationLanguage[counter].getClassificationLanguageLabel());
    supportedLanguages.add(language);
    public void setSupportedLanguages(java.util.List<SelectItem> supportedLanguages) {
    this.supportedLanguages = supportedLanguages;
    public java.util.List<SelectItem> getSupportedLanguages() {
    return supportedLanguages;
    }

  • How to set the value of process variables/payload using a managed bean?

    Hello,
    Someone can give me an example about how to set the values of a process payload in a managed bean?
    thank you!

    Try this:
    jsf page:
    <af:selectOneChoice label="Select Suburb"
    requiredMessageDetail="Select a suburb"
    valueChangeListener="#{selectOneChoiceBean.onValueChanged}"
    validator="#{selectOneChoiceBean.validate}"
    unselectedLabel="None" autoSubmit="true"
    binding="#{selectOneChoiceBean.selectOneChoice}"
    value="#{selectOneChoiceBean.value}">
    <f:selectItems value="#{selectOneChoiceBean.selectionList}"/>
    </af:selectOneChoice>
    backing bean:
    public class SelectChoiceBean {
    private List<SelectItem> selectionList;
    private String value = "B";
    private RichSelectOneChoice selectOneChoice;
    public SelectChoiceBean() {
    initSelectionList();
    public void setSelectionList(List<SelectItem> selectionList) {
    this.selectionList = selectionList;
    public List<SelectItem> getSelectionList() {
    return selectionList;
    public void onValueChanged(ValueChangeEvent valueChangeEvent) {
    System.out.println(valueChangeEvent.getNewValue());
    // Add event code here...
    public void validate(FacesContext facesContext, UIComponent uIComponent,
    Object object) {
    // Add event code here...
    private void initSelectionList() {
    selectionList = new ArrayList<SelectItem>();
    selectionList.add(new SelectItem("A", "A label"));
    selectionList.add(new SelectItem("B", "B label"));
    selectionList.add(new SelectItem("C", "C label"));
    public void setValue(String value) {
    this.value = value;
    public String getValue() {
    return value;
    public void setSelectOneChoice(RichSelectOneChoice selectOneChoice) {
    this.selectOneChoice = selectOneChoice;
    public RichSelectOneChoice getSelectOneChoice() {
    return selectOneChoice;
    }

  • Query with bind variable, how can use it in managed bean ?

    Hi
    I create query with bind variable (BindControlTextValue), this query return description of value that i set in BindControlTextValue variable, how can i use this query in managed bean? I need to set this value in String parameter in managed bean.
    Thanks

    Put the query in a VO and execute it the usual way.
    If you need to, you can write a parameterized method in VOImpl that executes the VO query with the parameter and then call that method from the UI (as a methodAction binding) either through the managed bean or via a direct button click on the page.

Maybe you are looking for

  • HP 3210 All-in-One Printer and Vista

    Having trouble with HP 3210 All-in-One Printer/Scanner.  Purchased printer late 2006.  Upgraded to Vista in February 2008.  All functions of the Printer/Scanner have been working just fine with Vista until this month.  Error message says 'Unable to S

  • Web Enterprise Manager Default Port Number in Oracle 9i

    Enabeling Auditing on database 9.2.0.8 Web Enterprise Manager Default Port Number in Oracle 9i: Does anyone know the default port number of the web enterprise manager (Oracle 9i)? If I installed or configured enterprise manager and I forgot the port,

  • ATV2 kicking other devices offline

    I've read threads about ATVs that disconnect themselves after sleep, but that's not my problem. I have a new ATV2 that effectively shuts down the internet for any other device on the network when it's in use, actually requiring a physical reboot of t

  • Modifying default "Inspectors"/"HUD" tools?

    I always want sharpening, noise, and shadow highlight opened. Is there somewhere to modify the default appearance of the inspector and/or HUD? By the way, what does "^s" mean? I have tried every combination of keyboard modifiers I could think of and

  • CS5 Encode Failure

    I have CS5 installed on my computer.  I am in the process of trying to burn a DVD for a presentation that I must give the first week in August, 2013.  I have rendered and assembled my Adobe Premiere *.prproj and it runs well.  When I "dynamic link" i