使用 Seam 的表达式语言中的 EJB-QL:查找多个值
我试图想出一个表达式,它将在列中找到两个值。我正在使用 JBoss 4.2.2、JSF 1.2、RichFaces 3.3。
在这两个例子中:
"personData.status in (#{personSortDataList.statusChoice == 'A' ? "
+ "personSortDataList.statusChoice : null})",
"personData.status in (#{personSortDataList.statusChoice == 'I' ? "
+ "personSortDataList.statusChoice : null})",
效果很好。当我尝试组合它们时:
"#{personSortDataList.statusChoice == 'B' ? "
+ "(personData.status in (A, I) : null})", // Done this several different ways
我无法弄清楚要使用什么类型的表达式来拉入 A 和 I。这些查询附加到 h:selectOneRadio:
<h:panelGrid columns="2">
<b>#{messages['Status']}: </b>
<h:selectOneRadio layout="lineDirection"
value="#{personSortDataList.statusChoice}">
<f:selectItem itemLabel="#{messages['Active']}" itemValue="A" />
<f:selectItem itemLabel="#{messages['Inactive']}" itemValue="I" />
<f:selectItem itemLabel="#{messages['Active and Inactive']}" itemValue="B" />
</h:selectOneRadio>
</h:panelGrid>
对于 bean,我有(查询除外):
@Name("personSortDataList")
public class PersonSortDataList extends EntityQuery<PersonData>
{
private static final long serialVersionUID = 1L;
...
private Character statusChoice;
...
private static final String EJBQL = "Select personData From PersonData personData";
private static final String[] RESTRICTIONS =
{
...
"personData.status in (#{personSortDataList.statusChoice == 'A' ? "
+ "personSortDataList.statusChoice : null})",
"personData.status in (#{personSortDataList.statusChoice == 'I' ? "
+ "personSortDataList.statusChoice : null})",
"#{personSortDataList.statusChoice == 'B' ? "
+ "(personData.status in (A, I) : null}",
...
};
public CIMinMax ciMinMax;
public CIMinMax getCiMinMax()
{
return ciMinMax;
}
public void setCiMinMax(CIMinMax ciMinMax)
{
this.ciMinMax = ciMinMax;
}
private PersonData personData;
public PersonSortDataList()
{
personData = new PersonData();
personData.setId(new PersonDataId());
ciMinMax = new CIMinMax();
setEjbql(EJBQL);
setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
setMaxResults(Integer.valueOf(300));
}
public PersonData getPersonData() {
return personData;
}
public void setPersonData(PersonData personData) {
this.personData = personData;
}
@Override
protected String getCountEjbql()
{
setUseWildcardAsCountQuerySubject(true);
return super.getCountEjbql();
}
...
public void setStatusChoice(Character statusChoice) {
this.statusChoice = statusChoice;
}
public Character getStatusChoice() {
return statusChoice;
}
}
任何非常感谢您的帮助!
I'm trying to come up with an Expression that will find two values within a column. I'm using JBoss 4.2.2, JSF 1.2, RichFaces 3.3.
In these two single examples:
"personData.status in (#{personSortDataList.statusChoice == 'A' ? "
+ "personSortDataList.statusChoice : null})",
"personData.status in (#{personSortDataList.statusChoice == 'I' ? "
+ "personSortDataList.statusChoice : null})",
It works great. When I try to combine them:
"#{personSortDataList.statusChoice == 'B' ? "
+ "(personData.status in (A, I) : null})", // Done this several different ways
I can't figure out what type of expression to use to pull in both A and I. These queries are attached to h:selectOneRadio:
<h:panelGrid columns="2">
<b>#{messages['Status']}: </b>
<h:selectOneRadio layout="lineDirection"
value="#{personSortDataList.statusChoice}">
<f:selectItem itemLabel="#{messages['Active']}" itemValue="A" />
<f:selectItem itemLabel="#{messages['Inactive']}" itemValue="I" />
<f:selectItem itemLabel="#{messages['Active and Inactive']}" itemValue="B" />
</h:selectOneRadio>
</h:panelGrid>
For the bean, I have (other than the queries):
@Name("personSortDataList")
public class PersonSortDataList extends EntityQuery<PersonData>
{
private static final long serialVersionUID = 1L;
...
private Character statusChoice;
...
private static final String EJBQL = "Select personData From PersonData personData";
private static final String[] RESTRICTIONS =
{
...
"personData.status in (#{personSortDataList.statusChoice == 'A' ? "
+ "personSortDataList.statusChoice : null})",
"personData.status in (#{personSortDataList.statusChoice == 'I' ? "
+ "personSortDataList.statusChoice : null})",
"#{personSortDataList.statusChoice == 'B' ? "
+ "(personData.status in (A, I) : null}",
...
};
public CIMinMax ciMinMax;
public CIMinMax getCiMinMax()
{
return ciMinMax;
}
public void setCiMinMax(CIMinMax ciMinMax)
{
this.ciMinMax = ciMinMax;
}
private PersonData personData;
public PersonSortDataList()
{
personData = new PersonData();
personData.setId(new PersonDataId());
ciMinMax = new CIMinMax();
setEjbql(EJBQL);
setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
setMaxResults(Integer.valueOf(300));
}
public PersonData getPersonData() {
return personData;
}
public void setPersonData(PersonData personData) {
this.personData = personData;
}
@Override
protected String getCountEjbql()
{
setUseWildcardAsCountQuerySubject(true);
return super.getCountEjbql();
}
...
public void setStatusChoice(Character statusChoice) {
this.statusChoice = statusChoice;
}
public Character getStatusChoice() {
return statusChoice;
}
}
Any help is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的同事找到了解决方案:
到目前为止,该方法工作正常
My coworker found a solution:
This works correctly so far