[JBoss Seam] - Re: Is this the correct way to go about this?
by bfo81
"joff" wrote : We have two questions:
| Is this the correct way to be doing this type of "pull" data access? We have looked at the "Blog" example, but it does not seem as complex as what we are trying to do.
| Is it possible to have multiple @RequestParameter fields on a JavaBean like the one above, which do not all have to be populated when any given method (which may or may not use them) is called?
* The examples are intentionally kept quite simple, so don't wonder why your real-life app seems to be "overcomplex". It surely isn't. DAOs are a very good way to retrieve data from a database, as long as they are used in many other classes. If there is only one class performing a certain db query (and no other predictable scenario in the future) I wouldn't create a DAO cause this only blows up the complexity. If there's no need for something and you still use it, then it's "pattern madness". But that's just my opinion and there surely are other opinion about this, too ;).
* Unfortunately there's no attribute "required" for @RequestParameter like @In or @Out have, and so it always must be set when invoking one of the methods of your bean. I don't know exactly how your app works, but maybe you can use @In(required=false) instead of @RequestParameter? I even believe that this is the way it was meant to in Seam. RequestParameter seems to me to be just a little... well... accomodation to the old fashioned way of passing data from one page to another;).
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3957685#3957685
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3957685
19 years, 9 months
[Installation, Configuration & Deployment] - Deployment Error
by sudjboss
This EJB example I am trying with jboss-4.0.4.GA and am trying to deply the StringProcessor.jar file to C:\jboss-4.0.4.GA\server\default\deploy.
The error generated is:
2006-07-13 12:20:33,606 ERROR [org.jboss.deployment.scanner.URLDeploymentScanner] Incomplete Deployment listing:
--- Incompletely deployed packages ---
org.jboss.deployment.DeploymentInfo@e4b0ad97 { url=file:/C:/jboss-4.0.4.GA/server/default/deploy/StringProcessor.jar }
deployer: MBeanProxyExt[jboss.ejb:service=EJBDeployer]
status: Deployment FAILED reason: Invalid XML: file=jar:file:/C:/jboss-4.0.4.GA/server/default/tmp/deploy/tmp31156StringProcessor.jar!/META-INF/ejb-jar.xml@6:2; - nested throwable: (org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.)
state: FAILED
watch: file:/C:/jboss-4.0.4.GA/server/default/deploy/StringProcessor.jar
altDD: null
lastDeployed: 1152786033278
lastModified: 1152786033278
mbeans:
I have also alternatively tried with adding to ejb-jar.xml file DOCTYPE versions ( <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd"> ) or ( <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_1_1.dtd"> )
And even I tried including the jboss.xml file.
Still getting the same error, any help to solve this settings is appreciated. Thanks.
The files used are:
*********************************************************************
Listing 1. The StringProcessor.java File
package com.javapro.ejb;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface StringProcessor extends EJBObject {
public String toUpperCase(String s) throws RemoteException;
}
*********************************************************************
Listing 2. The StringProcessorHome.java File
package com.javapro.ejb;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface StringProcessorHome extends EJBHome {
StringProcessor create() throws RemoteException, CreateException;
}
*********************************************************************
Listing 3. The StringProcessorBean.java File
package com.javapro.ejb;
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
public class StringProcessorBean implements SessionBean {
public String toUpperCase(String s) {
System.out.println("from StringProcessorBean");
if (s==null)
return null;
else
return s.toUpperCase();
}
public void ejbCreate() {
}
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext sc) {
}
}
*********************************************************************
Listing 4. The ejb-jar.xml File
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar>
Your first EJB application
<display-name>String Processor Application</display-name>
<enterprise-beans>
<ejb-name>StringProcessor</ejb-name>
com.javapro.ejb.StringProcessorHome
com.javapro.ejb.StringProcessor
<ejb-class>com.javapro.ejb.StringProcessorBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</enterprise-beans>
</ejb-jar>
*********************************************************************
Listing 5. Client.java
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.util.Properties;
import com.javapro.ejb.StringProcessor;
import com.javapro.ejb.StringProcessorHome;
public class Client {
public static void main(String[] args) {
// first argument must be the input
if (args.length==0) {
System.out.println("Please specify the input to convert to upper case.");
return;
}
String input = args[0];
// preparing properties for constructing an InitialContext object
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.PROVIDER_URL, "localhost:1099");
try {
// Get an initial context
InitialContext jndiContext = new InitialContext(properties);
System.out.println("Got context");
// Get a reference to the Bean
Object ref = jndiContext.lookup("StringProcessor");
System.out.println("Got reference");
// Get a reference from this to the Bean's Home interface
StringProcessorHome home = (StringProcessorHome)
PortableRemoteObject.narrow (ref, StringProcessorHome.class);
// Create an Adder object from the Home interface
StringProcessor sp = home.create();
System.out.println ("Uppercase of '" + input + "' is " +
sp.toUpperCase(input));
}
catch(Exception e) {
System.out.println(e.toString());
}
}
}
*********************************************************************
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3957684#3957684
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3957684
19 years, 9 months
[Beginners Corner] - Deployment Error
by sudjboss
This EJB example I am trying with jboss-4.0.4.GA and am trying to deply the StringProcessor.jar file to C:\jboss-4.0.4.GA\server\default\deploy.
The error generated is:
2006-07-13 12:20:33,606 ERROR [org.jboss.deployment.scanner.URLDeploymentScanner] Incomplete Deployment listing:
--- Incompletely deployed packages ---
org.jboss.deployment.DeploymentInfo@e4b0ad97 { url=file:/C:/jboss-4.0.4.GA/server/default/deploy/StringProcessor.jar }
deployer: MBeanProxyExt[jboss.ejb:service=EJBDeployer]
status: Deployment FAILED reason: Invalid XML: file=jar:file:/C:/jboss-4.0.4.GA/server/default/tmp/deploy/tmp31156StringProcessor.jar!/META-INF/ejb-jar.xml@6:2; - nested throwable: (org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.)
state: FAILED
watch: file:/C:/jboss-4.0.4.GA/server/default/deploy/StringProcessor.jar
altDD: null
lastDeployed: 1152786033278
lastModified: 1152786033278
mbeans:
I have also alternatively tried with adding to ejb-jar.xml file DOCTYPE versions ( <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd"> ) or ( <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_1_1.dtd"> )
And even I tried including the jboss.xml file.
Still getting the same error, any help to solve this settings is appreciated. Thanks.
The files used are:
*********************************************************************
Listing 1. The StringProcessor.java File
package com.javapro.ejb;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface StringProcessor extends EJBObject {
public String toUpperCase(String s) throws RemoteException;
}
*********************************************************************
Listing 2. The StringProcessorHome.java File
package com.javapro.ejb;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface StringProcessorHome extends EJBHome {
StringProcessor create() throws RemoteException, CreateException;
}
*********************************************************************
Listing 3. The StringProcessorBean.java File
package com.javapro.ejb;
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
public class StringProcessorBean implements SessionBean {
public String toUpperCase(String s) {
System.out.println("from StringProcessorBean");
if (s==null)
return null;
else
return s.toUpperCase();
}
public void ejbCreate() {
}
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext sc) {
}
}
*********************************************************************
Listing 4. The ejb-jar.xml File
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar>
Your first EJB application
<display-name>String Processor Application</display-name>
<enterprise-beans>
<ejb-name>StringProcessor</ejb-name>
com.javapro.ejb.StringProcessorHome
com.javapro.ejb.StringProcessor
<ejb-class>com.javapro.ejb.StringProcessorBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</enterprise-beans>
</ejb-jar>
*********************************************************************
Listing 5. Client.java
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
import java.util.Properties;
import com.javapro.ejb.StringProcessor;
import com.javapro.ejb.StringProcessorHome;
public class Client {
public static void main(String[] args) {
// first argument must be the input
if (args.length==0) {
System.out.println("Please specify the input to convert to upper case.");
return;
}
String input = args[0];
// preparing properties for constructing an InitialContext object
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.PROVIDER_URL, "localhost:1099");
try {
// Get an initial context
InitialContext jndiContext = new InitialContext(properties);
System.out.println("Got context");
// Get a reference to the Bean
Object ref = jndiContext.lookup("StringProcessor");
System.out.println("Got reference");
// Get a reference from this to the Bean's Home interface
StringProcessorHome home = (StringProcessorHome)
PortableRemoteObject.narrow (ref, StringProcessorHome.class);
// Create an Adder object from the Home interface
StringProcessor sp = home.create();
System.out.println ("Uppercase of '" + input + "' is " +
sp.toUpperCase(input));
}
catch(Exception e) {
System.out.println(e.toString());
}
}
}
*********************************************************************
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3957683#3957683
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3957683
19 years, 9 months
[EJB/JBoss] - Re: [URGENT] Classloading issue
by beugeair
thx,
I've seen the first two link with no results, but the logging tell this :
| [...]
| [2098372,RepositoryClassLoader,http-0.0.0.0-8080-3] loadClassLocally, org.jboss.mx.loading.UnifiedClassLoader3@5a3923{ url=file:/D:/gwallet/tools/j2ee/jboss-4.0.3SP1/server/default/tmp/deploy/tmp23128jboss-service.xml ,addedOrder=2} name=si3si.metier.quartierforce.client.vo.VoAdrEml
| [2098372,RepositoryClassLoader,http-0.0.0.0-8080-3] findClass, name=si3si.metier.quartierforce.client.vo.VoAdrEml
| [2098388,RepositoryClassLoader,http-0.0.0.0-8080-3] CFNE: Adding to blacklist: si3si.metier.quartierforce.client.vo.VoAdrEml
| [2098388,RepositoryClassLoader,http-0.0.0.0-8080-3] CFNE: Adding to blacklist: si3si.metier.quartierforce.client.vo.VoAdrEml
| [2098388,RepositoryClassLoader,http-0.0.0.0-8080-3] loadClassLocally, org.jboss.mx.loading.UnifiedClassLoader3@5a3923{ url=file:/D:/gwallet/tools/j2ee/jboss-4.0.3SP1/server/default/tmp/deploy/tmp23128jboss-service.xml ,addedOrder=2} name=si3si.metier.quartierforce.client.vo.VoAdrEml not found
|
The classloader is blacklisting the class because it don't find it inside the webapp, but the class IS INSIDE THE WEBAPP ?
Don't understand ...
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3957682#3957682
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3957682
19 years, 9 months
[JBoss Seam] - Re: Avoiding the DRY Principle with beans
by bfo81
Of course, there are many ways to build such a CRUD stuff. But I think one shouldn't persist a new object right after creation, cause then you have an item in your database with empty fields. I mean objects should only be persisted after JSF validation and a click on "Save".
In addition to that, I regard a Delete button on the edit page as useful. And this one should not be shown to the user when he just created a new object. Just for existing ones.
My approach would be like that:
- A page with a list of all existing instances of an entity. Every entity gets an edit link, and at the bottom there's a create button.
- Both buttons lead to the edit page. On the edit page there are the fields belonging to that entity, a save button, a cancel button, and a delete button (not for newly created entities).
So that's what I suggest:
The abstract superclass (it should use generics like iradix suggested):
| ...
|
| private boolean new;
| //true: Object has just bean created
| //false: User is editing an existing object
|
| public setNew(boolean new) {
| this.new = new;
| }
|
| public boolean getNew() {
| return new;
| }
|
|
|
| public String create() {
| setNew(true);
| setObject(new T());
| return "editPage";
| }
|
|
| public String edit() {
| setNew(false);
| setObject((T) entityManager.merge(theList.getSelection())); //how to get the entity from the previous page's list is discussed in another topic - so that's something to implement later ;)
| return "editPage";
| }
|
|
| public String delete() {
| entityManager.remove(getObject());
| return "listPage";
| }
|
|
| public String save() {
|
| if(getNew())
| entityManager.persist(getObject());
| else
| entityManager.merge(getObject());
|
| return "listPage";
| }
|
|
The concrete bean class:
| ...
|
| @In(required=false) @Out //Don't create here, this is done in the edit() or create() method ;)
| private Employee employee;
|
| public Employee getObject() {
| return employee;
| }
|
| public void setObject(Employee employee) {
| this.employee = employee;
| }
| ...
|
The list page:
| ...
| <h:form>
| <h:dataTable....>
|
| ...
|
| <h:column>
| <h:commandLink value="Edit" action="#{employeeBean.edit}" />
| </h:column>
|
| </h:dataTable>
|
| <h:commandLink value="Create new employee" action="#{employeeBean.create}" />
|
| </h:form>
|
The edit page:
| ...
| <h:form>
|
|
| <inputText value="#{employee.someproperty...}" />
| ...
|
| <h:commandLink value="Save" action="#{employeeBean.save}" />
| <h:commandLink value="Delete" action="#{employeeBean.delete}" rendered="#{not employeeBean.new}" />
| <h:commandLink value="Cancel" action="#{employeeBean.cancel}" />
|
| </h:form>
| ...
|
Note: This is just a draft and I wasn't able to test it here. Let me know if you like it or if you would do it an other way. Feel free to add your comments and don't be polite ;).
My TODOs (I'm thankful for any hint):
- How to put an entity that's been selected on the list page into the editor bean in a convenient way (without violating the "Don't Repeat Yourself" rule ;))
- cancel method (I'm not sure if return "pageList" is sufficient cause I'm not sure if the entityManager does some stuff behind my back ;))
- How to refresh the list when returning to it. I encounter problems here as the list page always needs an explicit refresh (F5 key) before it shows updated and new entries.
- Safety question: "Oh my god, do you really wanna delete this?" ;)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3957674#3957674
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3957674
19 years, 9 months