Important probleme dans l'utilisation des commandLink
Je suis debutante au niveau java server faces
J'ai créé une appli avec les frameworks spring, hibernate et java server faces à l'aide de netbeans 6.
Les librairies utilisées sont les suivantes :
spring et java server faces : utilisation des librairie intégrées dans netbeans
Hibernate : import manuel des librairies.
Ma page JSP liste un ensemble de categories et doit permettre de basculer vers la page d'édition d'une categorie
Voici le code pour la jsp :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
<h:dataTable value="#{CategoryBean.categories}" var="category">
<h:column>
<f:facet name="header">
<h:outputText value="Title" />
</f:facet>
<h:outputText value="#{category.categoryid}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Body" />
</f:facet>
<h:outputText value="#{category.categoryname}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Update" />
</f:facet>
<h:commandLink action="#{category.doPrepapareEditCategory}">
<h:outputText value="Edit"/>
<f:param value="#{category.categoryid}" name="categoryId" />
</h:commandLink>
<%--<h:outputLink value="editCategory.jsf">
<h:outputText value="Edit" />
<f:param value="#{category.categoryid}" name="categoryId" />
</h:outputLink >
--%>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Delete" />
</f:facet>
<h:outputLink value="showcategories.jsf">
<h:outputText value="Delete" />
<f:param value="#{category.categoryid}" name="categoryId" />
</h:outputLink >
</h:column>
</h:dataTable> |
Le code du backin bean est :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| public class CategoryBean extends BaseBean {
//list of all the product backing beans
private List categories=null;
private Category category;
private BusinessEntityService commonService;
public CategoryBean() {
this.logger.debug("Category Bean is created");
category=new Category();
}
public Category getCategory() {
return this.category;
}
// permet de rechercher toutes les catégroies
public String dofindCategories(){
if (categories == null) {
try {
this.logger.debug("############# categories null --> commonService.getAllCategories");
categories = commonService.getAllCategories();
} catch (BusinessEntityException ex) {
Logger.getLogger("global").log(Level.SEVERE, null, ex);
return NavigationResults.FAILURE;
}
}
//return NavigationResults.CATEGORY_LIST;
return NavigationResults.CATEGORY_LIST;
}
public String doPrepapareEditCategory(){
try {
category = commonService.getCategory(getParamId("categoryId"));
//return NavigationResults.CATEGORY_LIST;
} catch (BusinessEntityException ex) {
Logger.getLogger("global").log(Level.SEVERE, null, ex);
return NavigationResults.FAILURE;
}
return NavigationResults.EDIT_CATEGORY;
}
public String doUpdateCategory(){
this.logger.debug("#DDD############ updateToDoAction()");
try {
this.commonService.updateCategory(this.category);
this.logger.debug("#DDD############ updateCategoryAction->success");
} catch (BusinessEntityException ex) {
Logger.getLogger("global").log(Level.SEVERE, null, ex);
return NavigationResults.FAILURE;
}
return NavigationResults.EDIT_CATEGORY;
}
public String deleteCategoryAction(){
try {
this.commonService.deleteCategory(this.category);
this.logger.debug("#DDD############ deleteCategoryAction->success");
} catch (BusinessEntityException ex) {
Logger.getLogger("global").log(Level.SEVERE, null, ex);
return NavigationResults.FAILURE;
}
return NavigationResults.SUCCESS;
}
public List getCategories(){
return categories;
}
/* public BusinessEntityService getCommonService() {
this.logger.debug("############# getting BusinessEntityService");
return commonService;
}*/
public void setCommonService(BusinessEntityService commonService) {
this.commonService = commonService;
}
} |
Le code de la classe Category est ( hibernate)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| public class Category {
//private int categoryid;
private Integer categoryid;
private String categoryname;
public Category() {
}
public Integer getCategoryid() {
return categoryid;
}
// private car generé par le conteneur
private void setCategoryid(Integer categoryid) {
this.categoryid = categoryid;
}
public String getCategoryname() {
return categoryname;
}
public void setCategoryname(String categoryname) {
this.categoryname = categoryname;
}
} |
Voici l'erreur :
-------------------------------------------------------------
------------------------------------------------------------
Citation:
When loadin the jsf page i have the following errors messages :
2 août 2007 20:10:07 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: "Servlet.service()" pour la servlet Faces Servlet a généré une exception
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at com.sun.rave.web.ui.appbase.renderer.CommandLinkRenderer.encodeBegin(CommandLinkRenderer.java:214)
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:785)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:269)
at com.sun.faces.renderkit.html_basic.TableRenderer.encodeChildren(TableRenderer.java:307)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:809)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:809)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
at com.sun.faces.application.ViewHandlerImpl.doRenderView(ViewHandlerImpl.java:244)
at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:175)
at com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.renderView(ViewHandlerImpl.java:298)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
--------------------------------------------------------------
Apparemment commandLink ne sait pas convertir Integer en String.
Comment résoudre ce problème?
L'implémentation JSf est celle de sun
manifest du jsf-api.jar :
Code:
1 2 3 4 5 6 7 8 9 10
| Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.5
Created-By: 1.5.0_04-b05 (Sun Microsystems Inc.)
Specification-Title: JavaServer Faces
Specification-Version: 1.2MR1
Implementation-Title: Sun Microsystems JavaServer Faces Implementation
Implementation-Version: 1.2_04-b10-p01
Implementation-Vendor: Sun Microsystems, Inc.
Implementation-Vendor-Id: com.sun
Extension-Name: javax.faces |
Manifest du jsf-impl.jar :
Code:
1 2 3 4 5 6 7 8 9 10
| Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.5
Created-By: 1.5.0_04-b05 (Sun Microsystems Inc.)
Specification-Title: JavaServer Faces
Specification-Version: 1.2MR1
Implementation-Title: Sun Microsystems JavaServer Faces Implementation
Implementation-Version: 1.2_04-b10-p01
Implementation-Vendor: Sun Microsystems, Inc.
Implementation-Vendor-Id: com.sun
Extension-Name: com.sun.faces |
J'utilise Tomcat 6.0.13