-
1. Re: How to pass parameters to List objects?
gebuh Feb 25, 2012 10:53 AM (in response to jinghuiyin)Use restrictions:
private static final String[] RESTRICTIONS = { "lower(documentDb.field) like lower(concat(#{documentDbList.documentDb.field},'%'))", "lower(documentDb.otherField) like lower(concat(#{documentDbList.documentDb.otherField},'%'))",}; setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
-
2. Re: How to pass parameters to List objects?
jinghuiyin Feb 26, 2012 7:57 PM (in response to gebuh)Yes I've seen this. However i don't know how / where I can set the value for #{documentDbList.documentDb.field}? Pass it in as a request parameter? Or how? Please help.
Thanks!
-
3. Re: How to pass parameters to List objects?
gebuh Feb 27, 2012 12:58 AM (in response to jinghuiyin)What do you have so far? Is this for a search page?
-
4. Re: How to pass parameters to List objects?
jinghuiyin Feb 27, 2012 9:04 AM (in response to gebuh)It's not a search page. I have studentId passed into this page as query string. And on this page, I need to show datatable with only #{documentDbList.documentDb.studentId} equal to this passed in studentId. How do I set it?
Thanks!
-
5. Re: How to pass parameters to List objects?
jinghuiyin Feb 27, 2012 10:25 AM (in response to jinghuiyin)Since I don't know how to set parameters for List objects, I'd like to use List<DocumentDb> as the data store for the datatable. will that be viable? Especially the sortable column header part?
-
6. Re: How to pass parameters to List objects?
gebuh Feb 27, 2012 3:47 PM (in response to jinghuiyin)I need some context, how are you passing the studentId to the page? Are you using pages.xml? Post what you have so far.
-
7. Re: How to pass parameters to List objects?
jinghuiyin Feb 28, 2012 9:24 AM (in response to gebuh)I got it working by putting it in the where clause:
@Override
public String getEjbql() {
return "select documentDb from DocumentDb documentDb where documentDb.studentProfile.studentId=#{studentProfileHome.instance.studentId}";
}
Thanks Beth for your help!
-
8. Re: How to pass parameters to List objects?
kragoth Mar 6, 2012 9:02 PM (in response to jinghuiyin)Qingxin Yi wrote:
I got it working by putting it in the where clause:
@Override
public String getEjbql() {
return "select documentDb from DocumentDb documentDb where documentDb.studentProfile.studentId=#{studentProfileHome.instance.studentId}";
}
Thanks Beth for your help!
Just remember that with this solution you are opening yourself up for SQL injection attacks.
-
9. Re: How to pass parameters to List objects?
jinghuiyin Mar 9, 2012 10:59 AM (in response to kragoth)So can you suggest a better solution to this?
Thanks!
-
10. Re: How to pass parameters to List objects?
cyberanto Mar 9, 2012 12:51 PM (in response to jinghuiyin)As Beth pointed out, this should be:
private static final String EJBQL = "select documentDb from DocumentDb documentDb";
private static final String[] RESTRICTIONS = {
"documentDb.studentProfile.studentId=#{studentProfileHome.instance.studentId}",};
// constructor - whatever the name of your class is
public DocumentDBQuery() {
setEjbql(EJBQL);
setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
setMaxResults(25);
}
depending on requirements & re-usability goals, you may also consider using a Criteria Seam Component (set up in component.xml) of StudentProfile class to make your queries more flexible. Look at "Seam in Action" 10.4. Smarter Queries with the Query Component, and 10.4.5 Placing restrictions on the result set - Query by Example