About managed beans and

I'm trying a JSF code similar to:
<li>Number:<h:inputText value="#{contract.pk.number}" required="true" id="pk_number" /></li>
<li>Alias:<h:inputText value="#{contract.pk.alias}" required="true" id="pk_alias" /></li>The contract bean is similar to:
public class Contract implements Serializable {
    @EmbeddedId
    private Contract.PK pk;
    @Embeddable
    public static class PK implements Serializable {
        private String number;
        private String alias;
        public String getNumber() { return this.number; }
        public void setNumber(String sNumber) {...}
        public String getAlias() { return this.alias; }
        public void setAlias(String sAlias) {...}
}        The java code is generated automatically by Dal� (http://www.eclipse.org/dali/) and I can modify it as needed, while the database squema is out of my control.
I get stuck with next problem:
Whatever I input into my form a "conversion error" is returned for the pk members.
Thanks in advance for any help, hint or link!

I checked get/setPk were correctly defined. Still the problem persisted.
After tracing the error I found that getPk returns null, so I just added a dummy initializer for pk after which it all works correctly (myfaces implementation bug probably??? ). Just for anyone interested the working code looks like:
public class Contract implements Serializable {
    @EmbeddedId
    private Contract.PK pk = new Contract.PK();  // <- new Contract.PK() avoid the conversion error (null pointer exception).
    @Embeddable
    public static class PK implements Serializable {
        private String number;
        private String alias;
        public String getNumber() { return this.number; }
        public void setNumber(String sNumber) {...}
        public String getAlias() { return this.alias; }
        public void setAlias(String sAlias) {...}
}   

Similar Messages

  • Managed Beans and Data Access Object

    I have a question / need help understanding how to configure backing bean and model objects so that memory and object creation/deletion is done as efficiently as possible.
    1. I have a .jsf page with a form and a commandbutton that submits the form inputs to a backing bean (enrollispbean is backing bean)
    <h:commandButton value="Enter" action="#{enrollispbean.insert}"/>
    2. The backing bean is used for form handling - the insert() method is used to read the data fields from the form and create a SQL string that will be submitted to a model object, DbInsert, that is used as a generic data access object that connects to the database and insert the SQL string:
    public class EnrollIspBean {
    private String beanvar1="";
    private String beanvar2= "";
    // DbInsert is data access object
    private DbInsert dbinsert = new DbInsert();
    public String insert (){
    String sqlstmt;
    sqlstmt = "INSERT INTO ispmain VALUES(beanvar1, beanvar2,..)"
    dbinsert.insert(sqlstmt);
    return "success"; }
    3. DbInsert is the data access object that contains a method, insert(), that accepts a sql string to insert into the database. This method contains the code to obtain a connection from the database connection pool and then execute the sql statement (note: error checking code not shown):
    public class DbInsert {
    public void insert(String sqlstmt) throws SQLException {
    Connection conn = null;
    GetDBConnection getdbconnection = new GetDBConnection();
    PreparedStatement stmt = null;
    conn = getdbconnection.getdbconn();
    stmt = conn.prepareStatement(sqlstmt);
    stmt.executeUpdate();
    stmt.close();
    conn.close();
    return;
    Where I need help understanding is how to set up the scope for the managed beans and data access object. Currently, I have the backing bean within the session scope (using the facesconfig.xml file). My main question is how to set up the scope for the Data Access Object - currently I do not have it as a managed bean within facesconfig.xml. Instead I am creating a new instance within the backing bean:
    private DbInsert dbinsert = new DbInsert();
    Is this the best way to do this? Will the DBInsert object now be tied to the session scope of the backing bean (i.e., when backing bean is deleted, the DbInsert object will be deleted from session scope as well.)
    Ideally I would like the data access object to be available as a shared object throughout the life of the application. When I was programming using a servlet approach, I would have created a servlet to load on startup. Now that I'm using java server faces, I'm confused about the scope / how to efficiently set up a data access object that I want to be available to all backing beans in the application.
    tnanks for any help understanding this.
    Tom

    I was thinking about setting the data access object as application scope so that it can be used by an backing bean to execute sql statements.
    If I do set it as application scope, however, if I do this, do I still need to declare a new instance of the object from within each bean that uses the object?
    For example do I need to declare a new instance of the data access object from within the bean? or, should I assume that there is always an instance of the bean available in the application scope, and if so, how do I reference it from within the bean?
    Bean Code:
    public class EnrollIspBean {
    // DbInsert is data access object
    private DbInsert dbinsert = new DbInsert();
    Finally, I understand performance may be an issue if I have one instance of the data access object available in the application scope - is there a way to make multiple instances available in the application scope?
    thanks

  • 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

  • Pageless Managed beans and operation bindings, design question

    Hi,
    I am using ADF Faces and ADF BC and JDev 10.1.3.
    I want to declaratively execute an operation binding from a managed bean which does not have a page definition.
    How can I create a page definition for a managed bean which will allow me to define and call operation bindings in the same way that you can in a backing bean?
    In the past I have used the binding layer to get references to the AM and then execute the client methods directly.
    How can I do this declaratively from a managed bean?
    regards,
    Brenden

    Hi Steve,
    a good example would be a managed bean which is used by many pages for provide dynamic page forwarding (using global forwards).
    The page forwarding is based on what data the user has selected and the entry tasklist will have pages added and removed based on the users entered information.
    At the moment I use references in the managed bean which get the binding context by evaluating #{data} to get a reference to the AM and directly call an client method, which calls a PL/SQL procedure and returns a global forward string. The AM is imported into the managed bean and methods called directly.
    This is just one example, but probably the best I can come up with for now.
    In a backing bean I can use an operation binding to call a method and get a result declaratively like this:
            BindingContainer bindings  = getBindings();
            OperationBinding operation = bindings.getOperationBinding("getUserByEmail");
            operation.getParamsMap().put("email", email);
            String userName = (String)operation.execute();whereas in a managed bean I have to get direct references to the AM to call the method directly.
    if there is a way to do this in the same way as backing beans it would seem a more abstracted and cleaner approach?
    regards,
    Brenden

  • Difference between a Managed Bean and Backing Bean

    hi
    i am new to JSF made my 1st appl today ...
    couldnt clearly understand difference between a Managed Bean and Backing Bean , anybody know the difference?
    Regards
    dsdsf

    These are two terms that means the same .... A backing bean is a normal web term, in JSF specifically it is termed as managed bean as this' backing bean' configurations in faces-config.xml are termed within 'managed-bean ' tags.
    Cutting the long story short its a bean class . period :)

  • Confusion about backing beans and multiple pages

    Hello:
    I'm new to JSF and am confused by several high level and/or design issues surrounding backing beans. The
    application I am working on (not unlike many apps out there, I suspect), is comprised of several forms which
    collect various query parameters and other pages that display the query results via dataTables. Additionally, the
    displayed results have hyper-text enabled content sprinkled throughout in order to allow further "drill-down" to
    greater details about a given result.
    Obviously, the initial forms are backed by a managed bean that has the getters/setters for each of the various
    fields. From a modularization perspective, I'd prefer to have the query execution in a separate class entirely,
    which I can accomplish via delegation or actionListeners. Where I get confused is in the case that one of the
    hyper-text enabled fields needs to invoke yet another query requiring specific values from the original result.
    In this case, how should I design the beans to store the pertinent selection information AND still be able to
    have the resulting 'details' query in a separate class.
    For example, let's assume that I have a form with a simple backing bean to collect initial query params. The user
    fills out the form and clicks on submit. The action field of the <h:commandButton> tag inside the <h:form>
    delegates to a method which performs the query and returns a navigation string to the results display page. The
    results page then uses a <h:dataTable> tag to display the results. However, through the process of displaying the
    results, it will create the hyper-text links as follows:
                        <h:form>
                            <h:commandLink action="viewDetails">
                                <h:inputHidden id="P_ID" value="#{results.id}"/>
                                <h:outputText value="Click here to see details"/>
                            </h:commandLink>
                        </h:form>Notice that the value="#{results.id}" is the key field (in some case I may need more than one) that the subsequent
    details page will need to perform the query. However, this value is stored in the results attribute of the original
    query backing bean. I do NOT want to add yet another level of queries into the same backing bean as I would like
    to keep the original and details query beans separated for maintenance and style reasons. How then, can I get this
    specific value ("#{results.id}") into another backing bean that could be accessed by the subsequent details page
    and query? In general, how does one map a single display element to multiple backing beans (or accomplish the
    effect of having one 'source' bean's value end up in another 'destination' bean's attr? If this is not possible,
    then isn't the details query/page forced to use the same backing bean in order to get the data it needs? If so,
    how can it determine which id was selected in this case?
    I'd appreciate any thoughts, ideas and suggestions here! Is there a better way to design the above in order to
    maintain the separation of logic/control? What is the 'best practice' approach for this sort of stuff?
    Thanks much in advance!

    This is what I have done in the pass
    <h:commandLink action="#{AppAction.getRecord}" >
    <h:outputText value="#{bbr.id}"/>
    <f:param name = "recordid" value ="#{bbr.id}" />
    </h:commandLink>
    within the getRecord method
    String key = "";
    FacesContext facesContext = FacesContext.getCurrentInstance();
         ServletContext servletContext = ServletContext)facesContext.getExternalContext().getContext();
    key = (String)facesContext.getExternalContext().getRequestParameterMap().get("recordid");
    then call you dbmethod passing in the key of the record the user wants to edit
    and then simply return a string to what page you want the user to go to
    I think this is what your looking for

  • About managed beans

    Dear Helper,
    I have a bean called UserBean.java and it has some properties like userId, userName, password and etc.
    The problem starts when i want to bind the JSF components like InputText and OutputText to the UserBean properties, the IDE automatically bind these components to the backing bean of the page, and when i modify the code in the source the IDE again recreate the modified line and bind it to its coresponded property in the backing bean.
    like the following
    <h:form binding="#{login.form1}" id="form1">
                        <h:outputText binding="#{login.outputText1}" id="outputText1" style="left: 312px; top: 216px; position: absolute" value="UserID:"/>
                        <h:inputText binding="#{test.UserBean.userID}" id="textField1" style="left: 360px; top: 216px; position: absolute" value="#{test.UserBean.userName}"/>
                       <h:commandButton action="Login" binding="#{test.UserBean.action}" id="button1" style="left: 360px; top: 264px; position: absolute" value="Submit"/>                
    <h:inputText binding="#{login.textField1}" id="textField1"/>
                        <h:commandButton binding="#{login.button1}" id="button1"/>
                    </h:form>I don't want the IDE to create a Page bean for each jsp page
    regards
    Ayman

    Hi Ayman,
    The Page bean Page1.java is an automatically created Managed bean. This contains the properties for the components you are using in the JSP page. This managed bean allows you to add code like the event handler methods or user defined initialization statements. This page bean is of request scope. So as is evident it is necesasry to have the page bean.
    I hope this helps.
    Cheers :-)
    Creator Team

  • JSF managed beans and xmlbeans

    Hi,
    I am having a jsf application,where I get data from a back end configuration service,which returns data in the form of xml,for which we already have compiled xmlbeans.At our side we recieve the response and parse it to get back the response.My question is- Is it advisable to use these xmlbeans within the jsf managed beans,or do we need to create pojos from the xmlbeans,before sending them to mbeans.Why I am asking such a question is-xmlbeans have a tight coupling with the backend
    Thanks
    -Bibin

    I would suggest have pojo's. Below are my points
    1) You man not need everything from the XMLBean always. Most of the times, you may need very little from the XMLBean. You can transfer the required information to the POJO. This would also save you from network overhead in case the backend is running on a separate machine.
    2) Any changes to the backend code will not have any impact on your UI code.

  • How to use remote managed bean and JPA in JSF

    Hi All,
    I am familiar with referencing backing-beans and JPA properties where Glassfish and MySQL is running locally. However, is it possible to lookup these same properties using JNDI if they reside on remote servers? If so, what change is needed?
    I would like to distribute the J2EE 5 application load including database by running Glassfish, MySQL on separate servers. This will put on the JSF (presentation-tier) components on it's own server while a secondary system will handle the middle tier processing and leaving the database activities to be carried out on another server. Not sure whether this is the right approach though. These hardware would run on both Solaris and Windows platforms.
    Unfortunately, buying faster hardware is not an option.
    Any assistance would be appreciated,
    Jack

    Hi Faissal,
    Is your suggestion below:
    //Lookup an EJB and use it
       YourRemoteBean bean = (YourRemoteBean ) ServiceLocator.findRemoteObject(jndiName); // ServiceLocator is a class that lookup
                                                                                                                                           //  the remote objectis equivalent to the following lines:
    Properties props = new Properties();
        props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
                props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
                props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
                // optional.  Defaults to localhost.  Only needed if web server is running
                // on a different host than the appserver   
                // props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
                props.setProperty("org.omg.CORBA.ORBInitialHost", "remoteServer");
                // optional.  Defaults to 3700.  Only needed if target orb port is not 3700.
                // props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
                InitialContext jndiContext = new InitialContext(props);     
                InitialContext jndiContext = new InitialContext();
                YourRemoteBean bean =  (YourRemoteBean) jndiContext.lookup("ejb.YourRemoteBean");Thanks,
    Jack

  • Confused about nonGUI beans and events

    The crux of this is the question "When will a NON GUI bean use events to communicate?"
    Articles I have read advocate that Beans are not just GUI components, and I agree. However I've only ever seen examples of GUI Beans!
    I am writing a non GUI Bean to represent a credit card.
    Before I got concerned with beans I would have just written the class with some accessor methods and some functional methods to do what I want, something like;
    void setCardNumber(String n)
    boolean isNumberValid() //check the card number using MOD10
    and then used that class in my application.
    But now I want to make it conform closer to JavaBeans. I know that beans have methods, but I am confused somewhat about how events figure into this. Do nonGUI beans fire events/listen for events? Very often?
    What I am asking is, what events should a Bean like CreditCard fire? The main function of this Bean is to determine if the number conforms to MOD10 checks using isNumberValid() method.
    Consider that I want to write another Bean, a GUI component that takes card details and updates the nonGUI CreditCard Bean. Of course I want loose coupling, not every user will use my CreditCard Bean (especially if I dont get these events straight!). If I use property change events to fill in the card number etc in the CreditCard Bean, should I make it (the CreditCard bean) listen for focusLost events from the interface to determine when all the details have been filled in and fire an event about the validity of the card number?? Doesn't this break the rules a bit, by providing prior knowledge to the CreditCard nonGUI Bean??
    Should the CreditCard nonGUI bean fire an event to say that the number is valid/invalid?
    You will probably say, "WHY use events, when you only need methods?" and that is my question! When would a non GUI bean fire or listen to events? I want my non GUI bean to be completely ignorant of GUI stuff, so no focusLost listener.
    Should the credit card interface fire a custom event (CardDetailsEnteredEvent) and the non GUI bean listen for these? But that's tighter coupling than just implementing the methods isn't it?
    I think that the nonGUI bean will have property change listeners for the card number etc, but this begs the question, what is the point of setter methods if I am bound the properties anyway??
    I've read everything pertinent at http://java.sun.com/products/javabeans/training.html
    Thanks to anyone who can stop my head hurting.
    Jim

    Ah, I think I may have figured it out from the spec.
    "Conceptually, events are a mechanism for propagating state change notifications between a
    source object and one or more target listener objects."
    key phrase being "state change" - my non GUI bean CreditCard only really has two states; 1. incomplete card details and 2. complete card details. So I guess I could/should only fire an event (DetailsEntered) when the details are completely 'filled in'.
    Which leaves me with the GU interface bean, it has two states also, 1. details being edited (focus gained) and 2. details finished being edited (focus lost) - should then this bean fire its own event (DetailsEdited) or should it just rely on other beans listening for the focus lost event? It's my functional interpretation that a focus lost event signifies that the details have been edited, perhaps I should therefore implement my own event that has this contextual meaning (DetailsEdited).
    I'm aware that the names of these events are quite poor, I always find good naming to be another very important head scratcher!!
    Jim

  • Best practices for Manage beans and Navigation flow

    Hi,
    I have the following scenarios along with the possible solutions. I need confirmation from JSF experts, which is recommended way of doing it.
    Scenario
    I need to show a list of item from database/config file to the user. User will select the show details from the menu and the details page will be shown with list of items.
    User - > Menu - >Show Details -> Details Page.
    Components
    DetailsBean.java
    menu.jsp
    Details.jsp
    Solution 1:
    a) When user click show details, call DetailsBean.populate(),
    b) DetailsBean.populate() method populate list from DB, store it as a property in it and returns the String for next flow
    c) User will be navigated to the Details.jsp using the <from-outcome> for menu.jsp.
    d) Details.jsp will read the property from DetailsBean() to show the list of items on page.
    Solution 2
    a) When user click show details, navigate user to the Details.jsp.
    b) Details.jsp is tied with the DetailsBean.populate() method , will get the list and print the page.
    I am little confused which one to be used and when ?. Are there any scenarios where we need to use specifically solution 1 , any sometimes specifically solution 2?
    In Brief
    *" Should we populate bean first and let the jsp page, just draw what ever is there in the bean, without thinking much about how the bean get populated"*
    or
    *"Should we let JSP to call methods on bean, get contents directly and show to user, no need to store in bean."*
    Let me know, my you need more information about my question.
    Expecting an quick reply on this.
    Thanks,
    Sudhir

    In real world, I never use navigation cases. I always declare action methods void (or return null, if you want). I just show results at the same page, if necessary with help of the 'rendered' attribute. And then for plain page-to-page navigation I just use GET all the way using h:outputLink or plain HTML <a> elements, but not with commandLinks. Finally it's all much better for the User Experience.

  • About java beans and jsps

    hi,
    can anybody tell me is it good use only jsp for presentation and business logic.
    in terms of perfomence wise is it good practice.
    regards,
    sam

    I think you had better to write in a beans.otherwise,the work of maintenance will be difficult.

  • Structure of managed beans

    Hi All,
    I read a lot about managed beans and thought I understood how they are supposed to be used, but now I've seen some forum posts which makes me doubt whether what I'm doing is the correct way of doing things. I have a wizard-like sequence in my JSF application consisting of 3 pages in which each page requests additional information on an entity, for example:
    Page 1 - Provide company name and description
    Page 2 - Link employees to company
    Page 3 - Set company status and commit
    As I understand managed beans, I would use a request-scoped bean for each of the pages to handle basic page processing and provide getter/setters, and a session-scoped bean to store the Company entity so that it can be accessed from each request-scoped bean. Now, however, from what I've read on the forums it seems as if I should not use a session-scoped bean in this instance, but rather make use of one request-scoped bean and map all three pages to it?
    Which way is the correct way?
    Thank you,
    Ristretto

    Which way is the correct way?Depends on the functional requirements. The first way you described is good and easy to achieve. The second way is harder to achieve. You should pass al before entered values through all subsequent requests in hidden input elements. In such case a session scoped bean may come more in handy.
    You can decide to use only one session scoped bean with all form data and form actions in it. You can also decide to use one session scoped bean for saved form data and use separate request scoped beans for the form data and form action per page and inject the session scoped bean in each of them using managed-property facility of faces-config.xml.

  • ADF Faces and BC: Scope problem with managed bean

    Hi,
    I am using JDev 10.1.3 and ADF Faces with ADF BC.
    I have created a managed bean which needs to interact with the binding layer and also receive actions from the web pages. I have a managed property on the bean which is defined as follows:
    <managed-bean>
        <managed-bean-name>navigator</managed-bean-name>
        <managed-bean-class>ecu.ethics.view.managed.Navigator</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
        <managed-property>
          <property-name>bindings</property-name>
          <value>#{bindings}</value>
        </managed-property>
      </managed-bean>I need the been to session scope because it needs to keep previous and next pages to navigate the user through their proposal. If i use session scope (as above) i get the following error when i click on a comand link which references a method in the above bean: #{navigator.forwardNext_action} which returns a global forward.
    this is the exception:
    javax.faces.FacesException: #{navigator.forwardNext_action}:
    javax.faces.el.EvaluationException: javax.faces.FacesException:
    javax.faces.FacesException: The scope of the referenced object: '#{bindings}' is shorter than the referring object     at
    com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:78)     at
    oracle.adf.view.faces.component.UIXCommand.broadcast(UIXCommand.java:211) at
    javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)at
    javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)     at
    com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)     at
    com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)     
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)     at
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)how can i get around this?
    Brenden

    Hi pp,
    you need to create a managed (not backing) been set to session scope.
    You can call/reference the managed bean from your page.
    the backing bean is designed around a page lifecyle which is request oriented in it's design.
    This is a simple managed bean from faces-config.xml
    <managed-bean>
        <managed-bean-name>UserInfo</managed-bean-name>
        <managed-bean-class>ecu.ethics.admin.view.managed.UserInfo</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
          <managed-property>
          <property-name>bindings</property-name>
          <property-class>oracle.adf.model.BindingContext</property-class>
          <value>#{data}</value>
        </managed-property>
      </managed-bean>and the getters and setters for bindings in your session scope managed bean:
        public void setBindings(BindingContext bindings) {
            this._bindings = bindings;
        public BindingContext getBindings() {
            return _bindings;
        }you can access the model from the managed bean using the the BindingContext if needed.
    also have a look at JSFUtils from the ADF BC SRDemo application, there are methods in this class such as resolveExpression which demonstrate how to get the values of items on your page programatically using expression language. You can use this in your managed bean to get values from your pages.
    regards,
    Brenden

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

Maybe you are looking for