New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using init params in filters #1035
Comments
@mppfiles since you would write a filter yourself, you can pass any parameters to its constructor. Here is an example https://github.com/javalite/javalite/blob/master/activeweb/src/main/java/org/javalite/activeweb/controller_filters/DBConnectionFilter.java#L70 for instance, you would configure such a filter like this: public class AppControllerConfig extends AbstractControllerConfig {
public void init(AppContext context) {
add(new DBConnectionFilter("default", true)).exceptFor(HomeController.class, IntegrationsController.class, KbController.class, BlogController.class, CacheController.class);
add(new DBConnectionFilter("events", false)).to(
StatusController.class,
MessagesController.class,
PdfController.class
);
add(new DBConnectionFilter("events", false)).to(
StatusController.class,
MessagesController.class,
CampaignsController.class,
AutoRespondersController.class,
ViewOnlineController.class,
ContactDetailsController.class,
ContactsController.class,
ExportController.class,
PdfController.class
);
}
} The code is from a real production app and shows that you can hook the same filter multiple times with different configurations. |
This is great, it should be documented! |
I thought this is clear since a developer using the framework would be writing and initializing the filters. I guess what is clear to us, might not be clear to an end user. We will document this. I'm closing this issue, but you can continue commenting if you have further questions. |
one other note, you can use AppConfig to initialize filters differently depending on environment (development, production, etc.) import static org.javalite.app_config.AppConfig.p;
public class AppControllerConfig extends AbstractControllerConfig {
public void init(AppContext context) {
add(new MyControllerFilter(p("domain_name")));
}
} For more info: https://javalite.io/app-config In any case, this is just code, no magic... |
With plain Java Servlets, it's possible to define servlet filters with external params, both in declarative (look for "example 2") and programmatic way. This increases reusability of filter classes.
I'm wondering if something similar is possible with ActiveWeb filters... cannot find any doc or code related to this.
The text was updated successfully, but these errors were encountered: