Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support request scoped beans and stateless views in op:dataTable
- Loading branch information
Showing
12 changed files
with
326 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/org/omnifaces/optimusfaces/component/ExtendedDataTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2020 OmniFaces | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package org.omnifaces.optimusfaces.component; | ||
|
||
import javax.faces.context.FacesContext; | ||
import javax.faces.model.DataModel; | ||
|
||
import org.omnifaces.optimusfaces.model.LazyPagedDataModel; | ||
import org.primefaces.component.datatable.DataTable; | ||
|
||
/** | ||
* <p> | ||
* This extended data table is already automatically registered via our <code>faces-config.xml</code>. | ||
* This will preload lazy loaded model for decode against a request scoped bean or a stateless view. | ||
*/ | ||
public class ExtendedDataTable extends DataTable { | ||
|
||
@Override | ||
protected void preDecode(FacesContext context) { | ||
if (context.isPostback() && isLazy()) { | ||
DataModel<?> model = getDataModel(); | ||
|
||
if (model instanceof LazyPagedDataModel && model.getWrappedData() == null) { | ||
((LazyPagedDataModel<?>) model).preloadPage(context, this); | ||
} | ||
} | ||
|
||
super.preDecode(context); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/test/java/org/omnifaces/optimusfaces/test/view/OptimusFacesITLazyStatelessBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2020 OmniFaces | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package org.omnifaces.optimusfaces.test.view; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.context.RequestScoped; | ||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
|
||
import org.omnifaces.optimusfaces.model.PagedDataModel; | ||
import org.omnifaces.optimusfaces.test.model.Person; | ||
import org.omnifaces.optimusfaces.test.service.PersonService; | ||
|
||
@Named | ||
@RequestScoped | ||
public class OptimusFacesITLazyStatelessBean { | ||
|
||
private PagedDataModel<Person> lazyPersons; | ||
|
||
@Inject | ||
private PersonService personService; | ||
|
||
@PostConstruct | ||
public void init() { | ||
lazyPersons = PagedDataModel.lazy(personService).build(); | ||
} | ||
|
||
public PagedDataModel<Person> getLazyPersons() { | ||
return lazyPersons; | ||
} | ||
|
||
} |
Oops, something went wrong.