jsflive / jsf22-examples Goto Github PK
View Code? Open in Web Editor NEWJSFlive JSF 2.2 Examples
JSFlive JSF 2.2 Examples
your jsf22-cdi-viewscoped example is not one because you use ManagedBean instead of CDI Bean (@nAmed). CDI ViewScoped is managed by javax.faces.view.ViewScoped instead of javax.faces.bean.ViewScoped.
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 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 categorylist;
private List 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 getCategorylist() {
CategoryDAO cDao = new CategoryDAO();
this.categorylist= cDao.getAllcategoriesSelectItemName();
return categorylist;
}
public void setCategorylist(List 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 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.
Hi,
I'm using JSF 2.2.12 (latest version) and for some reason both tags below don't work:
<h:commandLink value="Cancel" action="#{bean.cancel}" immediate="true">
<f:resetValues render=":form" />
</h:commandLink >
<h:commandLink value="Edit">
<f:ajax render="@form" resetValues="true" />
<f:setPropertyActionListener value="#{item}" target="#{bean.product}" />
</h:commandLink>
I'm using correct namespaces on page (http://xmlns.jcp.org/jsf/core
and http://xmlns.jcp.org/jsf/html
). Eclipse doesn't recognize tag f:resetValues
, its code-completion doesn't work.
So far the only way I could clean up my form was programmatically using this method:
public void clean(UIComponent component) {
if (component instanceof EditableValueHolder) {
EditableValueHolder evh = (EditableValueHolder) component;
evh.resetValue();
}
if (component.getChildCount()>0){
for (UIComponent child : component.getChildren()) {
this.clean(child);
}
}
}
Could you help me to understand what's happening?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.