-
1. Re: Bypassing validations when using EntityQuery
pmuir Feb 18, 2008 4:52 PM (in response to boevink.boevinkp.xs4all.nl)Show us code.
-
2. Re: Bypassing validations when using EntityQuery
boevink.boevinkp.xs4all.nl Feb 18, 2008 4:56 PM (in response to boevink.boevinkp.xs4all.nl)
Pete Muir wrote on Feb 18, 2008 04:52 PM:
Show us code.
I have an entity User.java:
package web.entity.user; import ..... import org.hibernate.validator.Email; @Entity public class User implements Serializable { //seam-gen attributes (you should probably edit these) private Long id; private Integer version; private String username; private String password; private String email; @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=64) public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } @Length(max=64) public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Email @Length(max=64) public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } }
My seam-gen generated entityQuery (UserList.java):
package nl.wkm.orionglobe.web.session; import nl.wkm.orionglobe.web.entity.user.*; import org.jboss.seam.annotations.Name; import org.jboss.seam.framework.EntityQuery; import java.util.List; import java.util.Arrays; @Name("userList") public class UserList extends EntityQuery { private static final String[] RESTRICTIONS = { "lower(user.email) like concat(lower(#{userList.user.email}),'%')", "lower(user.password) like concat(lower(#{userList.user.password}),'%')", "lower(user.username) like concat(lower(#{userList.user.username}),'%')", }; private User user = new User(); @Override public String getEjbql() { return "select user from User user"; } @Override public Integer getMaxResults() { return 25; } public User getUser() { return user; } @Override public List<String> getRestrictions() { return Arrays.asList(RESTRICTIONS); } }
My STRIPPED seam-gen generated UserList.xhtml:
<!DOCTYPE composition 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: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" xmlns:a="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"> <head></head> <body> <h:messages globalOnly="true" styleClass="message" id="globalMessages"/> <h:form id="userSearch" styleClass="edit"> <h:inputText id="username" value="#{userList.user.username}"/> <h:inputText id="email" value="#{userList.user.email}"/> <div class="actionButtons"> <h:commandButton id="search" value="Search" action="/system/UserList.xhtml"/> </div> </h:form> </body> </html>
The STRIPPED Seam-gen generated UserList.page.xml:
<?xml version="1.0" encoding="UTF-8"?> <page xmlns="http://jboss.com/products/seam/pages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.0.xsd"> <param name="username" value="#{userList.user.username}"/> <param name="email" value="#{userList.user.email}"/> </page>
All what's left now is a 'naked' html form with two input fields.
If filling in a name in the second (e-mail address) field without @ and pressing the search button, a message will be shown: must be a well-formed email addressI'm using:
- jboss-seam-2.0.1.GA
- jboss-4.2.2.GA
- jdk1.5
-
3. Re: Bypassing validations when using EntityQuery
svadu Feb 19, 2008 11:13 AM (in response to boevink.boevinkp.xs4all.nl)Btw, I've hit the same problem yesterday. The code is generated by seam gen (of course validators were added at a later stage). It's very simple to test - just put a min length validator and try search with no search parms.
-
4. Re: Bypassing validations when using EntityQuery
boevink.boevinkp.xs4all.nl Feb 19, 2008 11:37 AM (in response to boevink.boevinkp.xs4all.nl)And did you manage to solve it?
-
5. Re: Bypassing validations when using EntityQuery
svadu Feb 19, 2008 5:02 PM (in response to boevink.boevinkp.xs4all.nl)No - I had to drop validdators, I'd say it's a good candidate for a JIRA.
-
6. Re: Bypassing validations when using EntityQuery
pmuir Feb 19, 2008 5:54 PM (in response to boevink.boevinkp.xs4all.nl) -
7. Re: Bypassing validations when using EntityQuery
boevink.boevinkp.xs4all.nl Feb 20, 2008 8:31 AM (in response to boevink.boevinkp.xs4all.nl)
Pete Muir wrote on Feb 19, 2008 05:54 PM:
This is due to the page parameters
JBSEAM-1587Thanks!
Finally an answer...where can I vote for this issue ;-) -
8. Re: Bypassing validations when using EntityQuery
marx3 Feb 20, 2008 9:01 AM (in response to boevink.boevinkp.xs4all.nl)As I understand, it's possible to fix it via page parameters, how?
-
9. Re: Bypassing validations when using EntityQuery
pmuir Feb 20, 2008 11:14 AM (in response to boevink.boevinkp.xs4all.nl)Not atm, no.
-
10. Re: Bypassing validations when using EntityQuery
vargadan.danielvrg.gmail.com Feb 20, 2008 1:13 PM (in response to boevink.boevinkp.xs4all.nl)You can use a HashMap instance as your example component, i.e.:
<component name="exampleSubsystem" class="java.util.HashMap" scope="conversation" /> <framework:entity-query name="subsystemList" ejbql="select s from CaasSubsystem s" max-results="10" scope="conversation" order="subsystem" > <framework:restrictions> <value>lower(subsystem) like lower(#{exampleSubsystem.subsystem})</value> <value>lower(displayName) like lower(#{exampleSubsystem.displayName})</value> </framework:restrictions> </framework:entity-query>
-
11. Re: Bypassing validations when using EntityQuery
candiani Feb 21, 2008 1:28 PM (in response to boevink.boevinkp.xs4all.nl)Hi, you can create a field @Transient (i.e.:mailtransient) in User.java
Then, in UserList.java add a restriction on User.email with this field (UserList.user.mailtransient),
add in userList.page.xml a parameter mailtransient, and modify UserList.xhtml the search field email x mailtransient.
(It's a posibility, but is not very ellegant, but should work) -
12. Re: Bypassing validations when using EntityQuery
luxspes Apr 7, 2009 11:34 PM (in response to boevink.boevinkp.xs4all.nl)So... in other words... DTOs are back?
-
13. Re: Bypassing validations when using EntityQuery
joblini Apr 9, 2009 3:25 AM (in response to boevink.boevinkp.xs4all.nl)Just replace the
example bean
with a Hashmap, as suggested by the previous poster.Why does Seam Gen generate code that is so obviously wrong?
-
14. Re: Bypassing validations when using EntityQuery
dan.j.allen Apr 9, 2009 4:47 AM (in response to boevink.boevinkp.xs4all.nl)It's not a problem in seam-gen. The issue is that page parameters are applying the validators unconditionally. seam-gen just happens to use page parameters and expects them to do the right thing. So let's fix the real problem.