julsorio
Joined: 05 Jun 2009 Posts: 168 Location: Bogota, Colombia, South America
|
Posted: Tue Jan 05, 2010 2:31 pm Post subject: Re: How to Create a Java EE 6 Application with JSF 2, EJB 3.1, JPA, and NetBeans IDE 6.8 |
|
|
2010/1/5 Jose Alvarez de Lara <address-removed ([email]address-removed[/email])>
| Quote: | I am trying the tutorial of DZone but I degrade to NB 6.7.1 with JSF 1.2 and EJB 3.0.
And the webapp works fine but I can not merge no customer because, in my opinion,
the jsf page CustomerDetails.xhtm is not well build.
|
|
| Back to top |
|
 |
pepelara
Joined: 29 Nov 2008 Posts: 115
|
Posted: Tue Jan 05, 2010 3:41 pm Post subject: Re: How to Create a Java EE 6 Application with JSF 2, EJB 3.1, JPA, and NetBeans IDE 6.8 |
|
|
Thanks Julian for your quick response.
I have got to admit I have the terrible mania to do the things on my own.
So I have resolved the issue.
But now it is time to complicate the app adding all the JSP files.
Best Regads,
Jose
From: JULIAN ENRIQUE OSORIO AMAYA ([email]address-removed[/email])
Sent: Tuesday, January 05, 2010 3:30 PM
To: address-removed ([email]address-removed[/email])
Subject: [nbj2ee] Re: How to Create a Java EE 6 Application with JSF 2, EJB 3.1, JPA, and NetBeans IDE 6.8
2010/1/5 Jose Alvarez de Lara <address-removed ([email]address-removed[/email])>
| Quote: | I am trying the tutorial of DZone but I degrade to NB 6.7.1 with JSF 1.2 and EJB 3.0.
And the webapp works fine but I can not merge no customer because, in my opinion,
the jsf page CustomerDetails.xhtm is not well build.
That is my opinion because it does not merge the customer. I have tried this,
<h:form>
<h:panelGrid columns="2" bgcolor="#eff5fa">
<h:outputLabel value="Customer ID:"/>
<h:inputText id="customerId" value="#{customer.details.customerId}" disabled="true"/>
<h:outputLabel value="Customer Name:"/>
<h:inputText id="customerName" value="#{customer.details.name}"/>
<h:outputLabel value="Credit Limit:"/>
<h:inputText id="creditLimit" value="#{customer.details.creditLimit}"/>
<h:outputLabel value="Discount Code"/>
<h:selectOneMenu id="discountCode" value="#{customer.details.discount}">
<f:selectItems value="#{customer.discountCodes}"/>
</h:selectOneMenu>
<h:outputLabel value="Email:"/>
<h:inputText id="email" value="#{customer.details.email}"/>
<h:outputLabel value="Phone:"/>
<h:inputText id="phone" value="#{customer.details.phone}"/>
<h:outputLabel value="Fax:"/>
<h:inputText id="fax" value="#{customer.details.fax}"/>
<h:outputLabel value="Address (Line 1):"/>
<h:inputText id="address1" value="#{customer.details.addressline1}"/>
<h:outputLabel value="Address (Line 2):"/>
<h:inputText id="address2" value="#{customer.details.addressline2}"/>
<h:outputLabel value="State:"/>
<h:inputText id="state" value="#{customer.details.state}"/>
<h:outputLabel value="City:"/>
<h:inputText id="city" value="#{customer.details.city}"/>
<h:outputLabel value="Zip:"/>
<h:inputText id="zip" value="#{customer.details.zip.zipCode}"/>
</h:panelGrid>
<h:commandButton id="back" value="Back" action="#{customer.list}"/>
<h:commandButton id="update" value="Update" actionListener="#{customer.update}">
<f:attribute name="attName" value="#{customerName}" />
<f:attribute name="attCreditLimit" value="#{creditLimit}" />
<f:attribute name="attDiscountCode" value="#{discountCode}" />
<f:attribute name="attEmail" value="#{email}" />
<f:attribute name="attPhone" value="#{phone}" />
<f:attribute name="attFax" value="#{fax}" />
<f:attribute name="attAddressline1" value="#{address1}" />
<f:attribute name="attAddressline2" value="#{address2}" />
<f:attribute name="attState" value="#{state}" />
<f:attribute name="attCity" value="#{city}" />
<f:attribute name="attZip" value="#{zip}" />
</h:commandButton>
</h:form>
What I am trying to do is passing the value of the inputText tags identified by its id
to the attribute tags putting in the value those id. But it does not work. Those values
are all of them null. The backing bean responses to the request ok, no problem. The
mistake is in the jsf page.
So how do I have to do?
Thanks in advance
Jose
|
Hello Jose
you can try this:
In index.jsp there is a panel grid with the customer info and you're going to need a h:commandLink tag to get the current customer info and display it in the next jsp. So, we use the h:commandLink and the f:param tags in index.jsp
<h:commandLink action="#{BackingBean.showInfo}" >
<f:param id="id" value="#{item.customerId}" />
<h:outputText value="#{item.customerId}" />
</h:commandLink>
Now in the BackingBean
@EJB
private YourEJBInterface ejb;
private Customer customer;
public String showInfo() {
String action = "show";
//get the parameter value from the link
String customerId = FacesContext().getExternalContext().getParameterMap().get("id");
this.setCustomer(ejb.getCustomerById(customerId));
return action;
}
//getter and setter for Customer object
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
Finally in your EJB
@PersistenceContext
EntityManager em;
public Customer getCustomerById(String id) {
Query query = em.createNamedQuery("customer.getCustomerById");
query.setParameter("customerId", Integer.parseInt(id));
Customer customer = (Customer) query.getSingleResult();
return customer;
}
Now, you have the Customer object in your Backing Bean and can display the object's attributes in customerDetails.jsp
like this
<h:panelGrid columns="2" bgcolor="#eff5fa">
<h:outputLabel value="Customer ID:"/>
<h:inputText id="customerId" value="#{BackingBean.customer.customerId}" disabled="true"/>
<h:outputLabel value="Customer Name:"/>
<h:inputText id="customerName" value="#{BackingBean.customer.name}"/>
<h:outputLabel value="Credit Limit:"/>
<h:inputText id="creditLimit" value="#{cBackingBean.customer.creditLimit}"/>
<h:outputLabel value="Discount Code"/>
and so on
Hope this helps
--
Julian Osorio Amaya
Ingenier
|
|
| Back to top |
|
 |
Christopher Lam Posted via mailing list.
|
Posted: Wed Jan 06, 2010 4:06 am Post subject: Re: How to Create a Java EE 6 Application with JSF 2, EJB 3.1, JPA, and NetBeans IDE 6.8 |
|
|
Hi,
Sorry for the late reply because I was trying to whip up the application to share here. Please find in the attached.
The way to do this in NB6.7.1 with JSF1.2 will be slightly different from the article in DZone which is using NB6.8 with JSF2. The way I do it here is as follows:
1) Uses JSPs
2) One Backing Bean for each view and playing around with the Scopes: Application, Session and Request
Your feedback are welcome and hope this helps.
Best regards,
Christopher Lam
On 05-Jan-2010, at 4:05 PM, Jose Alvarez de Lara wrote:
| Quote: | I am trying the tutorial of DZone but I degrade to NB 6.7.1 with JSF 1.2 and EJB 3.0.
And the webapp works fine but I can not merge no customer because, in my opinion,
the jsf page CustomerDetails.xhtm is not well build.
That is my opinion because it does not merge the customer. I have tried this,
<h:form>
<h:panelGrid columns="2" bgcolor="#eff5fa">
<h:outputLabel value="Customer ID:"/>
<h:inputText id="customerId" value="#{customer.details.customerId}" disabled="true"/>
<h:outputLabel value="Customer Name:"/>
<h:inputText id="customerName" value="#{customer.details.name}"/>
<h:outputLabel value="Credit Limit:"/>
<h:inputText id="creditLimit" value="#{customer.details.creditLimit}"/>
<h:outputLabel value="Discount Code"/>
<h:selectOneMenu id="discountCode" value="#{customer.details.discount}">
<f:selectItems value="#{customer.discountCodes}"/>
</h:selectOneMenu>
<h:outputLabel value="Email:"/>
<h:inputText id="email" value="#{customer.details.email}"/>
<h:outputLabel value="Phone:"/>
<h:inputText id="phone" value="#{customer.details.phone}"/>
<h:outputLabel value="Fax:"/>
<h:inputText id="fax" value="#{customer.details.fax}"/>
<h:outputLabel value="Address (Line 1):"/>
<h:inputText id="address1" value="#{customer.details.addressline1}"/>
<h:outputLabel value="Address (Line 2):"/>
<h:inputText id="address2" value="#{customer.details.addressline2}"/>
<h:outputLabel value="State:"/>
<h:inputText id="state" value="#{customer.details.state}"/>
<h:outputLabel value="City:"/>
<h:inputText id="city" value="#{customer.details.city}"/>
<h:outputLabel value="Zip:"/>
<h:inputText id="zip" value="#{customer.details.zip.zipCode}"/>
</h:panelGrid>
<h:commandButton id="back" value="Back" action="#{customer.list}"/>
<h:commandButton id="update" value="Update" actionListener="#{customer.update}">
<f:attribute name="attName" value="#{customerName}" />
<f:attribute name="attCreditLimit" value="#{creditLimit}" />
<f:attribute name="attDiscountCode" value="#{discountCode}" />
<f:attribute name="attEmail" value="#{email}" />
<f:attribute name="attPhone" value="#{phone}" />
<f:attribute name="attFax" value="#{fax}" />
<f:attribute name="attAddressline1" value="#{address1}" />
<f:attribute name="attAddressline2" value="#{address2}" />
<f:attribute name="attState" value="#{state}" />
<f:attribute name="attCity" value="#{city}" />
<f:attribute name="attZip" value="#{zip}" />
</h:commandButton>
</h:form>
What I am trying to do is passing the value of the inputText tags identified by its id
to the attribute tags putting in the value those id. But it does not work. Those values
are all of them null. The backing bean responses to the request ok, no problem. The
mistake is in the jsf page.
So how do I have to do?
Thanks in advance
Jose
|
| Description: |
|
 Download |
