jsf - CommandLink doesn't work. Tried everything -
it's first question on site :) first, sorry bad english, i'm learning :) plz, need help. i'm blocked application in jsf.
i have
<?xml version='1.0' encoding='utf-8' ?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://xmlns.jcp.org/jsf/core"> <body> <ui:composition template="./defaulttemplate.xhtml"> <ui:define name="content"> <h1 style="margin-bottom: 0px">#{msg.default_2}</h1> <br/> <ul style="padding-left: 0px"> <ui:repeat value="#{categorymb.categories}" var="categorie"> <h:outputlabel value=" -==- " style="color: #ff8620; font-size: 10px; padding-left: 0px"></h:outputlabel> <h:form> <h:commandlink value="#{categorie.categoryname}" action="#{categorymb.getitemsbycat(categorie.categoryid.id)}"/> </h:form> </ui:repeat> </ul> <ui:repeat value="#{categorymb.listitems}" var="item"> <div class="itemcategory"> <h:graphicimage class="item-image" url="#{item.urlimage}"/> <h:outputlabel value="#{item.price} €" class="prix"></h:outputlabel> <br/> <h2><h:outputlabel value="#{item.name}"></h:outputlabel></h2> <br/> <h:form> <h:commandlink value="#{msg.default_14}" action="#{itemmb.linkitem(item.id)}" ></h:commandlink> </h:form> </div> </ui:repeat> </ui:define> </ui:composition> </body> </html>
everything good, except second commandlink ! can't execute action. return on same page... tried , read subjects on site can't find solution. please, i'm asking you, me. i'm going crazy.
my bean categorymb :
package managedbean; import entitybean.item; import entitybean.translatecategory; import java.util.list; import javax.ejb.ejb; import javax.faces.bean.managedbean; import javax.faces.bean.managedproperty; import javax.faces.view.viewscoped; import sessionbean.itemfacadelocal; import sessionbean.translatecategoryfacadelocal; /** * * @author aurélien */ @managedbean @viewscoped public class categorymb { @ejb private itemfacadelocal itemfacade; @ejb private translatecategoryfacadelocal translatecategoryfacade; @managedproperty("#{internationalizationmb}") private internationalizationmb language; private list<item> listitems; /** * creates new instance of categorymb */ public categorymb() { } public list<translatecategory> getcategories () { return translatecategoryfacade.findbylanguage(language.getlocale().getlanguage()); } public void getitemsbycat (int idcat) { setlistitems(itemfacade.findbycat(idcat)); } public internationalizationmb getlanguage() { return language; } public void setlanguage(internationalizationmb language) { this.language = language; } public list<item> getlistitems() { return listitems; } public void setlistitems(list<item> listitems) { this.listitems = listitems; } }
and bean itemmb :
package managedbean; import javax.enterprise.context.sessionscoped; import java.io.serializable; import javax.faces.bean.managedbean; @managedbean @sessionscoped public class itemmb implements serializable { private int iditem; /** * creates new instance of itemmb */ public itemmb() { } public int getiditem() { return iditem; } public void setiditem(int iditem) { this.iditem = iditem; } public string linkitem(int id) { setiditem(id); return "item"; } }
you're mixing cdi @sessionscoped
jsf 2.x @sessionscoped
. noted in imports:
import javax.enterprise.context.sessionscoped; @managedbean @sessionscoped public class itemmb implements serializable { //... }
this makes managed bean have default scope, in jsf 2 @requestscoped
, managed bean re created on every request.
fix import to:
import javax.faces.bean.sessionscoped;
if happen use jsf 2.2.x, start working cdi 1.1. use @named
managed beans , use javax.faces.view.viewscoped
@viewscoped
.
more info:
Comments
Post a Comment