aspose file tools*
The moose likes Struts and the fly likes StrutsPrepareandExecutefilter error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "StrutsPrepareandExecutefilter error" Watch "StrutsPrepareandExecutefilter error" New topic
Author

StrutsPrepareandExecutefilter error

rajiv jackz
Greenhorn

Joined: Jul 12, 2010
Posts: 29
java.lang.NullPointerException
>>>> at
>>>> com.opensymphony.module.sitemesh.taglib.decorator.HeadTag.doEndTag(HeadTag.java:33)
>>>> at
>>>> freemarker.ext.jsp.TagTransformModel$TagWriter.endEvaluation(TagTransformModel.java:431)
>>>> at
>>>> freemarker.ext.jsp.TagTransformModel$TagWriter.onStart(TagTransformModel.java:370)
>>>> at freemarker.core.Environment.visit(Environment.java:295)
>>>> at freemarker.core.UnifiedCall.accept(UnifiedCall.java:130)
>>>> at freemarker.core.Environment.visit(Environment.java:209)
>>>> at freemarker.core.MixedContent.accept(MixedContent.java:92)
>>>> at freemarker.core.Environment.visit(Environment.java:209)
>>>> at freemarker.core.Environment.process(Environment.java:189)
>>>> at freemarker.template.Template.process(Template.java:237)
>>>> at
>>>> org.apache.struts2.sitemesh.FreeMarkerPageFilter.applyDecorator(FreeMarkerPageFilter.java:160)
>>>> at
>>>> org.apache.struts2.sitemesh.TemplatePageFilter.applyDecorator(TemplatePageFilter.java:116)
>>>> at
>>>> com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:62)
>>>> </code>
>>>>



package com.customer;



import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.util.ServletContextAware;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ModelDriven;

public class CustomerAction implements ModelDriven<Customer>,ServletContextAware{

Customer customer = new Customer();

//<constant name="struts.devMode" value="false" />


ServletContext servletContext;
CustomerBo customerBo;
List customerList=null;
// DI via Spring

public void setCustomerBo(CustomerBo customerBo){
this.customerBo = customerBo;
}

@Override
public Customer getModel() {
return customer;
}

public String addCustomer() throws Exception{

// to save
customer.setCreatedDate(new Date());

WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
CustomerBo customerBo =(CustomerBo) wac.getBean("customerBo");
// setCustomerBo();

customerBo.addCustomer(customer);

customerList = customerBo.listCustomer();

listCustomer();

return "success";
}
//update customer
public String updateCustomer() throws Exception{

// to save
customer.setCreatedDate(new Date());
setCustomerBo2();
customerBo.updateCustomer(customer);
customerList = customerBo.listCustomer();

return "success";
}

// list all customers
public String listCustomer() throws Exception {
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
CustomerBo customerBo =
(CustomerBo) wac.getBean("customerBo");
// setCustomerBo();
customerList = customerBo.listCustomer();
ActionContext ctx = ActionContext.getContext();
HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
request.setAttribute("customerList", customerList);


return "success";
}



public void setCustomerBo2()
{
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
customerBo = (CustomerBo) wac.getBean("customerBo");

}

public String deleteCustomer() {
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
customerBo = (CustomerBo) wac.getBean("customerBo");
//setCustomerBo2();
customerBo.deleteCustomer(customer);
customerList =customerBo.listCustomer();
ActionContext ctx = ActionContext.getContext();
HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
request.setAttribute("customerList", customerList);
return "success";
}

public void setCustomerList(List<Customer> customerList) {
this.customerList = customerList;
}

@Override
public void setServletContext(ServletContext context) {
// TODO Auto-generated method stub
this.servletContext = context;
}
/*public List<Customer> getCustomerList()
{
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
customerBo=(CustomerBo)wac.getBean("customerBo");
customerList = customerBo.listCustomer();

return customerList;
}*/

} CODE HAS exception


package com.customer;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;

public class CustomerDAOImpl implements CustomerDAO {

private HibernateTemplate hibernateTemplate;

public void setSessionFactory(SessionFactory sessionFactory){
this.hibernateTemplate = new HibernateTemplate(sessionFactory);
}
@Override
public void addCustomer(Customer customer) {
hibernateTemplate.save(customer);
}
@Override
public void updateCustomer(Customer customer) {
hibernateTemplate.update(customer);
}
@Override
public void deleteCustomer(Customer customer) {
hibernateTemplate.delete(customer);
}

@Override
public List<Customer> listCustomer() {

List<Customer> cust = hibernateTemplate.find("from Customer");
//List<Customer> cust2 = hibernateTemplate.findByValueBean(queryString, valueBean)
//List<Customer> cust2 = hibernateTemplate.findByCriteria(criteria)
//List<Customer> cust3 = hibernateTemplate.findByExample(exampleEntity);
return cust;
}
}

package com.customer;

import java.util.List;

public interface CustomerDAO {
void addCustomer(Customer customer);
void updateCustomer(Customer customer);
void deleteCustomer(Customer customer);
List<Customer> listCustomer();
}


package com.customer;

import java.util.List;

public class CustomerBoImpl implements CustomerBo{

CustomerDAO customerDAO;

public void setCustomerDAO(CustomerDAO customerDAO) {
this.customerDAO = customerDAO;
}
@Override
public void addCustomer(Customer customer) {
// TODO Auto-generated method stub
customerDAO.addCustomer(customer);

}
@Override
public void updateCustomer(Customer customer) {
// TODO Auto-generated method stub
customerDAO.updateCustomer(customer);

}
@Override
public void deleteCustomer(Customer customer)
{

customerDAO.deleteCustomer(customer);

}

@Override
public List<Customer> listCustomer() {
// TODO Auto-generated method stub
return customerDAO.listCustomer();
}
}

package com.customer;

import java.util.List;

public interface CustomerBo {

void addCustomer(Customer customer);

void deleteCustomer(Customer customer);

void updateCustomer(Customer customer);
List<Customer> listCustomer();
}

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

Please be sure to ask Struts questions in the Struts forum. I have moved this post there for you.

Also, please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information.

Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: StrutsPrepareandExecutefilter error