| Filename: |
CustomerApp3.zip |
| Filesize: |
65.26 KB |
| Downloaded: |
84 Time(s) |
|
|
| Back to top |
|
 |
Christopher Lam Posted via mailing list.
|
Posted: Thu Jan 07, 2010 4:13 pm Post subject: Re: How to Create a Java EE 6 Application with JSF 2, EJB 3.1, JPA, and NetBeans IDE 6.8 |
|
|
I don't have this problem, did you remember to change the TextMessage to ObjectMessage at the sending side? Anyway, you can refer to the attached project, see how it's different from mine.
Best regards,
Christopher Lam
On 07-Jan-2010, at 1:18 PM, JULIAN ENRIQUE OSORIO AMAYA wrote:
| Quote: |
2010/1/5 Christopher Lam <address-removed ([email]address-removed[/email])>
| Quote: | Hi,
Sorry for the late reply because I was trying to whip up the application to share here. Please find in the attached.
The way to do this in NB6.7.1 with JSF1.2 will be slightly different from the article in DZone which is using NB6.8 with JSF2. The way I do it here is as follows:
1) Uses JSPs
2) One Backing Bean for each view and playing around with the Scopes: Application, Session and Request
Your feedback are welcome and hope this helps.
Best regards,
Christopher Lam
On 05-Jan-2010, at 4:05 PM, Jose Alvarez de Lara wrote:
| Quote: | I am trying the tutorial of DZone but I degrade to NB 6.7.1 with JSF 1.2 and EJB 3.0.
And the webapp works fine but I can not merge no customer because, in my opinion,
the jsf page CustomerDetails.xhtm is not well build.
That is my opinion because it does not merge the customer. I have tried this,
<h:form>
<h:panelGrid columns="2" bgcolor="#eff5fa">
<h:outputLabel value="Customer ID:"/>
<h:inputText id="customerId" value="#{customer.details.customerId}" disabled="true"/>
<h:outputLabel value="Customer Name:"/>
<h:inputText id="customerName" value="#{customer.details.name}"/>
<h:outputLabel value="Credit Limit:"/>
<h:inputText id="creditLimit" value="#{customer.details.creditLimit}"/>
<h:outputLabel value="Discount Code"/>
<h:selectOneMenu id="discountCode" value="#{customer.details.discount}">
<f:selectItems value="#{customer.discountCodes}"/>
</h:selectOneMenu>
<h:outputLabel value="Email:"/>
<h:inputText id="email" value="#{customer.details.email}"/>
<h:outputLabel value="Phone:"/>
<h:inputText id="phone" value="#{customer.details.phone}"/>
<h:outputLabel value="Fax:"/>
<h:inputText id="fax" value="#{customer.details.fax}"/>
<h:outputLabel value="Address (Line 1):"/>
<h:inputText id="address1" value="#{customer.details.addressline1}"/>
<h:outputLabel value="Address (Line 2):"/>
<h:inputText id="address2" value="#{customer.details.addressline2}"/>
<h:outputLabel value="State:"/>
<h:inputText id="state" value="#{customer.details.state}"/>
<h:outputLabel value="City:"/>
<h:inputText id="city" value="#{customer.details.city}"/>
<h:outputLabel value="Zip:"/>
<h:inputText id="zip" value="#{customer.details.zip.zipCode}"/>
</h:panelGrid>
<h:commandButton id="back" value="Back" action="#{customer.list}"/>
<h:commandButton id="update" value="Update" actionListener="#{customer.update}">
<f:attribute name="attName" value="#{customerName}" />
<f:attribute name="attCreditLimit" value="#{creditLimit}" />
<f:attribute name="attDiscountCode" value="#{discountCode}" />
<f:attribute name="attEmail" value="#{email}" />
<f:attribute name="attPhone" value="#{phone}" />
<f:attribute name="attFax" value="#{fax}" />
<f:attribute name="attAddressline1" value="#{address1}" />
<f:attribute name="attAddressline2" value="#{address2}" />
<f:attribute name="attState" value="#{state}" />
<f:attribute name="attCity" value="#{city}" />
<f:attribute name="attZip" value="#{zip}" />
</h:commandButton>
</h:form>
What I am trying to do is passing the value of the inputText tags identified by its id
to the attribute tags putting in the value those id. But it does not work. Those values
are all of them null. The backing bean responses to the request ok, no problem. The
mistake is in the jsf page.
So how do I have to do?
Thanks in advance
Jose
|
|
Greetings
Actually I'm having an exception in the onMessage method from the NotificationBean class
Caused by: java.lang.ClassCastException: com.sun.messaging.jms.ra.DirectTextPacket cannot be cast to javax.jms.ObjectMessage
There is an attachment with the exception's stack trace
Thanks for your help.
--
Julian Osorio Amaya
Ingenier
| Description: |
|
 Download |
