Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Connection problem between category and subcategory in jsf  RSS feed

 
badcat Rapter
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I devised a sample category with subcategory module in jsf by eclipse. I made an adding category module without any issue but I couldn't make an adding subcategory under related category .  Here the code below.

Suncategory .xhtml



<h:form>

    <p:panelGrid columns="2">

        <h:outputLabel value="Category Name></h:outputLabel>

        <p:selectOneMenu value="#{subCategoryMB.categoryName}">
            <f:selectItem itemLabel="Select Category" itemValue=""></f:selectItem>
            <f:selectItems value="#{subCategoryMB.categorylist}" />
        </p:selectOneMenu>

        <h:outputLabel value="Category Name"></h:outputLabel>
        <p:inputText value="#{subCategoryMB.subcategory.subName}"></p:inputText>

        <h:outputLabel value="Category Description"></h:outputLabel>
        <p:inputText value="#{subCategoryMB.subcategory.subNameDes}"></p:inputText>

        <h:commandButton value="Add Subcategory" action="#{subCategoryMB.addSubCategory()}"></h:commandButton>


    </p:panelGrid>


</h:form>
</h:body



Category Dao

public List getAllcategoriesbyName(String name) {
// TODO Auto-generated method stub
Session session = HibernateUtil.getSessionFactory().openSession();

    try {

        List<Category> liste = session.createQuery("from Category C where name='"+name+"'").list();
        return liste;


    } catch (Exception e) {
        e.printStackTrace();

    }finally {

        session.close();

    }
    return null;
}

public List<Category> getAllcategoriesSelectItemName() {
// TODO Auto-generated method stub
Session session = HibernateUtil.getSessionFactory().openSession();

try {

List<Category> liste = session.createQuery("Select C.name from Category C").list();

return liste;


} catch (Exception e) {
e.printStackTrace();

}finally {

session.close();

}
return null;
}


SubCategoryMB


public class SubCategoryMB {

SubCategory subcategory = new SubCategory();

private String categoryName;
private List<Category> categorylist;
private List<SubCategory> subCategoryList;
private Category category= new Category();

public SubCategoryMB() {
    // TODO Auto-generated constructor stub
}

public SubCategory getSubcategory() {
    return subcategory;
}

public void setSubcategory(SubCategory subcategory) {
    this.subcategory = subcategory;
}

public List<Category> getCategorylist() {
    CategoryDAO cDao = new CategoryDAO();
    this.categorylist= cDao.getAllcategoriesSelectItemName();
    return categorylist;
}

public void setCategorylist(List<Category> categorylist) {
    this.categorylist = categorylist;
}


public String getCategoryName() {
    return categoryName;
}

public void setCategoryName(String categoryName) {
    this.categoryName = categoryName;
}


public Category getCategory() {
    return category;
}

public void setCategory(Category category) {
    this.category = category;
}


public List<SubCategory> getSubCategoryList() {
    SubCategoryDAO subDao = new SubCategoryDAO();
    this.subCategoryList= subDao.getAllSubcategories();
    return subCategoryList;
}

public void addSubCategory(){

           // ISSUE
                categorylistbySubCategory= new CategoryDAO().getAllcategoriesbyName(categoryName);
category.setId(categorylistbySubCategory.get(0).getId());
subcategory.setCategory(category);
subcategory.setSubName(subcategory.getSubName());
subcategory.setSubNameDes(subcategory.getSubNameDes());
new SubCategoryDAO().addSubCategory(subcategory);
}
}

There is a problem about addSubCategory(). I can't add subcategory to its category.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of:


Try



EL for backing bean properties is not supposed to be coded as method calls. These expressions are resource references. Results can be unpredictable when you code logic on a JSF View template.
 
badcat Rapter
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried action="#{subCategoryMB.addSubCategory} but nothing changed.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try changing your JavaRanch display name. We don't have many rules here, but obvious "handles" or aliases are not allowed. I realize that at the moment, anyone drawing attention to themselves in Turkey runs certain risks, but that's our policy.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!