[JBoss Seam] - Query with empty restriction
by lightbulb432
I get the following exception when I have in components.xml the following query, but #{member.countries} refers to an empty list:
SELECT c FROM Country c where c IN (#{member.countries})
If you look at the root cause of the error the message says:
org.hibernate.hql.ast.QuerySyntaxException: unexpected end of subtree [SELECT c FROM Country c where c IN ()]
The #{member.countries} expression for a member that has no countries specified doesn't show up in the generated query ("SELECT c FROM Country c where c IN ()"). Why is this happening, and how could I cause the query to simply return an empty list instead of this exception?
Thanks.
javax.faces.el.EvaluationException: /list.xhtml @36,43 rendered="#{empty countries}": Cannot get value for expression '#{countries.resultList}'
| at com.sun.facelets.el.LegacyValueBinding.getValue(LegacyValueBinding.java:60)
| at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:1075)
| at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:241)
| at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:249)
| at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:573)
| 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.servlet.SeamRedirectFilter.doFilter(SeamRedirectFilter.java:29)
| at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
| at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
| at org.jboss.seam.servlet.SeamExceptionFilter.doFilter(SeamExceptionFilter.java:43)
| 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.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
| 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.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
| 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)
| Caused by: javax.faces.el.EvaluationException: Exception getting value of property resultList of base of type : org.jboss.seam.framework.EntityQuery$$EnhancerByCGLIB$$4d3f50d3_7
| at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:96)
| at org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(ELParserHelper.java:532)
| at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
| at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:383)
| at org.jboss.seam.core.Expressions$1.getValue(Expressions.java:53)
| at org.jboss.seam.framework.Query.getParameterValues(Query.java:332)
| at org.jboss.seam.framework.Query.evaluateAllParameters(Query.java:340)
| at org.jboss.seam.framework.EntityQuery.createQuery(EntityQuery.java:101)
| at org.jboss.seam.framework.EntityQuery.getResultList(EntityQuery.java:40)
| at org.jboss.seam.framework.EntityQuery$$FastClassByCGLIB$$225925e6.invoke(<generated>)
| 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.SeamInvocationContext.proceed(SeamInvocationContext.java:55)
| at org.jboss.seam.interceptors.OutcomeInterceptor.interceptOutcome(OutcomeInterceptor.java:21)
| at sun.reflect.GeneratedMethodAccessor146.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
| at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
| at org.jboss.seam.interceptors.RollbackInterceptor.rollbackIfNecessary(RollbackInterceptor.java:29)
| at sun.reflect.GeneratedMethodAccessor148.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
| at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
| at org.jboss.seam.interceptors.ConversationInterceptor.endOrBeginLongRunningConversation(ConversationInterceptor.java:52)
| at sun.reflect.GeneratedMethodAccessor145.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
| Caused by: javax.faces.el.EvaluationException: Bean: org.jboss.seam.framework.EntityQuery$$EnhancerByCGLIB$$4d3f50d3_7, property: resultList
| at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:442)
| at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:82)
| at org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(ELParserHelper.java:532)
| at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
| at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:383)
| at org.jboss.seam.core.Expressions$1.getValue(Expressions.java:53)
| at org.jboss.seam.framework.Query.getParameterValues(Query.java:332)
| at org.jboss.seam.framework.Query.evaluateAllParameters(Query.java:340)
| at org.jboss.seam.framework.EntityQuery.createQuery(EntityQuery.java:101)
| at org.jboss.seam.framework.EntityQuery.getResultList(EntityQuery.java:40)
| at org.jboss.seam.framework.EntityQuery$$FastClassByCGLIB$$225925e6.invoke(<generated>)
| 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.SeamInvocationContext.proceed(SeamInvocationContext.java:55)
| at org.jboss.seam.interceptors.OutcomeInterceptor.interceptOutcome(OutcomeInterceptor.java:21)
| at sun.reflect.GeneratedMethodAccessor146.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
| at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
| at org.jboss.seam.interceptors.RollbackInterceptor.rollbackIfNecessary(RollbackInterceptor.java:29)
| at sun.reflect.GeneratedMethodAccessor148.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
| at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
| at org.jboss.seam.intercept.SeamInvocationContex
| 2007-03-18 14:22:34,375 ERROR [STDERR] t.proceed(SeamInvocationContext.java:64)
| at org.jboss.seam.interceptors.ConversationInterceptor.endOrBeginLongRunningConversation(ConversationInterceptor.java:52)
| at sun.reflect.GeneratedMethodAccessor145.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| 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)
| at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:82)
| at org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(ELParserHelper.java:532)
| at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
| at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:383)
| at org.jboss.seam.core.Expressions$1.getValue(Expressions.java:53)
| at org.jboss.seam.framework.Query.getParameterValues(Query.java:332)
| at org.jboss.seam.framework.Query.evaluateAllParameters(Query.java:340)
| at org.jboss.seam.framework.EntityQuery.createQuery(EntityQuery.java:101)
| at org.jboss.seam.framework.EntityQuery.getResultList(EntityQuery.java:40)
| at org.jboss.seam.framework.EntityQuery$$FastClassByCGLIB$$225925e6.invoke(<generated>)
| 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.SeamInvocationContext.proceed(SeamInvocationContext.java:55)
| at org.jboss.seam.interceptors.OutcomeInterceptor.interceptOutcome(OutcomeInterceptor.java:21)
| at sun.reflect.GeneratedMethodAccessor146.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
| at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
| at org.jboss.seam.interceptors.RollbackInterceptor.rollbackIfNecessary(RollbackInterceptor.java:29)
| at sun.reflect.GeneratedMethodAccessor148.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
| at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
| Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected end of subtree [SELECT c FROM Country c where c IN ()]
| at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:634)
| at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:73)
| at org.jboss.seam.framework.EntityQuery.getResultList(EntityQuery.java:41)
| at org.jboss.seam.framework.EntityQuery$$FastClassByCGLIB$$225925e6.invoke(<generated>)
| 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.SeamInvocationContext.proceed(SeamInvocationContext.java:55)
| at org.jboss.seam.interceptors.OutcomeInterceptor.interceptOutcome(OutcomeInterceptor.java:21)
| at sun.reflect.GeneratedMethodAccessor146.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
| at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
| at org.jboss.seam.interceptors.RollbackInterceptor.rollbackIfNecessary(RollbackInterceptor.java:29)
| at sun.reflect.GeneratedMethodAccessor148.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
| at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
| at org.jboss.seam.interceptors.ConversationInterceptor.endOrBeginLongRunningConversation(ConversationInterceptor.java:52)
| at sun.reflect.GeneratedMethodAccessor145.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
| at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:169)
| at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:64)
| at org.jboss.seam.interceptors.TransactionInterceptor$1.work(TransactionInterceptor.java:28)
| at org.jboss.seam.util.Work.workInTransaction(Work.java:37)
| at org.jboss.seam.interceptors.TransactionInterceptor.doInTransactionIfNecessary(TransactionInterceptor.java:23)
| at sun.reflect.GeneratedMethodAccessor147.invoke(Unknown Source)
| Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected end of subtree [SELECT c FROM Country c where c IN ()]
| at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
| at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
| at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
| at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:235)
| at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
| at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
| at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
| at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
| at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
| at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
| at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1113)
| at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
| at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
| at org.jboss.seam.framework.EntityQuery.getResultList(EntityQuery.java:41)
| at org.jboss.seam.framework.EntityQuery$$FastClassByCGLIB$$225925e6.invoke(<generated>)
| 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.SeamInvocationContext.proceed(SeamInvocationContext.java:55)
| at org.jboss.seam.interceptors.OutcomeInterceptor.interceptOutcome(OutcomeInterceptor.java:21)
| at sun.reflect.GeneratedMethodAccessor146.invoke(Unknown Source)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4029206#4029206
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4029206
19Â years, 1Â month
[JBoss Seam] - Re: SeamRemoting Spring DelegatingVariableResolver
by dan.j.allen
Oh yeah! I finally figured out a way to do away with the need for the delegating variable resolver all together, which in my mind really feels like the right solution to this problem! I am now using <seam:component> to expose my Spring bean as a native Seam component instance rather than relying on the variable resolver to look it up for me each time. Just the performance gain alone is going to make this worthwhile.
"What was the problem before?" you ask. Ah, well, Spring proxies were giving me quite a stumble. After A LOT of debugging inside of Eclipse, I finally got to the bottom of the matter. Seam can only expose Cglib proxies created by Spring, not JDK proxies (and Spring cannot do javassist, which would be another alternative). Since the default for Spring is to use JDK proxies, I was facing a sure failure.
Long story short, imagine that you have a TransactionProxyFactoryBean that you want to inject into a Seam managed component acting as a JSF backing bean...pretty standard stuff for Spring folks. Here is how it is done in 3 steps. (I am taking a somewhat complex example, courtesy of Appfuse).
CourseManagerImpl.java - business object
public class CourseManagerImpl extends org.appfuse.service.impl.GenericManagerImpl<Course, Long> implements CourseManager {
| // make CGLIB happy, feed it a default constructor
| public CourseManagerImpl() {
| super( null );
| }
|
| public CourseManagerImpl( GenericDao<Course, Long> courseDao ) {
| super( courseDao );
| }
|
| // finder methods...
| }
applicationContext.xml - Spring configuration snippet
<bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
| <!-- Seam cannot work with JDK proxies, so we must instead use Cglib-enhanced objects -->
| <property name="proxyTargetClass" value="true" />
| <property name="optimize" value="true" />
| <property name="transactionAttributes">
| <props>
| <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
| <prop key="*">PROPAGATION_REQUIRED</prop>
| </props>
| </property>
| </bean>
|
| <bean id="courseManager" parent="baseTransactionProxy" lazy-init="true">
| <seam:component beanClass="com.example.CourseManagerImpl" />
| <property name="target">
| <bean class="com.example.CourseManagerImpl" autowire="constructor"/>
| </property>
| <property name="proxyInterfaces" value="com.example.CourseManager" />
| </bean>
CourseListAction - Seam component / JSF backing bean
@Name( "courseListAction" )
| @Scope( ScopeType.CONVERSATION )
| public class CourseListAction implements Serializable {
| @In( create = true )
| private CourseManager courseManager;
|
| // other stuff...
| }
Now, the injecting of the courseManager does not rely on the Spring-JSF variable resolver and hence is available during @WebRemote calls. Keep in mind that the Spring bean must be lazy or you get strange errors on startup.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4029204#4029204
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4029204
19Â years, 1Â month
[JBoss Seam] - Re: Extended Persistence Context without EntityManager
by dan.j.allen
Hmm, what you said makes perfect sense, though I feel that I did not do a good job of stating my question. As a proud owner of JPwH I can positively say that I understand that Hibernate is a provider of the JPA standard (and a very good one!)
Let me try to be a bit more clear. I want to put my Hibernate session factory (or Session?) in the conversation scope so that it reattaches to the JDBC data source on a new request, but still uses the same first-level session cache. However, I would like to be able to do so without the EJB-microcontainer. It appears that Seam must rely on the microcontainer to use the extended persistence context, and when it does so, it always appears to inject it using the EntityManager as a target.
Perhaps this pseudo-code would be more clear. I want to be able to do:
@PersistenceContext(type=EXTENDED)
| Session session;
Is something like this possible? Or would it be more like the configuration below?
<core:managed-hibernate-session name="extendedSession" scope="conversation" />
Basically, if there were anyway that the Seam developers could provide an example of a long running conversation that avoids the use of detacted objects using ONLY hibernate sessions, we would do backflips for you.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4029193#4029193
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4029193
19Â years, 1Â month
[JBoss Seam] - my CRUD way, is it right? show yours please!
by kaiak
jboss-seam-1.2.0
jboss-4.0.5.GA
jdk1.5.0_0.8
the following is my way to do CRUD,it works!
but I'm not sure if it will cause some potential problems ,like performance.
please show me yours!
I like seam so much!
package org.kaiak.model;
|
| import java.io.Serializable;
|
| import javax.persistence.Entity;
| import javax.persistence.GeneratedValue;
| import javax.persistence.Id;
| import javax.persistence.Table;
| import javax.persistence.Version;
|
| import org.hibernate.validator.Length;
| import org.jboss.seam.annotations.Name;
|
| @Entity
| @Name("permission")
| @Table(name = "t_myor_permission")
| public class Permission implements Serializable {
|
| //seam-gen attributes (you should probably edit these)
| private Long id;
| private Integer version;
| private String name;
|
| //add additional entity attributes
|
| //seam-gen attribute getters/setters with annotations (you probably should edit)
|
| @Id @GeneratedValue
| public Long getId() {
| return id;
| }
|
| public void setId(Long id) {
| this.id = id;
| }
|
| @Version
| public Integer getVersion() {
| return version;
| }
|
| private void setVersion(Integer version) {
| this.version = version;
| }
|
| @Length(max=20)
| public String getName() {
| return name;
| }
|
| public void setName(String name) {
| this.name = name;
| }
| }
|
| package org.kaiak.service;
|
| import javax.ejb.Local;
|
| @Local
| public interface PermissionManager {
| public String persist();
| public String edit();
| public String delete();
| public void findPermissions(); public void destroy();
|
| //add additional interface methods here
| }
|
| package org.kaiak.service;
|
| import java.util.List;
|
| import javax.ejb.Remove;
| import javax.ejb.Stateful;
| import javax.persistence.EntityManager;
|
| import org.jboss.seam.annotations.Begin;
| import org.jboss.seam.annotations.Destroy;
| import org.jboss.seam.annotations.End;
| import org.jboss.seam.annotations.Factory;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Logger;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Out;
| import org.jboss.seam.annotations.datamodel.DataModel;
| import org.jboss.seam.annotations.datamodel.DataModelSelection;
| import org.jboss.seam.core.FacesMessages;
| import org.jboss.seam.log.Log;
| import org.kaiak.model.Permission;
|
| @Stateful
| @Name("permissionManager")
| public class PermissionManagerBean implements PermissionManager {
|
| @Logger
| private Log log;
|
| @In
| FacesMessages facesMessages;
|
| @In
| EntityManager entityManager;
|
| @DataModel
| private List<Permission> permissionList;
|
| @In(required = false)
| @Out(required = false)
| private Permission permission;
|
| @DataModelSelection
| private Permission selectedPermission;
|
| @Begin
| @Factory("permissionList") public void findPermissions() {
| permissionList = entityManager.createQuery(
| "select perm from Permission perm order by perm.id")
| .getResultList();
| }
|
| @End(beforeRedirect = true)
| public String persist() {
| entityManager.persist(permission);
| return "list";
| }
|
| @End(beforeRedirect = true)
| public String delete() {
| permission = selectedPermission;
| permissionList.remove(permission);
| entityManager.remove(permission);
| return "list";
| }
|
| public String edit() {
| if (selectedPermission != null)
| permission = selectedPermission;
| return "form";
| }
|
| @Destroy
| @Remove
| public void destroy() {
| }
| }
|
|
| permissionList.xhtml
|
| <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
| <ui:composition xmlns="http://www.w3.org/1999/xhtml"
| xmlns:s="http://jboss.com/products/seam/taglib"
| xmlns:ui="http://java.sun.com/jsf/facelets"
| xmlns:f="http://java.sun.com/jsf/core"
| xmlns:h="http://java.sun.com/jsf/html"
| template="layout/template.xhtml">
|
| <ui:define name="body">
|
| <h1>permissionList</h1>
| <p>Generated list page</p>
|
| <h:messages globalOnly="true" styleClass="message"/>
|
| <h:outputText value="No permission exists"
| rendered="#{permissionList.rowCount==0}"/>
| <h:dataTable id="permissionList" var="p"
| value="#{permissionList}"
| rendered="#{permissionList.rowCount>0}">
| <h:column>
| <f:facet name="header">Id</f:facet>
| #{p.id}
| </h:column>
| <h:column>
| <f:facet name="header">Name</f:facet>
| <s:link id="permission" value="#{p.name}" action="#{permissionManager.edit}"/>
| </h:column>
| <h:column>
| <f:facet name="header">Action</f:facet>
| <s:link id="user" value="Delete" action="#{permissionManager.delete}"/>
| </h:column>
| </h:dataTable>
|
| <div class="actionButtons"><h3><h:outputText value="#{permission.name}"/></h3>
| <s:button id="done" value="Create permission"
| action="#{permissionManager.edit}"/>
| </div>
|
| </ui:define>
|
| </ui:composition>
|
|
|
permissionForm.xhtml
|
| <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
| <ui:composition xmlns="http://www.w3.org/1999/xhtml"
| xmlns:s="http://jboss.com/products/seam/taglib"
| xmlns:ui="http://java.sun.com/jsf/facelets"
| xmlns:f="http://java.sun.com/jsf/core"
| xmlns:h="http://java.sun.com/jsf/html"
| template="layout/template.xhtml">
|
| <ui:define name="body">
|
| <h1>permissionForm</h1>
| <p>Generated edit page</p>
|
| <h:messages globalOnly="true" styleClass="message"/>
|
| <h:form id="perm">
| <div class="dialog">
| <s:validateAll>
| <div class="prop">
| <span class="name">Name</span>
| <span class="value">
| <s:decorate>
| <h:inputText id="name" required="true"
| value="#{permission.name}"/>
| </s:decorate>
| </span>
| </div>
| </s:validateAll>
| </div>
| <div class="actionButtons">
| <h:commandButton id="save" value="Save"
| action="#{permissionManager.persist}"/>
| <s:button id="done" value="Done"
| propagation="end" view="/permissionList.xhtml"/>
| </div>
| </h:form>
|
| </ui:define>
|
| </ui:composition>
|
|
|
pages.xml
|
| <!DOCTYPE pages PUBLIC
| "-//JBoss/Seam Pages Configuration DTD 1.2//EN"
| "http://jboss.com/products/seam/pages-1.2.dtd">
|
| <pages no-conversation-view-id="/home.xhtml"
| login-view-id="/login.xhtml">
|
| <page view-id="*">
| <navigation>
| <rule if-outcome="home">
| <redirect view-id="/home.xhtml"/>
| </rule>
| </navigation>
| </page>
|
| <page view-id="/permissionList.xhtml">
| <navigation>
| <rule if-outcome="list">
| <redirect view-id="/permissionList.xhtml"/>
| </rule>
| <rule if-outcome="form">
| <redirect view-id="/permissionForm.xhtml"/>
| </rule>
| </navigation>
| </page>
|
| <page view-id="/permissionForm.xhtml">
| <navigation>
| <rule if-outcome="list">
| <redirect view-id="/permissionList.xhtml"/>
| </rule>
| </navigation>
| </page>
|
| <exception class="org.jboss.seam.framework.EntityNotFoundException">
| <redirect view-id="/error.xhtml">
| <message>Not found</message>
| </redirect>
| </exception>
|
| <exception class="javax.persistence.EntityNotFoundException">
| <redirect view-id="/error.xhtml">
| <message>Not found</message>
| </redirect>
| </exception>
|
| <exception class="javax.persistence.OptimisticLockException">
| <end-conversation/>
| <redirect view-id="/error.xhtml">
| <message>Another user changed the same data, please try again</message>
| </redirect>
| </exception>
|
| <exception class="org.jboss.seam.security.AuthorizationException">
| <redirect>
| <message>You don't have permission to do this</message>
| </redirect>
| </exception>
|
| <exception class="org.jboss.seam.security.NotLoggedInException">
| <redirect view-id="/login.xhtml">
| <message>Please log in first</message>
| </redirect>
| </exception>
|
| <exception>
| <redirect view-id="/error.xhtml">
| <message>Unexpected error, please try again</message>
| </redirect>
| </exception>
| </pages>
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4029190#4029190
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4029190
19Â years, 1Â month