Field error in seam bean
petitefl3ur.petitefl3ur.gmail.com May 13, 2009 10:58 PMHi i have a problem to display some components like a simple list in a JSF page.
The goal of my code is to have a generic list of objects (lazy loaded) to display in different pages with a specific implementation.
In the implementation i have some bean variables that i need to initialize and move to choose the list i will display.
The problem is that if i put everything in one bean without any inheritance it works!
And with the code below i have this error :
java.lang.NumberFormatException: For input string: "choixCatalogue" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Integer.parseInt(Integer.java:447) at java.lang.Integer.parseInt(Integer.java:497) at javax.el.ListELResolver.coerce(ListELResolver.java:166) at javax.el.ListELResolver.getValue(ListELResolver.java:51) at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53) at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72) at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53) at org.jboss.el.parser.AstValue.getValue(AstValue.java:67) at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186) at org.jboss.seam.core.Expressions$1.getValue(Expressions.java:112) at org.jboss.seam.navigation.Param.getStringValueFromModel(Param.java:137) at org.jboss.seam.navigation.Pages.getStringValuesFromModel(Pages.java:762) ....
So the code, the generic list :
@Scope(ScopeType.CONVERSATION) public abstract class LazyList<T> extends AbstractList<T> implements Serializable { private static final long serialVersionUID = -7605315613035999016L; private static final int defaultPageSize = 5; protected Map<Integer, T> lazyList; protected int numberOfResults; protected int currentPage; protected boolean hasMore; protected int pageSize; @Create public void create() { lazyList = new HashMap<Integer, T>(); this.pageSize = defaultPageSize; this.numberOfResults = 0; this.currentPage = 0; this.hasMore = false; } public abstract void getFirstResults(); public abstract T getMoreResults(); public abstract int getCurrentLoadedSize(); public void lazyLoading() { if (!lazyList.containsKey(currentPage)) { T results = getMoreResults(); lazyList.put(currentPage, results); } lazyLoadingHasMore(); } @Override public T get(int i) { if (!lazyList.containsKey(i)) { T results = getMoreResults(); lazyList.put(i, results); } return lazyList.get(i); } public void lazyLoadingHasMore() { hasMore = (getCurrentLoadedSize() > pageSize) ? true : false; } public void nextPage() { if (!isLastPage()) { currentPage++; lazyLoading(); } } public void prevPage() { if (!isFirstPage()) { currentPage--; lazyLoading(); } } public boolean isFirstPage() { return ( get(currentPage) != null ) && ( currentPage == 0 ); } public boolean isLastPage() { return ( get(currentPage) != null ) && !hasMore; } @Override public int size() {return numberOfResults;} /** Accessors */ public Map<Integer, T> getLazyList() {return lazyList;} public void setLazyList(Map<Integer, T> lazyList) {this.lazyList = lazyList;} public int getCurrentPage() {return currentPage;} public void setCurrentPage(int currentPage) {this.currentPage = currentPage;} public boolean isHasMore() {return hasMore;} public void setHasMore(boolean hasMore) {this.hasMore = hasMore;} }
And its implentation :
The problem is with the choixCatalogue variable...but i don't understand why because it works if a merge the two files...
@Name("catalogue") @Scope(ScopeType.CONVERSATION) public class CatalogueAction extends LazyList<CataloguePageList> { private static final long serialVersionUID = -7606638159326958137L; @Logger Log logger; @In EntityManager entityManager; private int choixCatalogue = 0; private Long typeProduitId; @Override public void create() { super.create(); if (typeProduitId == null) { choixCatalogue = 0; getFirstResults(); } } public void rechercherCatalogue() { reset(); lazyLoading(); } public void switchCatalogue() {} @Override public void getFirstResults() { reset(); this.get(currentPage); } @Override public CataloguePageList getMoreResults() { if (this.getChoixCatalogue()==0) { return extractFromOffre(findAllOffres()); } return null; } @Override public int getCurrentLoadedSize() { return ((CataloguePageList)this.get(this.getCurrentPage())).size(); } public CataloguePageList extractFromOffre(List<Offre> listeOffres) { List<CatalogueProxy> listeProxys = new ArrayList<CatalogueProxy>(); for (Offre offre : listeOffres) { listeProxys.add(new CatalogueProxy(offre.getId(),"Offre",offre.getNom(),offre.getDescription())); } return new CataloguePageList(listeProxys); } /** Query */ @SuppressWarnings("unchecked") public List<Offre> findAllOffres() { some code... } /** Accessors */ public List<CatalogueProxy> pageCourrante() {return ((CataloguePageList)get(currentPage)).getPageList();} public int getChoixCatalogue() {return choixCatalogue;} public void setChoixCatalogue(int choixCatalogue) {this.choixCatalogue = choixCatalogue;} public Long getTypeProduitId() {return typeProduitId;} public void setTypeProduitId(int typeProduitId) {this.typeProduitId = new Long(typeProduitId);} }
the page.xml :
<page view-id="/catalogue.xhtml"> <param name="choixCatalogue" value="#{catalogue.choixCatalogue}"/> <param name="typeProduitId" value="#{catalogue.typeProduitId}"/> <begin-conversation flush-mode="MANUAL" join="true"/> </page>
and the catalogue.xhtml view, that's it there is no other EL expressions in this view (no display of the list) :
<h:form id="searchForm"> <a:region> <h:outputText styleClass="label" value="Catalogue : "/> <h:selectOneMenu value="#{catalogue.choixCatalogue}" required="true"> <f:selectItem itemValue="0" itemLabel="Offres promotionnelles"/> <f:selectItem itemValue="1" itemLabel="L'ensemble des produits Enov"/> <a:support event="onchange" reRender="typeProduitSelect" action="#{catalogue.switchCatalogue}"/> </h:selectOneMenu> </a:region> <br /> <a:outputPanel id="typeProduitSelect"> <rich:panel rendered="#{catalogue.choixCatalogue == 1}"> <h:outputText styleClass="label" value="Produits : "/> <h:selectOneMenu value="#{catalogue.typeProduitId}" required="true"> <f:selectItem itemValue="0" itemLabel="tous les produits"/> <s:selectItems value="#{listeTypeProduitsNoeud}" var="_type" itemValue="#{_type.id}" label="#{_type.nom}" /> </h:selectOneMenu> </rich:panel> </a:outputPanel> <br /> <h:commandLink action="#{catalogue.rechercherCatalogue}" styleClass="link"> <h:outputText styleClass="linkTextButton" escape="false" value="#{messages['enov.menu.button.recherche']}"/> </h:commandLink> </h:form>
Even if there is a error, the create() is ok. Everything is loaded in the lazylist when i log the whole thing...
I have just notice that all my views are no longer avalaible to display...with all the same error...
Have you some clues to help me solve this problem?
Thanks in advance, and sorry for my bad bad bad english...and code!
Bye.