⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 categorybean.java

📁 一个ssh结构组成 的BS开发
💻 JAVA
字号:
package cn.hxex.library.view.bean;

import cn.hxex.library.exception.LibraryException;
import cn.hxex.library.model.Category;
import cn.hxex.library.view.util.FacesUtils;

public class CategoryBean extends BaseBean
{
	// the catalog id
	private String id;
	
	// the catalog name
	private String name;
	
	// the catalog description
	private String description;
	
	/**
	 * @return Returns the description.
	 */
	public String getDescription()
	{
		return description;
	}

	/**
	 * @param description The description to set.
	 */
	public void setDescription(String description)
	{
		this.description = description;
	}

	/**
	 * @return Returns the id.
	 */
	public String getId()
	{
		return id;
	}

	/**
	 * @param id The id to set.
	 */
	public void setId(String id)
	{
		this.id = id;
	}

	/**
	 * @return Returns the name.
	 */
	public String getName()
	{
		return name;
	}

	/**
	 * @param name The name to set.
	 */
	public void setName(String name)
	{
		this.name = name;
	}
	
	protected void init()
	{

	}

	/**
	 * Backing bean action to create a new category.
	 * 
	 * @return the navigation result
	 */
	public String createAction() 
	{
		this.logger.info( "Catalog createAction is invoked!" );

		Category category = convertToCategory();
		try
		{
			this.getServiceLocator().getCategoryService().saveCategory( category );
			
			this.logger.info( "Reset the Bean: categoryListBean." );
			FacesUtils.resetManagedBean( BeanNames.CATEGORY_LIST_BEAN );
			FacesUtils.resetManagedBean( BeanNames.CATEGORY_BEAN );
			
			String params[] = { this.name };
			FacesUtils.addInfoMessageById( "categoryBean_create_category_success", 
					params );
			
			return NavigationResults.SUCCESS;
		}
		catch ( LibraryException e )
		{
			FacesUtils.addErrorMessageById( e.getMessage() );
			return NavigationResults.RETRY;
		}
	}
	
	/**
	 * 进入商品分类信息修改页面
	 * 
	 * @return the navigation result
	 */
	public String editAction()
	{
		this.logger.info( "Catalog editAction is invoked!" );

		if( this.id!=null )
		{
			try
			{
				Category category = this.getServiceLocator().getCategoryService()
					.getCategory( this.id );
				converToCategoryBean( this, category );
				return NavigationResults.CATEGORY_EDIT;
			}
			catch( LibraryException ex )
			{
				FacesUtils.addErrorMessageById( ex.getMessage() );
			}
		}
		else
		{
			FacesUtils.addErrorMessage( "Edit Category's parameter Error!" );
		}
		return NavigationResults.CATEGORY_LIST;
	}
	
	/**
	 * 保存修改后的商品分类信息
	 * 
	 * @return the navigation result
	 */
	public String updateAction()
	{
		this.logger.info( "Catalog updateAction is invoked!" );

		Category category = convertToCategory();
		try
		{
			this.getServiceLocator().getCategoryService().updateCategory( category );
			
			this.logger.info( "Reset the Bean: categoryListBean." );
			FacesUtils.resetManagedBean( BeanNames.CATEGORY_LIST_BEAN );
			
			String params[] = { this.name };
			FacesUtils.addInfoMessageById( "categoryBean_update_category_success", 
					params );
			
			return NavigationResults.CATEGORY_LIST;
		}
		catch ( LibraryException e )
		{
			FacesUtils.addErrorMessageById( e.getMessage() );
			return NavigationResults.RETRY;
		}
	}
	
	/**
	 * 删除商品分类信息
	 * 
	 * @return the navigation result
	 */
	public String deleteAction()
	{
		this.logger.info( "Catalog deleteAction is invoked!" );
		
		try
		{
			this.getServiceLocator().getCategoryService().deleteCategory( this.id );

			this.logger.info( "Reset the Bean: categoryListBean." );
			FacesUtils.resetManagedBean( BeanNames.CATEGORY_LIST_BEAN );
			
			FacesUtils.addInfoMessageById( "categoryBean_delete_category_success" );
		}
		catch( LibraryException ex )
		{
			FacesUtils.addErrorMessageById( ex.getMessage() );
		}
				
		return NavigationResults.CATEGORY_LIST;
	}

	private Category convertToCategory()
	{
		Category category = new Category();
		category.setId( this.id );
		category.setName( this.name );
		category.setDescription( this.description );
		return category;
	}

	public static CategoryBean converToCategoryBean( CategoryBean categoryBean, 
			Category category )
	{
		categoryBean.setId( category.getId() );
		categoryBean.setName( category.getName() );
		categoryBean.setDescription( category.getDescription() );
		return categoryBean;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -