[JBoss Seam] - selectManyListbox and SelectItem error
by mgervais
Hi,
I'm trying to use two selectManyListBox to assign a list of roles to a user.
| <h:selectManyListbox value="#{rolemanager.source}" converter="#{rolemanager.converter}" size="5">
| <f:selectItems value="#{rolemanager.items}" />
| </h:selectManyListbox>
|
| <h:commandButton value="add" action="#{rolemanager.add}" />
| <h:commandButton value="remove" action="#{rolemanager.remove}" />
|
| <h:selectManyListbox value="#{rolemanager.selected}" converter="#{rolemanager.converter}" size="5">
| <f:selectItems value="#{rolemanager.destination}" />
| </h:selectManyListbox>
|
when I click on "Add", the list "source" in role manager is a list of Role and not a list of SelectItem, I'd like to know if it's a normal behaviour... I expect to have a List of SelectItem...
the Complte code is
RoleManager.java
| @Stateful
| @Scope(SESSION)
| @Name("rolemanager")
| public class RoleManagerBean implements RoleManager {
|
| @In(value="agaetisDatabase")
| private EntityManager em;
|
| @EJB
| private CompanyFacade company;
|
| private List<Role> roles;
|
| private List<SelectItem> items;
|
| private List<SelectItem> source=new ArrayList<SelectItem>();
|
| private List<SelectItem> destination=new ArrayList<SelectItem>();
|
| private List<SelectItem> selected=new ArrayList<SelectItem>();
|
| @Create
| public void loadData() {
| roles = company.findAllRoles(em);
|
| items=new ArrayList<SelectItem>(roles.size());
| for(Role role : roles)
| items.add(new SelectItem(role, role.getRole()));
| }
|
| public List<Role> getRoles() {
| return roles;
| }
|
| public Converter getConverter() {
|
| return new Converter(){
| public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException {
| if(value==null)
| return null;
|
| for(Role role : roles)
| if(role.getRole().equals(value))
| return role;
| return null;
| }
| public String getAsString(FacesContext context, UIComponent component, Object value) throws ConverterException {
| return value==null ? null : ((Role)value).getRole();
| }
| };
| }
|
| public List<SelectItem> getItems() {
| return items;
| }
|
| public void setItems(List<SelectItem> items) {
| this.items = items;
| }
|
| public List<SelectItem> getDestination() {
| return destination;
| }
|
| public void setDestination(List<SelectItem> destination) {
| this.destination=destination;
| }
|
| public List<SelectItem> getSource() {
| return source;
| }
|
| public void setSource(List<SelectItem> source) {
| this.source=source;
| }
|
| public void setSelected(List<SelectItem> selected) {
| this.selected = selected;
| }
|
| public List<SelectItem> getSelected() {
| return selected;
| }
|
| public void add() {
| destination.addAll(source);
| source.clear();
| }
|
| public void remove() {
| source.addAll(destination);
| destination.clear();
| }
|
| @Destroy
| @Remove
| public void destroy() {
| }
|
| public void processValueChange(ValueChangeEvent event) throws AbortProcessingException {
| System.out.println(event);
| }
| }
|
Role.java
| @Entity
| @Table
| @Scope(SESSION)
| @NamedQueries({@NamedQuery(name = MappedQueries.ROLE_QUERY_FIND_BY_ROLE, query = "select r from Role r where r.role=:role") })
| public class Role implements java.io.Serializable {
|
| private static final long serialVersionUID = 2;
|
| @Id
| @GeneratedValue(strategy = GenerationType.IDENTITY)
| @Column(precision = 3, scale = 0)
| private short idrole;
|
| @NotNull
| @Length(max=70)
| @Column(unique = true, nullable = false, length = 70)
| private String role;
|
| @Length(max=200)
| @Column(length = 200)
| private String description;
|
| @ManyToMany(mappedBy = "roles")
| private List<User> users;
|
| public Role() {
| }
|
| public Role(String role) {
| this.role = role;
| }
|
| public Role(String role, String description) {
| this(role);
| this.description = description;
| }
|
| public short getIdrole() {
| return idrole;
| }
|
| public void setIdrole(short idrole) {
| this.idrole = idrole;
| }
|
| public String getRole() {
| return role;
| }
|
| public void setRole(String role) {
| this.role = role;
| }
|
| public String getDescription() {
| return description;
| }
|
| public void setDescription(String description) {
| this.description = description;
| }
|
| public List<User> getUsers() {
| if (users == null)
| users = new Vector<User>(0);
| return users;
| }
|
| public void setUsers(List<User> users) {
| this.users = users;
| }
|
| /*
| * (non-Javadoc)
| *
| * @see java.lang.Object#hashCode()
| */
| @Override
| public int hashCode() {
| final int PRIME = 31;
| int result = 1;
| result = PRIME * result + idrole;
| return result;
| }
|
| /*
| * (non-Javadoc)
| *
| * @see java.lang.Object#equals(java.lang.Object)
| */
| @Override
| public boolean equals(Object obj) {
| if (this == obj)
| return true;
| if (obj == null)
| return false;
| if (getClass() != obj.getClass())
| return false;
| final Role other = (Role) obj;
| if (idrole != other.idrole)
| return false;
| return true;
| }
|
| @PrePersist
| public void format() {
| role = Formatter.captializeFirstLetter(role);
| }
| }
And the exception...
| java.lang.IllegalArgumentException: Collection referenced by UISelectItems with binding '#{rolemanager.destination}' and Component-Path : {Component-Path : [Class: org.ajax4jsf.framework.ajax.AjaxViewRoot,ViewId: /credentials.xhtml][Class: javax.faces.component.html.HtmlForm,Id: credentials][Class: javax.faces.component.html.HtmlSelectManyListbox,Id: _id33][Class: javax.faces.component.UISelectItems,Id: _id34]} does not contain Objects of type SelectItem
|
Mickael
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4029354#4029354
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4029354
19Â years, 1Â month
[JBoss Seam] - can not catch exception
by enesterov
Hi everyone,
I am trying to handle the situation when session is expired and user make an attempt to navigate to some other page within the same application. I tried to follow documentation and examples (defined exception in exceptions.xml, added seam filter in web.xml,...) but apparently still doing something wrong as every time I try to navigate to other page when session is expired I am getting ?An Error Occurred:? generated by Facelets page.
I am running patched seam1.2.0. Here is the exception which I am getting:
SEVERE: Error Rendering View[/customers.xhtml]
javax.faces.el.EvaluationException: /customers.xhtml @60,69 value="#{userSearch.pageSize}": Exception getting value of property pageSize of base of type : com.gg.mv.ui.interfaces.UserSearching$$EnhancerByCGLIB$$ed819530
at com.sun.facelets.el.LegacyValueBinding.getValue(LegacyValueBinding.java:60)
at javax.faces.component.UIOutput.getValue(UIOutput.java:77)
at org.apache.myfaces.shared_impl.renderkit.html.HtmlRendererUtils.getSubmittedOrSelectedValuesAsSet(HtmlRendererUtils.java:320)
at org.apache.myfaces.shared_impl.renderkit.html.HtmlRendererUtils.internalRenderSelect(HtmlRendererUtils.java:296)
at org.apache.myfaces.shared_impl.renderkit.html.HtmlRendererUtils.renderMenu(HtmlRendererUtils.java:252)
at org.apache.myfaces.shared_impl.renderkit.html.HtmlMenuRendererBase.encodeEnd(HtmlMenuRendererBase.java:54)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:536)
at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:242)
at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:239)
at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:239)
at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:554)
at org.ajax4jsf.framework.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:101)
at org.ajax4jsf.framework.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:197)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:384)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:138)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:79)
at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
at org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:84)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:67)
at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:223)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)
Caused by: javax.faces.el.EvaluationException: Bean: com.gg.mv.ui.interfaces.UserSearching$$EnhancerByCGLIB$$ed819530, property: pageSize
at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:442)
at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:82)
at com.sun.facelets.el.LegacyELContext$LegacyELResolver.getValue(LegacyELContext.java:141)
at com.sun.el.parser.AstValue.getValue(AstValue.java:117)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:192)
at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
at com.sun.facelets.el.LegacyValueBinding.getValue(LegacyValueBinding.java:56)
... 49 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:438)
... 55 more
Caused by: java.lang.ClassCastException: java.lang.String
at $Proxy199.getPageSize(Unknown Source)
at com.gg.mv.ui.interfaces.UserSearching$$FastClassByCGLIB$$3593f9f1.invoke()
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:45)
at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:74)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:57)
at org.jboss.seam.interceptors.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:40)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
at org.jboss.seam.interceptors.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:31)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103)
at org.jboss.seam.intercept.ClientSideInterceptor.intercept(ClientSideInterceptor.java:52)
at com.gg.mv.ui.interfaces.UserSearching$$EnhancerByCGLIB$$ed819530.getPageSize()
... 60 more
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4029353#4029353
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4029353
19Â years, 1Â month