Thanks,
Guy
-----Original Message-----
From: Janap [mailto:[EMAIL PROTECTED]
Sent: Saturday, July 12, 2008 10:30 AM
To: [email protected]
Subject: Re: Datatable Filtering
Pseudo code,
if(dataTable == null) {
// this code avoids multiple calls to execute query , only called in the
render response phase
if (FacesContext.getCurrentInstance().getRenderResponse())
reloadDataModel();
}
public void reloadDataModel() {
myDAO.SQL_SELECT(getfilterCriteria()); // where filter criteria just
uses simple getter methods
data = myDAO.getTableData();
}
public String getFilterCriteria() {
String criteriaValue = getCriteria();
// criteria is a simple data member could be defined in same class or use
a separate FilterBean
return "where my criteria =" + criteriaValue;
}
The result of the above code is that the DataModel is not reloaded in the
apply request values phase. So you have to use saveState component for the
Datatable so that JSF restores values when form is submitted.
best wishes
Janap
Sent from a MacBook
bashan wrote:
>
> Yes, you are right it does make the code auglier. Can you explain
> about your solution briefly? You prepare the query from your bean or
> from external phase listener?
>
> Thanks,
> Guy
>
> Sent from my iPhone
>
> On 12/07/2008, at 00:06, Janap <[EMAIL PROTECTED]> wrote:
>
>>
>>
>> Hello ,
>>
>> Thx for the reply. I have found a solution in the meantime. I
>> execute my
>> query in the render response phase. Then my model values are properly
>> updated and then I have the filter values ready when I want to
>> execute the
>> query.
>>
>> I use saveState for saving the state of the Datatable.
>>
>> The way you did it works for one filter parameter but if you have many
>> filter criteria then the code will become cumbersome.
>>
>> Janap
>>
>>
>>
>>
>> bashan wrote:
>>>
>>> I have a also encountered this problem many time, and haven't found
>>> any
>>> reasonable way of doing it in JSF other than getting the value from
>>> the
>>> drop
>>> down as a query parameter and generating the table data directly
>>> from the
>>> getter.
>>>
>>> For example:
>>>
>>> private List data;
>>>
>>> public List getTableData()
>>> {
>>> if (data == null)
>>> {
>>> String selection = getQueryParameter("formData:myDropdown");
>>> // The parameter can be taken from the faces context, I don't
>>> remember the
>>> exact code now...
>>> data = myDAO.getTableData(selection);
>>> }
>>>
>>> Return data;
>>> }
>>>
>>> Hope it helps, or someone else give better solution.
>>>
>>> Guy.
>>>
>>>
>>> -----Original Message-----
>>> From: Janap [mailto:[EMAIL PROTECTED]
>>> Sent: Thursday, July 10, 2008 6:43 PM
>>> To: [email protected]
>>> Subject: Datatable Filtering
>>>
>>>
>>>
>>> Hello all ,
>>>
>>> I need to filter rows of the Datatable depending on the criteria
>>> entered
>>> by
>>> the user. The criteria is in the form of selectBox right above the
>>> Datatable.
>>>
>>> So , after the user enters the criteria and submits the form I
>>> capture
>>> the
>>> criteria and generate a new query and then load the Datatable with
>>> the new
>>> query. This is how I want it to work.
>>>
>>> I implemented it already but since my Datatable is loaded in the
>>> Apply
>>> Request Values phase, I am not able to read the new values of
>>> criteria
>>> before that. I am using immediate="true" and value binding on the
>>> selectBox
>>> component.
>>>
>>> What is the correct way to do this?? Do I have to use component
>>> binding to
>>> get new values of selectBox before the Datatable model reloads or
>>> do I
>>> need
>>> to push Datatable model reloading to the UpdateModel phase.
>>>
>>> I am using Request scope all throughout my application.
>>>
>>> Thx for the help,
>>> Janap.
>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Datatable-Filtering-tp18385566p18385566.html
>>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Datatable-Filtering-tp18385566p18412555.html
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>
>
--
View this message in context:
http://www.nabble.com/Datatable-Filtering-tp18385566p18416937.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.