-
1. Re: How to retain the previous page's values
gonorrhea May 6, 2009 10:03 PM (in response to arullis)javax.naming.NameNotFoundException: SampleHome not bound
is a JNDI lookup problem.
There was another thread I answered on this forum recently, search on
not bound
.as far as modeling a 2 (or more) page use case in Seam is concerned, you need to use @Begin and @End annotations in your SFSB with extended PC (or even better SMPC) to solve this.
check the hotel booking example for code.
-
2. Re: How to retain the previous page's values
luxspes May 7, 2009 4:02 PM (in response to arullis)
arulraj michealraj wrote on May 06, 2009 10:59:
How to retain the previous page's values ( 2 step form)?
This is the kind of problem that conversations should help solving, but only if you can only go to page 2 if all the data is valid and complete in page 1.
If you want to allow you user to freely navigate between the 2 pages, and only validate and the end, your best chance is to keep stuff in the same page... after all... what is the point of putting it in 2 pages? If you wantwizard like
behavior, use something client side, like for example a jQuery Wizard Plugin, (there are many to choose from) it will save you a lot of headaches.
Ex. I have two pages A & B. the user has to fill the form in page A and then go to page B to fill the rest of the form. In this case, the user might go back to previous page and alter the values that the user entered first time.
in my seam project,the code has been generated by reverse engineering concept. By default, session bean was stateless. I changed to stateful and execute the application .But i am getting the following exception.
Caused by: javax.naming.NameNotFoundException: SampleHome not bound
This, as Arbi Sookazian pointed out, looks like a JNDI lookup problem. Seems to me like you are using an EAR project, with EJBs instead of POJOs, are you sure you need to go down that road? I recommend you to keep using Seam POJOs and use a WAR project, chances are you are never going to need the gigantic amount of gratuitous complexity EJBs will bring into your project.
could any one of you please guide me on how to resovle the above problem and also how to retain previous page's value?
Thanks
Arulraj -
3. Re: How to retain the previous page's values
gonorrhea May 7, 2009 6:00 PM (in response to arullis)what app server are you using? e.g. Glassfish, JBoss, etc.
-
4. Re: How to retain the previous page's values
arullis May 8, 2009 11:33 AM (in response to arullis)I am using Jboss application server.
I have to fill the form in page 1 and got to page 2 with next button. Fill the form in second page and save it.
Here is my code:
I have a table called customer which 4 columns.
id,name,customerid,customername.
id and name in page1
customerid,customername in page2.
^"CustomerHome.java - stateless session bean.
package org.domain.SampleSeam.session;
import javax.persistence.EntityManager;
import org.domain.SampleSeam.entity.*;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.End;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.framework.EntityHome;
@Name("customerHome")
@Scope(ScopeType.CONVERSATION)
public class CustomerHome extends EntityHome<Customer> {
@In EntityManager entityManager;
public void setCustomerCustomerId(Integer id) {
setId(id);
}
public Integer getCustomerCustomerId() {
return (Integer) getId();
}
@Override
protected Customer createInstance() {
Customer customer = new Customer();
return customer;
}
public void wire() {
getInstance();
}
public boolean isWired() {
return true;
}
public Customer getDefinedInstance() {
return isIdDefined() ? getInstance() : null;
}
@Begin(join=true)
public void insertRecod()
{
Customer customer=getInstance();
entityManager.merge(customer);
}
@End
public String persist()
{
Customer customer=getInstance();
System.out.println("customer.id:"+customer.getId());
System.out.println("customer.name:"+customer.getName());
System.out.println("customer.getCustomerId:"+customer.getCustomerId());
System.out.println("customer.getCustomerName:"+customer.getCustomerName());
entityManager.persist(customer);
return "";
}
}
CustomerEdit.xhtml - page 1
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:a="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
template="layout/template.xhtml">
<ui:define name="body">
<h:messages globalOnly="true" styleClass="message" id="globalMessages"/>
<h:form id="customer" styleClass="edit">
<rich:panel>
<f:facet name="header">#{customerHome.managed ? 'Edit' : 'Add'} Customer</f:facet>
<s:decorate id="idDecoration" template="layout/edit.xhtml">
<ui:define name="label">id</ui:define>
<h:inputText id="id"
value="#{customerHome.instance.id}">
<a:support event="onblur" reRender="idDecoration" bypassUpdates="true" ajaxSingle="true"/>
</h:inputText>
</s:decorate>
<s:decorate id="nameDecoration" template="layout/edit.xhtml">
<ui:define name="label">name</ui:define>
<h:inputText id="name"
size="25"
maxlength="25"
value="#{customerHome.instance.name}">
<a:support event="onblur" reRender="nameDecoration" bypassUpdates="true" ajaxSingle="true"/>
</h:inputText>
</s:decorate>
<div style="clear:both">
<span class="required">*</span>
required fields
</div>
</rich:panel>
<div class="actionButtons">
<h:commandButton id="save"
value="Save"
action="#{customerHome.persist}"
disabled="#{!customerHome.wired}"
rendered="#{!customerHome.managed}"/>
<h:commandButton id="update"
value="Save"
action="#{customerHome.update}"
rendered="#{customerHome.managed}"/>
<h:commandButton id="delete"
value="Delete"
action="#{customerHome.remove}"
immediate="true"
rendered="#{customerHome.managed}"/>
<s:button id="done"
value="Done"
propagation="end"
view="/Customer.xhtml"
rendered="#{customerHome.managed}"/>
<s:button id="cancel"
value="Cancel"
propagation="end"
view="/#{empty customerFrom ? 'CustomerList' : customerFrom}.xhtml"
rendered="#{!customerHome.managed}"/>
<s:button id="next"
value="Next"
propagation="begin"
action="#{customerHome.insertRecod()}"
view="/CustomerEdit1.xhtml"
/>
</div>
</h:form>
</ui:define>
</ui:composition>
customerEdit1.xhmtl- page -2
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:a="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
template="layout/template.xhtml">
<ui:define name="body">
<h:messages globalOnly="true" styleClass="message" id="globalMessages"/>
<h:form id="customer" styleClass="edit">
<rich:panel>
<f:facet name="header">#{customerHome.managed ? 'Edit' : 'Add'} Customer</f:facet>
<s:decorate id="customerIdDecoration" template="layout/edit.xhtml">
<ui:define name="label">customerId</ui:define>
<h:inputText id="customerId"
required="true"
disabled="#{customerHome.managed}"
value="#{customerHome.instance.customerId}">
<a:support event="onblur" reRender="customerIdDecoration" bypassUpdates="true" ajaxSingle="true"/>
</h:inputText>
</s:decorate>
<s:decorate id="customerNameDecoration" template="layout/edit.xhtml">
<ui:define name="label">customerName</ui:define>
<h:inputText id="customerName"
size="50"
maxlength="50"
value="#{customerHome.instance.customerName}">
<a:support event="onblur" reRender="customerNameDecoration" bypassUpdates="true" ajaxSingle="true"/>
</h:inputText>
</s:decorate>
<div style="clear:both">
<span class="required">*</span>
required fields
</div>
</rich:panel>
<div class="actionButtons">
<h:commandButton id="save"
value="Save"
action="#{customerHome.persist()}"
disabled="#{!customerHome.wired}"
rendered="#{!customerHome.managed}"/>
<h:commandButton id="update"
value="Save"
action="#{customerHome.update}"
rendered="#{customerHome.managed}"/>
<h:commandButton id="delete"
value="Delete"
action="#{customerHome.remove}"
immediate="true"
rendered="#{customerHome.managed}"/>
<s:button id="done"
value="Done"
propagation="end"
view="/Customer.xhtml"
rendered="#{customerHome.managed}"/>
<s:button id="cancel"
value="Cancel"
propagation="end"
view="/#{empty customerFrom ? 'CustomerList' : customerFrom}.xhtml"
rendered="#{!customerHome.managed}"/>
<s:button id="back"
value="Back"
propagation="end"
view="/CustomerEdit.xhtml"
/>
</div>
</h:form>
</ui:define>
</ui:composition>"^
As you suggested, i have userd @Begin and @End annotation for method in session bean. Evenif i used those annotation, still i am not able to retain values across the page.
Please correct me if anything is wrong in my code.
-
5. Re: How to retain the previous page's values
luxspes May 8, 2009 7:35 PM (in response to arullis)
arulraj michealraj wrote on May 08, 2009 11:33:
I am using Jboss application server.
And your project is EAR or WAR? (Since your component does not seem to be implementing any superfluous interface I am gonna go ahead and guess that is a WAR project)
I have to fill the form in page 1 and got to page 2 with next button. Fill the form in second page and save it.
Short answer, your problem is the next button:<s:button id="next" value="Next" propagation="begin" action="#{customerHome.insertRecod()}" view="/CustomerEdit1.xhtml" />
it is a s:button that means it does not submit the form, and since your form is not submitted, the values written in it never reach your entities.
As you suggested, i have userd @Begin and @End annotation for method in session bean. Evenif i used those annotation, still i am not able to retain values across the page.
Please correct me if anything is wrong in my code.
-
6. Re: How to retain the previous page's values
luxspes May 8, 2009 7:39 PM (in response to arullis)The solution is to change the s:button to an h:commandButton, but since this will submit the form, that means validation will be triggered, and that means that if all the data in your first page is not complete and valid, you will not be able to go to the second page.
Easy solution for that? Why complicate your self by having 2 pages, just present the 2 steps to the user using something like the jQuery Wizard Plugin ;-)