[EJB/JBoss] - Emergency for help!
by Arklis
Deveoplement environment:
JBoss 3.2.5 + jre 1.4.2 + Ejb 2.0 + MySQL 5.0
Issue: I wrote a BMP entitybean for query products by product nam, but I got the null and 0 values from the BMP entitybean with not error message in JBoss container. My code as follow.
1.package com.jatosoft.ejb.bmps;
import java.rmi.RemoteException;
import javax.ejb.EJBObject;
/**
* @author Administrator
* write a remote interface for client sides using
*/
public interface Product extends EJBObject {
public int getProductId()throws RemoteException;
public double getPrice()throws RemoteException;
public String getProductName()throws RemoteException;
public String getDescription()throws RemoteException;
}
2.package com.jatosoft.ejb.bmps;
import java.rmi.RemoteException;
import java.util.Enumeration;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
import javax.ejb.FinderException;
/**
* @author Administrator write a remote home interface to create an remote
* interface for client sides call
*/
public interface ProductHome extends EJBHome {
public Product create(int productId, String productName,
String description, double price) throws RemoteException,
CreateException;
public Product findByPrimaryKey(ProductPK key) throws RemoteException,
FinderException;
public Enumeration findByName(String name) throws RemoteException,
FinderException;
}
3.package com.jatosoft.ejb.bmps;
import java.io.Serializable;
public class ProductPK implements Serializable {
public String productId;
public ProductPK() {
// TODO Auto-generated constructor stub
}
public ProductPK(String productId) {
this.productId = productId;
}
public boolean equals(Object o){
return ((ProductPK)o).productId.equals(productId);
}
public int hashCode(){
return productId.hashCode();
}
public String toString(){
return productId;
}
}
4. package com.jatosoft.ejb.bmps;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Enumeration;
import java.util.Vector;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.FinderException;
import javax.ejb.ObjectNotFoundException;
import javax.ejb.RemoveException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class ProductBean implements EntityBean {
private EntityContext ctx;
int productId;
String productName;
String description;
double price;
public ProductPK ejbCreate(int productId, String productName,
String description, double price) throws RemoteException,
CreateException {
this.dbgPrint("ejbCreate()");
//receive the parameter from client sides
this.productId = productId;
this.productName = productName;
this.description = description;
this.price = price;
//connect with database
Connection con = null;
PreparedStatement ps = null;
con = this.getConnection();
//insert values into the database
String sql = "insert into products(productId,productName,description,price) values"
+ "(?,?,?,?)";
try {
ps = con.prepareStatement(sql);
ps.setInt(1,this.productId);
ps.setString(2,this.productName);
ps.setString(3,this.description);
ps.setDouble(4,this.price);
ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(ps != null){
try {
ps.close();
if (con != null)
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return new ProductPK(Integer.toString(productId));
}
public void ejbPostCreate(int productId, String productName,
String description, double price) throws RemoteException,
CreateException {
this.dbgPrint("ejbPostCreate()");
}
/**
* @param primaryKey
* @return
* @throws RemoteException
* @throws FinderException
* implement the findByPrimaryKey() method in the remote home interface
*/
public ProductPK ejbFindByPrimaryKey(ProductPK primaryKey)throws RemoteException,FinderException{
this.dbgPrint("ejbFindByPrimaryKey()");
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
String sql = "select productName from products where productId=?";
int productId = Integer.parseInt(primaryKey.productId);
con = this.getConnection();
try {
ps = con.prepareStatement(sql);
ps.setInt(1, productId);
rs = ps.executeQuery();
if (rs.next()){
rs.close();
ps.close();
con.close();
return primaryKey;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
this.dbgPrint(e.toString());
}finally{
try{
if (rs != null)
rs.close();
if (ps != null)
ps.close();
if (con != null)
con.close();
}catch(Exception e){
e.printStackTrace();
}
}
throw new ObjectNotFoundException();
}
/**
* @param name
* @return
* @throws RemoteException
* @throws FinderException
* implement findByName() method in the remote home interface
*/
public Enumeration ejbFindByName(String name)throws RemoteException,FinderException{
this.dbgPrint("ejbFindByName()");
Vector products = new Vector();
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try{
String sql = "select productId from products where productName=?";
con = this.getConnection();
ps = con.prepareStatement(sql);
ps.setString(1, name);
rs = ps.executeQuery();
while(rs.next()){
int productId = rs.getInt(1);
products.addElement(new ProductPK(Integer.toString(productId)));
}
}catch(Exception e){
this.dbgPrint(e.toString());
}finally{
try{
if (rs != null)
rs.close();
if (ps != null)
ps.close();
if (con != null)
con.close();
}catch(Exception e){
this.dbgPrint(e.toString());
}
}
return products.elements();
}
/**
* @return
* retrieve the connection with database
*/
protected Connection getConnection(){
String dbUrl = null;
String userName = null;
String password = null;
Context initialContext = null;
Context environment = null;
Connection connection = null ;
try {
initialContext = new InitialContext();
environment = (Context) initialContext.lookup("java:comp/env");
dbUrl = (String) environment.lookup("dbUrl");
userName = (String)environment.lookup("dbUserName");
password = (String)environment.lookup("dbPassword");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
this.dbgPrint(e.toString());
}
try {
connection = DriverManager.getConnection(dbUrl,userName,password);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
this.dbgPrint(e.toString());
}
return connection;
}
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
dbgPrint("ejbActivate()");
}
public void ejbLoad() throws EJBException, RemoteException {
// TODO Auto-generated method stub
dbgPrint("ejbLoad()");
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try{
String sql = "select productName,description, price from products where productId=?";
con = this.getConnection();
ps = con.prepareStatement(sql);
ps.setInt(1, this.productId);
rs = ps.executeQuery();
if (rs.next()){
this.productName = rs.getString(1);
this.description = rs.getString(2);
this.price = rs.getDouble(3);
}
}catch(Exception e){
this.dbgPrint(e.toString());
}finally{
try{
if (rs != null)
rs.close();
if (ps != null)
ps.close();
if (con != null)
con.close();
}catch(Exception e){
this.dbgPrint(e.toString());
}
}
}
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
dbgPrint("ejbPassivate()");
}
public void ejbRemove() throws RemoveException, EJBException,
RemoteException {
// TODO Auto-generated method stub
dbgPrint("ejbRemove()");
Connection con = null;
PreparedStatement ps = null;
try{
String sql = "delete from products where productId=?";
ProductPK key = (ProductPK)ctx.getPrimaryKey();
con = this.getConnection();
int productId = Integer.parseInt(key.productId);
ps = con.prepareStatement(sql);
ps.setInt(1, productId);
ps.executeUpdate();
}catch(Exception e){
this.dbgPrint(e.toString());
}finally{
try{
if (ps != null)
ps.close();
if (con != null)
con.close();
}catch(Exception e){
this.dbgPrint(e.toString());
}
}
}
public void ejbStore() throws EJBException, RemoteException {
// TODO Auto-generated method stub
Connection con = null;
PreparedStatement ps = null;
try{
String sql = "update products set productName=?, description=?, price=?"
+ " where productId=?";
con = this.getConnection();
ps = con.prepareStatement(sql);
ps.setString(1, this.productName);
ps.setString(2, this.description);
ps.setDouble(3,this.price);
ps.setInt(4, productId); //don not forget this parameter???
ps.executeUpdate();
}catch(Exception e){
this.dbgPrint(e.toString());
}finally{
try{
if (ps != null)
ps.close();
if (con != null)
con.close();
}catch(Exception e){
this.dbgPrint(e.toString());
}
}
}
public void setEntityContext(EntityContext arg0) throws EJBException,
RemoteException {
// TODO Auto-generated method stub
this.ctx = arg0;
dbgPrint("setEntityContext()");
}
public void unsetEntityContext() throws EJBException, RemoteException {
// TODO Auto-generated method stub
this.ctx = null;
dbgPrint("unsetEntityContext()");
}
public String getDescription() {
dbgPrint("getDescription()");
return description;
}
public double getPrice() {
dbgPrint("getPrice()");
return price;
}
public int getProductId() {
dbgPrint("getProductId()");
return productId;
}
public String getProductName() {
dbgPrint("getProductName()");
return productName;
}
/**
* @param temp
* write a debug method for later use
*/
private void dbgPrint(String temp) {
System.out.println(temp);
}
public void setDescription(String description) {
this.description = description;
}
public void setPrice(double price) {
this.price = price;
}
public void setProductId(int productId) {
this.productId = productId;
}
public void setProductName(String productName) {
this.productName = productName;
}
}
5. Client test code is as following
package com.jatosoft.ejb.bmp.tester;
import java.util.Enumeration;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import com.jatosoft.ejb.bmps.Product;
import com.jatosoft.ejb.bmps.ProductHome;
/**
* @author Administrator
* write a bmp entitybean tester
*/
public class BMPTester {
public static void main(String[] args){
BMPTester tester = new BMPTester();
tester.testBMP();
}
/**
* write e method for tester ejbs
*/
public void testBMP(){
//initial the jndi
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.PROVIDER_URL, "localhost:1099");
try{
//1. get the initial context
InitialContext jndiContext = new InitialContext(properties);
//2. get a reference to the bean
Object ref = jndiContext.lookup("BMPProduct");
this.dbgPrint("Got reference");
//3. get a refernce from this to the bean's home interface
ProductHome home = (ProductHome)PortableRemoteObject.narrow(ref,ProductHome.class);
//4. create an interest object from the home interface
// home.create(16, "Franklin Spring Water", "400ml", 2.25);
// home.create(17, "Franklin Spring Water", "600ml", 3.25);
// home.create(18,"Choco Bar", "Chocoloate Bar 200g", 2.96);
// home.create(19,"Timtim Biscuit","Biscuit w. mint flavor, 300g",9.25);
Product product = home.create(20,"Supermine","Instant Noodle",1.05);
product.remove();
Enumeration enumeration = home.findByName("Franklin Spring Water");
while(enumeration.hasMoreElements()){
this.dbgPrint("The enumeration has more elements is " + enumeration.hasMoreElements());
product = (Product) enumeration.nextElement();
this.dbgPrint("The product is " + product);
this.dbgPrint("Id: " + product.getProductId());
this.dbgPrint("Product Name: " + product.getProductName());
this.dbgPrint("Description: " + product.getDescription());
this.dbgPrint("Price: " + product.getPrice());
}
}catch(Exception e){
}
}
/**
* @param temp
* write a debug method for later use
*/
private void dbgPrint(String temp){
System.out.println(temp);
}
}
What's wrong with my code. Please help me!
Thank you!
Arklis Zeng
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3976818#3976818
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3976818
19 years, 7 months
[JBoss Seam] - Populating Lookup Column in JSF Table using Seam
by johnurban
I have a jsf datatable thats maps to a personlist list of person objects. While displaying the list of person objects I need to lookup a special attendance code in another table. I am thinking the best way is to call a method the PersonFinderBean called getSecurityCode(). This will go "lookup" the securitycode in the attendance table given the person ID.
I have posted the JSF and SFSB. My question is this the correct way of doing this in Seam?
uPersonCheckin.jsp
| <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
| <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
| <f:view>
| <f:loadBundle basename="messages" var="msg"/>
| <head>
|
| <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
| <title>Kidslife Checkin</title>
| <style type="text/css" media="all">
| @import "style/default/screen.css";
| </style>
| </head>
| <body>
|
| <%@ include file="header.htm" %>
|
| <h:form>
|
| <div class="rvgFind">
| <fieldset class="rvgFieldSet">
| <legend><h:outputText value="#{msg.Person} #{msg.SearchCriteria}"/></legend>
|
| <span class="rvgInputs">
| <h:outputLabel value="#{msg.Person_firstName}" for="firstName">
| <h:inputText value="#{personFinder.example.firstName}" id="firstName"/>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_lastName}" for="lastName">
| <h:inputText value="#{personFinder.example.lastName}" id="lastName"/>
| </h:outputLabel>
| </span>
|
| <span class="rvgActions">
| <h:commandButton type="submit" value="#{msg.Clear}" action="#{personFinder.clear}"/>
| <h:commandButton type="submit" value="#{msg.Find}" action="#{personFinder.findFirstPage}"/>
| </span>
|
| </fieldset>
| </div>
|
| <div class="rvgResults">
|
| <span class="rvgResultsNone">
| <h:outputText value="#{msg.EnterSearchCriteria}" rendered="#{personList==null}"/>
| <h:outputText value="#{msg.No} #{msg.Person} #{msg.MatchedSearchCriteria}" rendered="#{personList.rowCount==0 && !personFinder.previousPage}"/>
| </span>
|
| <h:dataTable value="#{personList}" var="person" rendered="#{personList.rowCount>0}"
| rowClasses="rvgRowOne,rvgRowTwo" headerClass="rvgOrder">
| <h:column>
| <f:facet name="header">
| <h:outputText value="Edit"/>
| </f:facet>
| <h:commandLink value="profile" action="#{personFinder.edit}">
| <f:param name="id" value="#{id}"/>
| </h:commandLink>
| </h:column>
| <h:column>
| <f:facet name="header">
| <h:outputText value="Register"/>
| </f:facet>
| <h:commandLink value="checkin" action="#{personFinder.checkIn}">
| <f:param name="id" value="#{id}"/>
| </h:commandLink>
| </h:column>
| <h:column>
| <f:facet name="header">
| <h:outputText value="Security Code"/>
| </f:facet>
| <h:outputText value="#{personFinder.securityCode}"/>
| </h:column>
| <h:column>
| <f:facet name="header">
| <h:commandLink value="#{msg.Person_firstName}" action="#{personFinder.reorder}">
| <f:param name="orderBy" value="firstName"/>
| </h:commandLink>
| </f:facet>
| <h:outputText value="#{person.firstName}"/>
| </h:column>
| <h:column>
| <f:facet name="header">
| <h:commandLink value="#{msg.Person_middleName}" action="#{personFinder.reorder}">
| <f:param name="orderBy" value="middleName"/>
| </h:commandLink>
| </f:facet>
| <h:outputText value="#{person.middleName}"/>
| </h:column>
| <h:column>
| <f:facet name="header">
| <h:commandLink value="#{msg.Person_lastName}" action="#{personFinder.reorder}">
| <f:param name="orderBy" value="lastName"/>
| </h:commandLink>
| </f:facet>
| <h:outputText value="#{person.lastName}"/>
| </h:column>
| </h:dataTable>
|
| <span class="rvgPage">
| <h:commandButton action="#{personFinder.findPreviousPage}" value="#{msg.PreviousPage}" disabled="#{!personFinder.previousPage}" />
| <h:commandButton action="#{personFinder.findNextPage}" value="#{msg.NextPage}" disabled="#{!personFinder.nextPage}" />
| <h:commandButton action="editPerson" value="#{msg.Create}" rendered="#{personSelector.createEnabled}"/>
| <h:commandButton action="#{personSelector.selectNone}" value="#{msg.SelectNone}" rendered="#{!personSelector.createEnabled}"/>
| <h:commandButton action="#{personSelector.cancel}" value="#{msg.Cancel}" rendered="#{!personSelector.createEnabled}"/>
| </span>
|
| </div>
|
| </h:form>
|
| </body>
| </f:view>
| </html>
|
PersonFinderBean
| package testSeam;
|
| // Generated Sep 23, 2006 1:30:01 PM by Hibernate Tools 3.2.0.beta7
|
| import static javax.ejb.TransactionAttributeType.NOT_SUPPORTED;
|
| import java.util.HashMap;
| import java.util.List;
| import java.util.Map;
| import java.util.Map.Entry;
| import java.util.Random;
| import java.util.Date;
| import javax.ejb.Remove;
| import javax.ejb.Stateful;
| import javax.ejb.TransactionAttribute;
| import javax.interceptor.Interceptors;
| import javax.persistence.EntityManager;
| import javax.persistence.Query;
| import org.jboss.seam.ScopeType;
| import org.jboss.seam.annotations.Destroy;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Out;
| import org.jboss.seam.annotations.Begin;
| import org.jboss.seam.annotations.End;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.RequestParameter;
| import org.jboss.seam.annotations.Scope;
| import org.jboss.seam.annotations.datamodel.DataModel;
| import org.jboss.seam.annotations.datamodel.DataModelSelection;
| import org.jboss.seam.ejb.SeamInterceptor;
|
| @Name("personFinder")
| @Stateful
| @Scope(ScopeType.SESSION)
| @Interceptors(SeamInterceptor.class)
| public class PersonFinderBean implements PersonFinder {
|
| private Person example = new Person();
|
| public Person getExample() {
| return example;
| }
|
| @DataModelSelection
| @Out(required=false)
| private Person selectedPerson;
|
| @In(required=false)
| private Login login;
|
| @In(create=true)
| private AttendanceEditor attendanceEditor;
|
| private int pageNumber = 0;
| private int pageSize = 20;
| private boolean registered = false;
|
| public void setRegistered(boolean value) {
| registered = value;
| }
|
| public boolean getRegistered() {
| return registered;
| }
|
| public void setPageSize(int size) {
| pageSize = size;
| }
|
| public int getPageSize() {
| return pageSize;
| }
|
| public boolean isPreviousPage() {
| return personList != null && pageNumber > 0;
| }
|
| public boolean isNextPage() {
| return personList != null && personList.size() == pageSize;
| }
|
| @DataModel
| private List<Person> personList;
|
| @In(create = true)
| private EntityManager entityManager;
|
| private void executeQuery() {
| Map<String, Object> parameters = new HashMap<String, Object>();
| StringBuffer queryString = new StringBuffer();
| if (example.getId() != 0) {
| queryString.append(" and person.id = :id");
| parameters.put("id", example.getId());
| }
| if (example.getRoomId() != 0) {
| queryString.append(" and person.roomId = :roomId");
| parameters.put("roomId", example.getRoomId());
| }
| if (example.getOrganizationId() != 0) {
| queryString.append(" and person.organizationId = :organizationId");
| parameters.put("organizationId", example.getOrganizationId());
| }
| if (example.getFirstName() != null && example.getFirstName().length() > 0) {
| queryString.append(" and person.firstName like :firstName");
| parameters.put("firstName", '%' + example.getFirstName() + '%');
| }
| if (example.getMiddleName() != null
| && example.getMiddleName().length() > 0) {
| queryString.append(" and person.middleName like :middleName");
| parameters.put("middleName", '%' + example.getMiddleName() + '%');
| }
| if (example.getLastName() != null && example.getLastName().length() > 0) {
| queryString.append(" and person.lastName like :lastName");
| parameters.put("lastName", '%' + example.getLastName() + '%');
| }
| if (example.getAddress1() != null && example.getAddress1().length() > 0) {
| queryString.append(" and person.address1 like :address1");
| parameters.put("address1", '%' + example.getAddress1() + '%');
| }
| if (example.getCity() != null && example.getCity().length() > 0) {
| queryString.append(" and person.city like :city");
| parameters.put("city", '%' + example.getCity() + '%');
| }
| if (example.getState() != null && example.getState().length() > 0) {
| queryString.append(" and person.state like :state");
| parameters.put("state", '%' + example.getState() + '%');
| }
| if (example.getZip() != null && example.getZip().length() > 0) {
| queryString.append(" and person.zip like :zip");
| parameters.put("zip", '%' + example.getZip() + '%');
| }
| if (example.getEmail() != null && example.getEmail().length() > 0) {
| queryString.append(" and person.email like :email");
| parameters.put("email", '%' + example.getEmail() + '%');
| }
| if (example.getBirthday() != null) {
| queryString.append(" and person.birthday = :birthday");
| parameters.put("birthday", example.getBirthday());
| }
| if (example.getSex() != null) {
| queryString.append(" and person.sex = :sex");
| parameters.put("sex", example.getSex());
| }
| if (example.getHomePhone() != null
| && example.getHomePhone().length() > 0) {
| queryString.append(" and person.homePhone like :homePhone");
| parameters.put("homePhone", '%' + example.getHomePhone() + '%');
| }
| if (example.getWorkPhone() != null
| && example.getWorkPhone().length() > 0) {
| queryString.append(" and person.workPhone like :workPhone");
| parameters.put("workPhone", '%' + example.getWorkPhone() + '%');
| }
| if (example.getBeeperPhone() != null
| && example.getBeeperPhone().length() > 0) {
| queryString.append(" and person.beeperPhone like :beeperPhone");
| parameters.put("beeperPhone", '%' + example.getBeeperPhone() + '%');
| }
| if (example.getCellPhone() != null
| && example.getCellPhone().length() > 0) {
| queryString.append(" and person.cellPhone like :cellPhone");
| parameters.put("cellPhone", '%' + example.getCellPhone() + '%');
| }
| if (example.getExtraPhone() != null
| && example.getExtraPhone().length() > 0) {
| queryString.append(" and person.extraPhone like :extraPhone");
| parameters.put("extraPhone", '%' + example.getExtraPhone() + '%');
| }
| if (example.getExtraPhoneMemo() != null
| && example.getExtraPhoneMemo().length() > 0) {
| queryString
| .append(" and person.extraPhoneMemo like :extraPhoneMemo");
| parameters.put("extraPhoneMemo",
| '%' + example.getExtraPhoneMemo() + '%');
| }
| if (example.getSchool() != null && example.getSchool().length() > 0) {
| queryString.append(" and person.school like :school");
| parameters.put("school", '%' + example.getSchool() + '%');
| }
| if (example.getSchoolGrade() != null
| && example.getSchoolGrade().length() > 0) {
| queryString.append(" and person.schoolGrade like :schoolGrade");
| parameters.put("schoolGrade", '%' + example.getSchoolGrade() + '%');
| }
| if (example.getContact() != null && example.getContact().length() > 0) {
| queryString.append(" and person.contact like :contact");
| parameters.put("contact", '%' + example.getContact() + '%');
| }
| if (example.getParentName() != null
| && example.getParentName().length() > 0) {
| queryString.append(" and person.parentName like :parentName");
| parameters.put("parentName", '%' + example.getParentName() + '%');
| }
| if (example.getComments() != null && example.getComments().length() > 0) {
| queryString.append(" and person.comments like :comments");
| parameters.put("comments", '%' + example.getComments() + '%');
| }
| if (example.getMinsitry() != null && example.getMinsitry().length() > 0) {
| queryString.append(" and person.minsitry like :minsitry");
| parameters.put("minsitry", '%' + example.getMinsitry() + '%');
| }
| if (example.getDrama() != null) {
| queryString.append(" and person.drama = :drama");
| parameters.put("drama", example.getDrama());
| }
| if (example.getMusic() != null) {
| queryString.append(" and person.music = :music");
| parameters.put("music", example.getMusic());
| }
| if (example.getStatus() != null) {
| queryString.append(" and person.status = :status");
| parameters.put("status", example.getStatus());
| }
| if (example.getVisitor() != null) {
| queryString.append(" and person.visitor = :visitor");
| parameters.put("visitor", example.getVisitor());
| }
| if (example.getMailList() != null) {
| queryString.append(" and person.mailList = :mailList");
| parameters.put("mailList", example.getMailList());
| }
| if (example.getLeader() != null) {
| queryString.append(" and person.leader = :leader");
| parameters.put("leader", example.getLeader());
| }
| if (example.getLastAttended() != null) {
| queryString.append(" and person.lastAttended = :lastAttended");
| parameters.put("lastAttended", example.getLastAttended());
| }
| if (example.getCreated() != null) {
| queryString.append(" and person.created = :created");
| parameters.put("created", example.getCreated());
| }
| if (example.getUpdated() != null) {
| queryString.append(" and person.updated = :updated");
| parameters.put("updated", example.getUpdated());
| }
| if (example.getVcall() != null) {
| queryString.append(" and person.vcall = :vcall");
| parameters.put("vcall", example.getVcall());
| }
| if (example.getVhouseCall() != null) {
| queryString.append(" and person.vhouseCall = :vhouseCall");
| parameters.put("vhouseCall", example.getVhouseCall());
| }
| if (example.getTeam() != null && example.getTeam().length() > 0) {
| queryString.append(" and person.team like :team");
| parameters.put("team", '%' + example.getTeam() + '%');
| }
| if (example.getPhotoFile() != null
| && example.getPhotoFile().length() > 0) {
| queryString.append(" and person.photoFile like :photoFile");
| parameters.put("photoFile", '%' + example.getPhotoFile() + '%');
| }
| if (example.getUniqueId() != null && example.getUniqueId().length() > 0) {
| queryString.append(" and person.uniqueId like :uniqueId");
| parameters.put("uniqueId", '%' + example.getUniqueId() + '%');
| }
| if (queryString.length() == 0) {
| queryString.append("select person from Person person");
| } else {
| queryString.delete(0, 4).insert(0,
| "select person from Person person where");
| }
|
| if (order != null) {
| queryString.append(" order by person.").append(order);
| if (descending)
| queryString.append(" desc");
| }
|
| Query query = entityManager.createQuery(queryString.toString());
| for (Entry<String, Object> param : parameters.entrySet()) {
| query.setParameter(param.getKey(), param.getValue());
| }
| personList = (List<Person>) query.setMaxResults(pageSize)
| .setFirstResult(pageSize * pageNumber).getResultList();
| }
|
| public String findFirstPage() {
| pageNumber = 0;
| executeQuery();
| return null;
| }
|
| public String findNextPage() {
| pageNumber++;
| executeQuery();
| return null;
| }
|
| public String findPreviousPage() {
| pageNumber--;
| executeQuery();
| return null;
| }
|
| public void refresh() {
| if (personList != null)
| executeQuery();
| }
|
| public String clear() {
| personList = null;
| example = new Person();
| return null;
| }
|
| public Person getSelection() {
| return entityManager.merge(selectedPerson);
| }
|
| @Destroy
| @Remove
| public void destroy() {
| }
|
| private String order;
|
| private boolean descending = false;
|
| @RequestParameter
| private String orderBy;
| private int id;
|
| public String reorder() {
| if (orderBy.equals(order)) {
| descending = !descending;
| } else {
| descending = false;
| }
| order = orderBy;
| executeQuery();
| return null;
| }
|
| @Begin
| @End
| public String checkIn() {
| // insert new record into attendance table
| Users loggedInUser = login.getInstance();
|
| System.out.println("I check'd em in...:"+selectedPerson.getId());
| System.out.println("I am from church:"+loggedInUser.getOrganizationId());
|
| java.util.Random rNum = new Random();
| int securityCode = Math.abs(rNum.nextInt());
| Attendance attend = attendanceEditor.getInstance();
|
| attend.setCheckedByUserId(loggedInUser.getId());
| attend.setDateTimeEntry(new Date());
| attend.setPersonId(selectedPerson.getId());
| attend.setRoomId(example.getRoomId());
| attend.setSecurityCode(""+securityCode);
| attend.setType("In");
| attendanceEditor.create();
|
| return "code:"+securityCode;
| }
|
| public String getSecurityCode() {
| Attendance attend = attendanceEditor.getInstance();
|
| //Here is where I want to do the lookup..
| return "special code";
| }
|
| public String edit() {
| return "/editPerson.jsp";
| }
| }
|
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3976815#3976815
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3976815
19 years, 7 months
[JBoss Seam] - Tomahawk fileUpload tag
by rlhr
Hi,
I'm using the fileUpload tag from Tomahawk library. I followed the setup explained in the wiki and the download part seems to work fine.
I get a .tmp (the name of the file is like upload__639ed4a2_10e27a79cd0__7fff_00000003.tmp) file on the upload directory I setup.
The UploadedFile object contains the right data with the name of the original file.
I was expecting the tmp file to be renamed after the download is complete. But it seems it is not happening that way. I keep having a .tmp file in the upload directory.
On the other hand, I don't really have a way to connect that .tmp file to any file object in java.
Do I miss something? Is the file writing somewhere else after the upload succeeded and the .tmp file is just garbage?
Thanks for you help,
Richard
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3976809#3976809
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3976809
19 years, 7 months
[JBossWS] - Problem starting user guide
by koriel
I want to implement some web services in my app which is a j2ee web application based in jsf,ejb3.0 with seam. I download the jbossws-1.0.3.GA and I start the user guide... So I created the following classes
| package some.webservices;
| import java.rmi.RemoteException;
| import javax.ejb.Remote;
|
| @Remote
| public interface TrivialService {
|
| String purchase (String person, String product) throws RemoteException;
|
| }
|
| package some.webservices;
| import java.rmi.RemoteException;
| import org.jboss.seam.annotations.Logger;
| import org.jboss.seam.log.Log;
| public class TrivialEndpointJSE implements TrivialService {
|
|
| @Logger
| private Log log;
| public String purchase(String person, String product) throws RemoteException {
| // TODO Auto-generated method stub
| log.info("purchase :"+ person+" "+product);
| return "ok"+person+product;
| }
| }
|
|
and the config file
| <configuration xmlns="http://www.jboss.org/jbossws-tools">
|
| <java-wsdl>
| <service name="SampleService" wsdlStyle="rpc" endpoint="TrivialService"/>
| <namespaces targetNamespace="http://org.jboss.ws/samples/rpcstyle" typeNamespace="http://org.jboss.ws/samples/rpcstyle/types"/>
| <mapping fileName="jaxrpc-mapping.xml"/>
| <wsxml servletLink="TrivialEndpoint"/>
| </java-wsdl>
|
| </configuration>
|
|
so in the root directory of the above classes I run
wstools.sh -cp . wstools-config.xml and I get the following error
| log4j:WARN No appenders could be found for logger (org.jboss.ws.tools.WSTools).
| log4j:WARN Please initialize the log4j system properly.
| Exception in thread "main" org.jboss.ws.WSException: Endpoint TrivialService cannot be loaded
| at org.jboss.ws.tools.helpers.ToolsHelper.handleJavaToWSDLGeneration(ToolsHelper.java:113)
| at org.jboss.ws.tools.WSTools.process(WSTools.java:132)
| at org.jboss.ws.tools.WSTools.generate(WSTools.java:120)
| at org.jboss.ws.tools.WSTools.main(WSTools.java:61)
|
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3976804#3976804
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3976804
19 years, 7 months
[JBoss Seam] - Re: Cryptic id's in error log
by SpecialAgent
Hey,
thank you.
But, it doesnt run. I am not a Facelets specialist... uhm... actually I did nothing with Facelets yet, so I need some help for this.
So, I put the stuff from your site to my jsp page:
| <?xml version="1.0"?>
| <html xmlns:jsp="http://java.sun.com/JSP/Page"
| xmlns:h="http://java.sun.com/jsf/html"
| xmlns:f="http://java.sun.com/jsf/core"
| xmlns:s="http://jboss.com/products/seam/taglib"
| xmlns:ui="http://java.sun.com/jsf/facelets"
| xmlns="http://www.w3.org/1999/xhtml">
| <jsp:output doctype-root-element="html"
| doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
| doctype-system="http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
| <jsp:directive.page contentType="text/html"/>
| <head>
| <title>Successfully Registered New User</title>
| </head>
| <body>
| <f:view>
| <h3>Welcome, <h:outputText value="#{person.name}"/>,</h3>
| you are successfully registered as <h:outputText value="#{person.username}"/>.
| <h:outputText value="No persons to display" rendered="#{personList.rowCount==0}"/>
| <h:outputText value="#{person.name}"/>
| <h:dataTable var="person" value="#{personList}" rendered="#{personList.rowCount>0}">
| <h:column>
| <f:facet name="header">
| <h:outputText value="Real name"/>
| </f:facet>
| <h:commandLink value="#{person.username}" action="#{registeredManager.select}"/>
| </h:column>
| <h:column>
| <f:facet name="header">
| <h:outputText value="User name"/>
| </f:facet>
| <h:outputText value="#{person.name}">
| </h:outputText>
| </h:column>
| <h:column>
| <h:commandButton value="Delete" action="#{registeredManager.delete}"/>
| </h:column>
| </h:dataTable>
| Passwort:
| <h:outputText value="#{person.password}"/>
| <ui:debug hotkey="d"/>
| </f:view>
| </body>
| </html>
|
I got rid of the rendered paramater in <ui:debug> cause I dont know what I have to write in the web.xml file to turn debug on. But it should run so.
When I am now running this page, and I want to debug this.. I press CTRL+SHIFT+d and nothing happens in my Firefox window?!
Is there a wiki page how turning debug in seam on? I didnt find anything and it would be an important page I think.
Thank you guys,
Im just a beginner.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3976803#3976803
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3976803
19 years, 7 months
[Beginners Corner] - Re: Newbie Need Help :)
by jaikiran
anonymous wrote : 2006-10-07 09:57:53,210 DEBUG [org.jboss.deployment.scanner.URLDeploymentScanner] Failed to deploy: org.jboss.deployment.scanner.URLDeploymentScanner$DeployedURL@bef53c88{ url=file:/D:/jboss-4.0.4.GA/server/default/deploy/jms/mysql-jdbc2-service.xml, deployedLastModified=0 }
| org.jboss.deployment.DeploymentException: Trying to install an already registered mbean: jboss.mq:service=DestinationManager
| at org.jboss.system.ServiceCreator.install(ServiceCreator.java:103)
The mysql-jdbc2-service.xml appears to be the culprit. As far as i know, this file does not come by default in the JBoss installation. Did your application put in this file at this location?
anonymous wrote : I just erased the file hsqldb-jdbc2-service.xml..
Undo this. Place the hsqldb-jdbc2-service.xml back into the jms folder.
anonymous wrote : I dont know why :) maybe it conflicts with mysql-ds.xml i just dont know. :)
No. hsqldb-jdbc2-service.xml is conflicting with mysql-jdbc2-service.xml and not mysql-ds.xml.
Solution to these problems would be to reintroduce the hsqldb-jdbc2-service.xml into the jms folder and remove the mysql-jdbc2-service.xml from the jms folder.
By the way, were you trying to use mysql-jdbc2-service.xml for deploying your datasource. If so then you will need to write a file named mysql-ds.xml (or *-ds.xml) and place it in "deploy" folder.
Have a look at:
http://wiki.jboss.org/wiki/Wiki.jsp?page=ConfigDataSources
http://wiki.jboss.org/wiki/Wiki.jsp?page=SetUpAMysqlDatasource
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3976801#3976801
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3976801
19 years, 7 months