The name of this question is “three JSF questions”
Hello and Thank you in advance for any assistance.


System info:

Netbeans,MySQL,glassfish

The Purpose of this post is:

have someone look at the excel file (subscribe_app_notes2)at :

http://cid-b5cb457363230793.skydrive.live.com/browse.aspx/Public


The functionality of this code is:

I have the whole package I am creating (pseudo code) stated there along with 3 questions I am presently trying to figure out.

My question is:

One: I am using MySQL and the tutorial I am studying uses Oracle so I need to resolve the resource tag?

Two: My web.xml is different from the one presented in the tutorial. Could someone point out what needs to be added or changed to get it to work with my project?

Three: One of my classes (TopLinkSubscriberDAO.java) is using imports related to Oracle. I am exploring oracle to resolve this. Is anyone able to explain how to resolve errors in this class?

The errors related to this code are:


Code description:

Thanks again.
-ceyesumma

Note: If you are note willing to look at the exel file that is understandable. I just use it to present every single aspect of the project I am trying to build.
………………………………………………………………………………………………

Code description

The name of this question is revised “three JSF questions”
Hello and Thank you in advance for any assistance.


System info:

Netbeans,MySQL,glassfish
Studing tutorial at:
http://www.oracle.com/technology/pub/articles/cioroianu_jsfdb.html
note: hopefully this link is still good.


The Purpose of this post is:

to understand how to resolve with a class with links to oracle toplink DAO and if it is possible to use MySQL databade as apposed to an Oracle database.

The functionality of this code is:

add data to database with JSF

My question is:

One: I am using MySQL and the tutorial I am studying uses Oracle so I need to resolve the resource tag?

Code description: web.xml from the tutorial

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app PUBLIC
    "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

    <context-param>
        <param-name>adminEmail</param-name>
        <param-value>admin@localhost</param-value>
    </context-param>

    <context-param>
        <param-name>javax.servlet.jsp.jstl.sql.dataSource</param-name>
        <param-value>jdbc/OracleDS</param-value>
    </context-param>

    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>

    <servlet>
        <servlet-name>FacesServlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>FacesServlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>
<resource-ref>
        <res-ref-name>jdbc/OracleDS</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

</web-app>

Two: My web.xml is different from the one presented in the tutorial. Could someone point out what needs to be added or changed to get it to work with my project?

Code description: My present web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <context-param>
        <param-name>com.sun.faces.verifyObjects</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>com.sun.faces.validateXml</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>subscribe/welcomeJSF.jsp</welcome-file>
        </welcome-file-list>
    </web-app>

Three: One of my classes (TopLinkSubscriberDAO.java) is using imports related to Oracle. I am exploring oracle to resolve this. Is anyone able to explain how to resolve errors in this class?

Code description: TopLinkSubsriberDAO.java oracle imports

package jsfdb.model.dao;

import jsfdb.model.LoginInfo;
import jsfdb.model.Subscriber;
import jsfdb.model.ModelUtils;
import jsfdb.model.err.IncorrectPasswordException;
import jsfdb.model.err.LoginException;
import jsfdb.model.err.ProfileException;
import jsfdb.model.err.SubscribeException;
import jsfdb.model.err.UnknownSubscriberException;
import jsfdb.model.err.UnsubscribeException;

import oracle.toplink.expressions.ExpressionBuilder;
import oracle.toplink.queryframework.ReadObjectQuery;
import oracle.toplink.sessions.Session;
import oracle.toplink.sessions.UnitOfWork;
import oracle.toplink.threetier.ClientSession;
import oracle.toplink.threetier.Server;
import oracle.toplink.tools.sessionmanagement.SessionManager;


Code description: TopLinkSubscriberDAO.java

package jsfdb.model.dao;