| Filename: |
CustomerApp3.zip |
| Filesize: |
70.14 KB |
| Downloaded: |
74 Time(s) |
|
|
| Back to top |
|
 |
pepelara
Joined: 29 Nov 2008 Posts: 115
|
Posted: Thu Jan 07, 2010 4:46 pm Post subject: Re: How to Create a Java EE 6 Application with JSF 2, EJB 3.1, JPA, and NetBeans IDE 6.8 |
|
|
Hi folks,
I was having problems on update the Customer, but I have resolved.
This is my code snippet,
<h:form>
<h:panelGrid columns="2" bgcolor="#eff5fa">
<h:outputLabel value="Customer ID:"/>
<h:inputText id="customerId" value="#{details.customer.customerId}" disabled="true"/>
<h:outputLabel value="Customer Name:"/>
<h:inputText id="customerName" value="#{details.customer.name}"/>
<h:outputLabel value="Credit Limit:"/>
<h:inputText id="creditLimit" value="#{details.customer.creditLimit}"/>
<h:outputLabel value="Discount Code"/>
<h:selectOneMenu id="discountCode" value="#{details.selectedItem}"
converter="myDiscountCodeConverter">
<f:selectItems value="#{details.selectItems}"/>
</h:selectOneMenu>
<h:outputLabel value="Email:"/>
<h:inputText id="email" value="#{details.customer.email}"/>
<h:outputLabel value="Phone:"/>
<h:inputText id="phone" value="#{details.customer.phone}"/>
<h:outputLabel value="Fax:"/>
<h:inputText id="fax" value="#{details.customer.fax}"/>
<h:outputLabel value="Address (Line 1):"/>
<h:inputText id="address1" value="#{details.customer.addressline1}"/>
<h:outputLabel value="Address (Line 2):"/>
<h:inputText id="address2" value="#{details.customer.addressline2}"/>
<h:outputLabel value="State:"/>
<h:inputText id="state" value="#{details.customer.state}"/>
<h:outputLabel value="City:"/>
<h:inputText id="city" value="#{details.customer.city}"/>
<h:outputLabel value="ZipCode:"/>
<h:inputText id="zipCode" value="#{details.customer.zip.zipCode}"/>
</h:panelGrid>
<h:commandButton id="back" value="Back" action="#{details.list}"/>
<h:commandButton id="update" value="Update" action="#{details.update}"/>
</h:form>
Update method in CustomerDetails backing bean is,
public String update()
{
System.out.println("###UPDATE###");
customer = customerSessionBean.update(customer);
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,
"Sucessful", "Record successfully saved!"));
return "SAVED";
}
where the constructor is,
public CustomerDetails() {
try {
InitialContext ic = new InitialContext();
customerSessionBean = (CustomerSessionLocal)ic.lookup("java:comp/env/ejb/CustomerSessionBean");
} catch (NamingException ex) {
Logger.getLogger(ApplicationMBean.class.getName()).log(Level.SEVERE, null, ex);
}
if (customerId == null) {
this.setCustomerId((Integer)FacesUtil.getSessionMapValue("appBean.customerId"));
}
this.fillDiscountCodes();
this.getDetails();
}
This let me call the customer from the jsf instead of details and update.
What I am thinking is in the way to set the dropdown list up exactly on the corresponding value for the selected customer.
I mean if Discount% for Livermore Enterprises is 11.00, in the Customer Detais the ddl must be set on [M(11%)]
I think this is done using javascript. I have to investigate in google.
Regards,
Jose
From: Christopher Lam ([email]address-removed[/email])
Sent: Thursday, January 07, 2010 5:13 PM
To: address-removed ([email]address-removed[/email])
Subject: [nbj2ee] Re: How to Create a Java EE 6 Application with JSF 2, EJB 3.1, JPA, and NetBeans IDE 6.8
I don't have this problem, did you remember to change the TextMessage to ObjectMessage at the sending side? Anyway, you can refer to the attached project, see how it's different from mine.
Best regards,
Christopher Lam
On 07-Jan-2010, at 1:18 PM, JULIAN ENRIQUE OSORIO AMAYA wrote:
| Quote: |
2010/1/5 Christopher Lam <address-removed ([email]address-removed[/email])>
| Quote: | Hi,
Sorry for the late reply because I was trying to whip up the application to share here. Please find in the attached.
The way to do this in NB6.7.1 with JSF1.2 will be slightly different from the article in DZone which is using NB6.8 with JSF2. The way I do it here is as follows:
1) Uses JSPs
2) One Backing Bean for each view and playing around with the Scopes: Application, Session and Request
Your feedback are welcome and hope this helps.
Best regards,
Christopher Lam
On 05-Jan-2010, at 4:05 PM, Jose Alvarez de Lara wrote:
| Quote: | I am trying the tutorial of DZone but I degrade to NB 6.7.1 with JSF 1.2 and EJB 3.0.
And the webapp works fine but I can not merge no customer because, in my opinion,
the jsf page CustomerDetails.xhtm is not well build.
That is my opinion because it does not merge the customer. I have tried this,
<h:form>
<h:panelGrid columns="2" bgcolor="#eff5fa">
<h:outputLabel value="Customer ID:"/>
<h:inputText id="customerId" value="#{customer.details.customerId}" disabled="true"/>
<h:outputLabel value="Customer Name:"/>
<h:inputText id="customerName" value="#{customer.details.name}"/>
<h:outputLabel value="Credit Limit:"/>
<h:inputText id="creditLimit" value="#{customer.details.creditLimit}"/>
<h:outputLabel value="Discount Code"/>
<h:selectOneMenu id="discountCode" value="#{customer.details.discount}">
<f:selectItems value="#{customer.discountCodes}"/>
</h:selectOneMenu>
<h:outputLabel value="Email:"/>
<h:inputText id="email" value="#{customer.details.email}"/>
<h:outputLabel value="Phone:"/>
<h:inputText id="phone" value="#{customer.details.phone}"/>
<h:outputLabel value="Fax:"/>
<h:inputText id="fax" value="#{customer.details.fax}"/>
<h:outputLabel value="Address (Line 1):"/>
<h:inputText id="address1" value="#{customer.details.addressline1}"/>
<h:outputLabel value="Address (Line 2):"/>
<h:inputText id="address2" value="#{customer.details.addressline2}"/>
<h:outputLabel value="State:"/>
<h:inputText id="state" value="#{customer.details.state}"/>
<h:outputLabel value="City:"/>
<h:inputText id="city" value="#{customer.details.city}"/>
<h:outputLabel value="Zip:"/>
<h:inputText id="zip" value="#{customer.details.zip.zipCode}"/>
</h:panelGrid>
<h:commandButton id="back" value="Back" action="#{customer.list}"/>
<h:commandButton id="update" value="Update" actionListener="#{customer.update}">
<f:attribute name="attName" value="#{customerName}" />
<f:attribute name="attCreditLimit" value="#{creditLimit}" />
<f:attribute name="attDiscountCode" value="#{discountCode}" />
<f:attribute name="attEmail" value="#{email}" />
<f:attribute name="attPhone" value="#{phone}" />
<f:attribute name="attFax" value="#{fax}" />
<f:attribute name="attAddressline1" value="#{address1}" />
<f:attribute name="attAddressline2" value="#{address2}" />
<f:attribute name="attState" value="#{state}" />
<f:attribute name="attCity" value="#{city}" />
<f:attribute name="attZip" value="#{zip}" />
</h:commandButton>
</h:form>
What I am trying to do is passing the value of the inputText tags identified by its id
to the attribute tags putting in the value those id. But it does not work. Those values
are all of them null. The backing bean responses to the request ok, no problem. The
mistake is in the jsf page.
So how do I have to do?
Thanks in advance
Jose
|
|
Greetings
Actually I'm having an exception in the onMessage method from the NotificationBean class
Caused by: java.lang.ClassCastException: com.sun.messaging.jms.ra.DirectTextPacket cannot be cast to javax.jms.ObjectMessage
There is an attachment with the exception's stack trace
Thanks for your help.
--
Julian Osorio Amaya
Ingenier
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|
|