[JBoss Seam] - why Factory method is calling more than once?
by mnrz
Hi
I have a factory method for a field User in my SB, and I want to know why this method is calling as many time as the number of User's field?
in my case, the User has 12 fields do this method is called 12 times whereas I load it once from database ?
please take a look at following code:
| @Factory(value = "tempUser", scope = ScopeType.STATELESS)
| public User loadUser() {
| if(reload || tempUser == null) {
| if(selectedUsername.equals("0")) {
| logger.debug("instantiating a new User");
| tempUser = new User();
| verifyPassword = password = "";
| selectedGroup = 0L;
| }else{
| logger.debug("loading User with username '"+selectedUsername+"'");
| tempUser = userDao.load(selectedUsername);
| if(tempUser.getGroup() != null)
| selectedGroup = tempUser.getGroup().getId();
| verifyPassword = password = tempUser.getPassword();
| selectedRoles = new ArrayList<String>();
| for(UserRole r : tempUser.getRoles()) {
| selectedRoles.add(r.getRoleName());
| }
| logger.debug(tempUser.toString());
| reload = false;
| //setInputValuesWithUser();
| }
| }
| return tempUser;
| }
|
|
as you see, at first the "reload" is true so the User will be populated from the database and then the reload will set to false, but at my XHTML page, no value will be displayed !!!!! however I can see all the User's value in the logs (produced by logger)
if I remove the line highlighted bu blue color reload = false; it will work fine but this method will be called 6 times and in app server console I can see that 12 times the EJB is selecting from database!!!
thank you very much in advance
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4095089#4095089
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4095089
18Â years, 9Â months
[Beginners Corner] - My first session application
by Nagendra42
Hi Friends,
I am first time using application server, So can any one help me how can i run first session bean in jboss without eclips.
i have this files;
package test.session;
import java.lang.*;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
public interface MyTestSession extends javax.ejb.EJBObject{
public java.lang.String SayHello() throws java.rmi.RemoteException;
}
===============================================================
package test.session;
import java.lang.*;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
public interface MyTestSessionHome extends javax.ejb.EJBHome{
public static final String COMP_NAME="java:comp/env/ejb/test/MyTestSession";
public static final String JNDI_NAME="ejb/test/MyTestSessionBean";
public test.session.MyTestSession create() throws javax.ejb.CreateException, java.rmi.RemoteException;
}
===========================================
public class MyTestSessionBean implements SessionBean{
public void ejbCreate() throws CreateException {
}
public String SayHello(){
String msg="Hello! I am Session Bean";
System.out.println(msg);
return msg;
}
public void setSessionContext( SessionContext aContext ) throws EJBException {
}
public void ejbActivate() throws EJBException {
}
public void ejbPassivate() throws EJBException {
}
public void ejbRemove() throws EJBException {
}
}
=====================================
ejb-jar.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
Example 3
<display-name>Example 3</display-name>
<enterprise-beans>
<!-- Session Beans -->
<display-name>My Test Session Bean</display-name>
<ejb-name>test/MyTestSession</ejb-name>
test.session.MyTestSessionHome
test.session.MyTestSession
<ejb-class>test.session.MyTestSessionBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</enterprise-beans>
<assembly-descriptor>
</assembly-descriptor>
</ejb-jar>
==============================================
/*
* SessionTestServlet.java
*
*/
package test.session;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
/**
* @author Deepak Kumar
* @Web http://www.roseindia.net
* @Email deepak(a)roseindia.net
*/
public class SessionTestServlet extends HttpServlet {
MyTestSessionHome testSessionBean;
public void init(ServletConfig config) throws ServletException{
//Look up home interface
try {
InitialContext ctx = new InitialContext();
Object objref = ctx.lookup("ejb/test/MyTestSessionBean");
testSessionBean = (MyTestSessionHome)PortableRemoteObject.narrow(objref, MyTestSessionHome.class);
} catch (Exception NamingException) {
NamingException.printStackTrace();
}
}
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out;
response.setContentType("text/html");
String title = "EJB Example";
out = response.getWriter();
out.println("");
out.println("");
out.println("Hello World Servlet!");
out.println("");
out.println("");
out.println("<p align=\"center\"><font size=\"4\" color=\"#000080\">Servlet Calling Session Bean");
try{
MyTestSession beanRemote;
beanRemote = testSessionBean.create();
out.println("<p align=\"center\"> Message from Session Bean is: " + beanRemote.SayHello() + "");
beanRemote.remove();
}catch(Exception CreateException){
CreateException.printStackTrace();
}
out.println("<p align=\"center\"><a href=\"javascript:history.back()\">Go to Home");
out.println("");
out.println("");
out.close();
}
public void destroy() {
System.out.println("Destroy");
}
}
=======================================
web.xml
<?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>
<servlet-name>SessionServlet</servlet-name>
<display-name>Simple Session Servlet</display-name>
<servlet-class>test.session.SessionTestServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<servlet-mapping>
<servlet-name>SessionServlet</servlet-name>
<url-pattern>/servlet/test</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>0</session-timeout>
</session-config>
</web-app>
please tell me step by step
Thanks in adv
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4095088#4095088
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4095088
18Â years, 9Â months
[JBoss Seam] - Help - post login and EntityHome instance
by terryb
I am not sure if my problem is conversation related, or something I'm missing.
I have two menu links on the page. Login and Add User. Login is via Seam authentication with users in my database. Login link uses UserHome object to update user login history; and AddUser.xhtml is bound to UserHome as well.
When I click on Login link and perform login, the page refreshes the Edit User link generted by s:link is already appended with the UserId causing it to load record of the logged in user; instead of giving blank Add User form.
I this it is because UserHome has already been initialised by my login process. But I am not sure, what should be done after the login process to avoid this?
Login Link
| <s:link view="/login.xhtml" value="Login" rendered="#{not identity.loggedIn}" propagation="none"/>
|
| Add User
| <s:link view="/user-edit.xhtml" value="User Add" propagation="none"/>
|
| login.page.xml
| <page conversation-required="false">
| <navigation>
| ...
| </navigatioin>
| </page>
|
| user.page.xml
| <page no-conversation-view-id="/user-list.xhtml" login-required="true">
|
| <begin-conversation join="true"/>
| <action execute="#{userHome.wire}"/>
|
| <param name="userFrom"/>
| <param name="userId" value="#{userHome.userId}"/>
|
| <navigation from-action="#{userHome.persist}">
| <end-conversation/>
| <redirect view-id="/user.xhtml"/>
| </navigation>
|
| <navigation from-action="#{userHome.update}">
| <end-conversation/>
| <redirect view-id="/user.xhtml"/>
| </navigation>
|
| <navigation from-action="#{userHome.remove}">
| <end-conversation/>
| <redirect view-id="/user-list.xhtml"/>
| </navigation>
| </page>
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4095077#4095077
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4095077
18Â years, 9Â months