import jsfdb.model.LoginInfo;
import jsfdb.model.Subscriber;
import jsfdb.model.ModelUtils;
import jsfdb.model.err.IncorrectPasswordException;
import jsfdb.model.err.LoginException;
import jsfdb.model.err.ProfileException;
import jsfdb.model.err.SubscribeException;
import jsfdb.model.err.UnknownSubscriberException;
import jsfdb.model.err.UnsubscribeException;

import oracle.toplink.expressions.ExpressionBuilder;
import oracle.toplink.queryframework.ReadObjectQuery;
import oracle.toplink.sessions.Session;
import oracle.toplink.sessions.UnitOfWork;
import oracle.toplink.threetier.ClientSession;
import oracle.toplink.threetier.Server;
import oracle.toplink.tools.sessionmanagement.SessionManager;

public class TopLinkSubscriberDAO implements SubscriberDAO {
    private Server serverSession;

    public TopLinkSubscriberDAO() {
        SessionManager manager = SessionManager.getManager();
        String id = ModelUtils.getResource("TopLinkSession");
        ClassLoader loader = this.getClass().getClassLoader();
        serverSession = (Server) manager.getSession(id, loader);
        Runtime.getRuntime().addShutdownHook(new Thread() {
            public void run() {
                serverSession.logout();
                SessionManager.getManager().getSessions().remove(
                    ModelUtils.getResource("TopLinkSession"));
            }
        });
    }

    private ClientSession acquireClientSession() {
        return serverSession.acquireClientSession();
    }

    private UnitOfWork acquireUnitOfWork() {
        return acquireClientSession().acquireUnitOfWork();
    }

    private Subscriber read(Session session, String email) {
        ReadObjectQuery query
            = new ReadObjectQuery(Subscriber.class);
        ExpressionBuilder builder = new ExpressionBuilder();
        query.setSelectionCriteria(builder.get("email").equal(email));
        return (Subscriber) session.executeQuery(query);
    }

    public Subscriber select(LoginInfo loginInfo)
            throws LoginException,
            UnknownSubscriberException,
            IncorrectPasswordException {
        Subscriber s = null;
        try {
            ClientSession session = acquireClientSession();
            s = read(session, loginInfo.getEmail());
        } catch (Exception x) {
            ModelUtils.log(x);
            throw new LoginException();
        }
        if (s == null)
            throw new UnknownSubscriberException();
        if (!s.getPassword().equals(loginInfo.getPassword()))
            throw new IncorrectPasswordException();
        return s;
    }

    public void insert(Subscriber subscriber)
            throws SubscribeException {
        try {
            UnitOfWork uow = acquireUnitOfWork();
            Subscriber s = new Subscriber();
            ModelUtils.copy(subscriber, s);
            uow.registerObject(s);
            uow.commit();
        } catch (Exception x) {
            ModelUtils.log(x);
            throw new SubscribeException();
        } }

    public void update(Subscriber subscriber)
            throws ProfileException {
        try {
            UnitOfWork uow = acquireUnitOfWork();
            Subscriber s = read(uow, subscriber.getEmail());
            ModelUtils.copy(subscriber, s);
            uow.commit();
        } catch (Exception x) {
            ModelUtils.log(x);
            throw new ProfileException();
        }
    }

    public void delete(Subscriber subscriber)
            throws UnsubscribeException {
        try {
            UnitOfWork uow = acquireUnitOfWork();
            Subscriber s = read(uow, subscriber.getEmail());
            uow.deleteObject(s);
            uow.commit();
        } catch (Exception x) {
            ModelUtils.log(x);
            throw new UnsubscribeException();
        }
    }

}


The errors related to this code are:


Code description:

Thanks again.
-ceyesumma

Note: If you are note willing to look at the exel file that is understandable. I just use it to present every single aspect of the project I am trying to build.
………………………………………………………………………………………………

Code description

It seems the only option is to declare the JDBC\datasorce an use the standard jdbc api. Oracle will have to wait
thanks

I guess the oracle program just generates code using the GUI.

It works fine with the entitymanger.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.