使用 Seam 的表达式语言中的 EJB-QL:查找多个值

发布于 2024-11-09 02:16:44 字数 3089 浏览 0 评论 0原文

我试图想出一个表达式,它将在列中找到两个值。我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七月上 2024-11-16 02:16:44

我的同事找到了解决方案:

"not (personData.status not in (#{personSortDataList.statusChoice == 'B' ? " 
       + "'A' : null})",

"personData.status not in (#{personSortDataList.statusChoice == 'B' ? " 
       + "'I' : null}))", 

到目前为止,该方法工作正常

My coworker found a solution:

"not (personData.status not in (#{personSortDataList.statusChoice == 'B' ? " 
       + "'A' : null})",

"personData.status not in (#{personSortDataList.statusChoice == 'B' ? " 
       + "'I' : null}))", 

This works correctly so far

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文