This content has been marked as final.
Show 2 replies
-
1. Re: reading a form value in EntityHome constructor - how??
jerry426 Jan 9, 2009 7:43 AM (in response to jerry426)I meant to say EntityQuery, not EntityHome!
-
2. Re: reading a form value in EntityHome constructor - how??
jerry426 Jan 10, 2009 3:06 AM (in response to jerry426)I figured out a solution to my problem. I was trying to get access to a submitted form value in my EntityQuery constructor (which was originally created by seam-gen), however, every other way to do it I could find would not work in the constructor.
Perhaps there's a cleaner/better way to do this - but it's working well so I'm happy :-)
My relevant class level declarations:
// WHERE 1=1 is in here so we can simply append AND statements elsewhere in this class. private String EJBQL = "SELECT ticket FROM Ticket ticket WHERE 1=1"; // this gives us direct access to the RequestParameterMap. private Map<String, String> requestParameters = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
Then I made an override for getEjbql() like this:
@Override public String getEjbql() { applyGroupFilter(); applyDateRangeFilter(); applyLocationFilter(); return EJBQL; }
then I can modify EJBQL:
private void applyGroupFilter() { List<String> groupList = someMethod(requestParameters.get("groupId")); // make sure the SQL is harmlessly valid if groupList is empty groupList.add("-1"); // and add the list to the EJBQL EJBQL += " AND id IN (" + StringUtils.join(groupList, ",") + ")"; }
Now when the rest of the framework code executes, it will get the modified EJBQL value.