Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JSF表的过滤器_Jsf_Jsf 2 - Fatal编程技术网

JSF表的过滤器

JSF表的过滤器,jsf,jsf-2,Jsf,Jsf 2,我想为JSF表添加过滤器,并根据过滤器值限制这些值 <h:inputText id="search" value="#{accounts.searchString}"></h:inputText> <h:commandButton value="Search" action="#{accounts.search()}"> <f:ajax execute="search" render="output"></f:ajax> &l

我想为JSF表添加过滤器,并根据过滤器值限制这些值

<h:inputText id="search" value="#{accounts.searchString}"></h:inputText>

<h:commandButton value="Search" action="#{accounts.search()}">
    <f:ajax execute="search" render="output"></f:ajax>
</h:commandButton>
完整代码:

如何将代码实现到链接中

我用这种方式修改了代码:

<div class="div_input_style">
    <h:inputText id="search" class="input_style" value="#{accounts.searchString}"></h:inputText>

    <h:commandButton class="theSpan" value="Search by title">
        <f:ajax execute="search" render="output"></f:ajax>
    </h:commandButton>
</div>

public列表(int firstRow、int rowCount、String sortField、boolean sortAscending)抛出SQLException
{
字符串SqlStatement=null;
如果(ds==null)
{
抛出新的SQLException();
}
连接conn=ds.getConnection();
如果(conn==null)
{
抛出新的SQLException();
}
字符串sortDirection=sortAscending?“ASC”:“DESC”;
SqlStatement=“从帐户中选择*
+其中?为NULL或?IN(用户名、名、姓)
+“按%S%S抵销的订单?限额?”;
stringsql=String.format(SqlStatement、sortField、sortDirection);
PreparedStatement ps=null;
ResultSet ResultSet=null;
List resultList=new ArrayList();
尝试
{
连接设置自动提交(错误);
布尔值=false;
ps=连接准备状态(sql);
ps.setString(1,搜索字符串);
ps.setString(2,搜索字符串);
ps.setInt(3,第一排);
ps.setInt(4,行计数);
resultSet=ps.executeQuery();
结果列表=ProcessorArrayList(结果集);
conn.commit();
承诺=真实;
}
最后
{
ps.close();
康涅狄格州关闭();
}
返回结果列表;
}

我认为最好的方法是使用,这样你就不需要完全接触SQL。好吧,在我的例子中,我更喜欢使用核心JSF。我有很多定制的东西。请帮个忙好吗?这个问题太宽泛了。请尝试自己实施,如果出现任何具体问题,请在此处询问。建议不要将搜索参数直接放在原始查询中,因为这会使SQL注入成为可能。改用查询参数。SQL注入不是问题。这是内部系统,我也使用准备好的语句。看看我使用惰性分页的代码。你能提出一些解决方案吗?试着问一个具体的问题,而不是在你前进的过程中把它变成一个完全不同的问题。你现在的问题令人困惑。它与答案相矛盾,所以我删除了它。另外,很多人不阅读链接后面的代码。只需在MCVE flavor中发布有问题的代码。如果你不能发布一个MCVE,但是只能发布100多行意大利面代码,那么你就会遇到另一个问题(这可以通过学习编写代码而不是复制粘贴代码来解决)。
<div class="div_input_style">
    <h:inputText id="search" class="input_style" value="#{accounts.searchString}"></h:inputText>

    <h:commandButton class="theSpan" value="Search by title">
        <f:ajax execute="search" render="output"></f:ajax>
    </h:commandButton>
</div>
public List<AccountsObj> list(int firstRow, int rowCount, String sortField, boolean sortAscending) throws SQLException
    {
        String SqlStatement = null;

        if (ds == null)
        {
            throw new SQLException();
        }

        Connection conn = ds.getConnection();
        if (conn == null)
        {
            throw new SQLException();
        }

        String sortDirection = sortAscending ? "ASC" : "DESC";

        SqlStatement = "SELECT * FROM ACCOUNT "
            + " WHERE ? IS NULL OR ? IN (USER_NAME, FIRST_NAME, LAST_NAME)"
            + " ORDER BY %S %S offset ? limit ? ";

        String sql = String.format(SqlStatement, sortField, sortDirection);

        PreparedStatement ps = null;
        ResultSet resultSet = null;
        List<AccountsObj> resultList = new ArrayList<>();

        try
        {
            conn.setAutoCommit(false);
            boolean committed = false;

            ps = conn.prepareStatement(sql);
            ps.setString(1, searchString);
            ps.setString(2, searchString);
            ps.setInt(3, firstRow);
            ps.setInt(4, rowCount);

            resultSet = ps.executeQuery();
            resultList = ProcessorArrayList(resultSet);

            conn.commit();
            committed = true;

        }
        finally
        {
            ps.close();
            conn.close();
        }

        return resultList;
    }