Integrating Scheduler into Web Application

2008-12-11 Thread wfroud

Hi,

I am trying to integrate a scheduler into my web application. I believe my
question is probably very trivial but I am missing some vital Java
knowledge. Please let me explain… 
My web application currently allows users to choose, customise and run
reports.
I now need to add a detailed scheduler so that users can choose when to run
the reports and how often etc.

I'm using Spring for the db access, and I was going to use Quartz for
scheduling.

A basic Quartz schedule looks something like the following:
public class SimpleExample {

public void run() throws Exception {
 
// First we must get a reference to a scheduler
// This schedule info is  stored in a db, defined in the
quartz.properties file.
SchedulerFactory sf = new StdSchedulerFactory();
Scheduler sched = sf.getScheduler();
 
// Add jobs and triggers to schedule.
 
// Start up the scheduler (nothing can actually run until the 
// scheduler has been started)
sched.start();
 
// Wait for a short period of time so scheduler has chance to run
jobs.
 
 sched.shutdown();
}
 
public static void main(String[] args) throws Exception {
 
SimpleExample example = new SimpleExample();
example.run();
 
}
 
}

More details about a really basic example can be found here:
http://wiki.opensymphony.com/display/QRTZ1/TutorialLesson1

I can run this fine as a standalone test.

The basics of my web application are as follows:

MyApp which extends WebApplication.
Loads of classes which extend WebPage
A MySession class which extends WebSession

What I'm not sure about is where I should be instantiating the
SchedulerFactory within my application so that all users can update any
schedule (i.e. so there is kind-of-like global access to the scheduler
object) and so that the SchedulerFactory is only instantiated the once.

I can't instantiate it in a web page as this will be user specific.
I could instantiate it in the MyApp class but then I don't have access to it
from the web pages.

Any help whatsoever, just to point me in the right direction, would be much
appreciated.

Thanks

Will 


-- 
View this message in context: 
http://www.nabble.com/Integrating-Scheduler-into-Web-Application-tp20960629p20960629.html
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Dynamic Form Data Retrieval

2008-06-17 Thread wfroud

Thanks for your suggestion Maurice, I had a bit of trouble getting the syntax
to work correctly so resorted to another solution which I've explained below
for those that might come across this post. It's probably not the best
solution but it's good enough for my demo tomorrow!

Instead of passing a model as the second argument to the getParamPanels
method I passed an object.
This object is then used to hold a list of Models.
Then when adding the components to the list I added the models to a list as
well stored within this second object:

for (QueryDefParam p : qdp) {

QueryParamValue valueModel = new QueryParamValue(); // this is a generic
model that I'm going to try and use for each component

if (TextField.equals(p.getName())) {
params.add(new TextFieldPanel(panel, new
 CompoundPropertyModel(compModel), p.getDescription()));
}
else if (CheckBox.equals(p.getName())) {
params.add(new CheckBoxPanel(panel, null,
 p.getDescription()));
}

response.addValues(valueModel); // we must add the new model to the list

}

Then when the Submit button is pressed I am able to just loop through the
list from the response object.

Thanks again,

Will


Mr Mean wrote:
 
 In the Button.onSubmit do getForm.visitChildren(FormComponent.class,
 new IVisitor()
 {
public Object component(Component component)
{
   //do something with the models from the components here.
}
 }
 
 Maurice
 
 On Fri, Jun 13, 2008 at 2:10 PM, wfroud [EMAIL PROTECTED] wrote:

 Hi All,

 I have successfully written some code to create a dynamic form depending
 on
 drop down selection.

 I have used the technique described here
 http://cwiki.apache.org/WICKET/forms-with-dynamic-elements.html

 A shortened copy of the code is below.

 The problem I'm now having is how to extract data entered into the
 dynamically generated components.
 I'm starting with trying to get information from the TextField component,
 so
 any help regarding
 this would be of enormous help. Please refer to the TODO comments below,
 I
 think I'm close.


 // Define a model to hold values for any component, at the moment just
 the
 TextField.

 final ComponentPanelModel compPanelModel = new ComponentPanelModel();

 // Define the list model.

 final List paramsList = getParamPanels(queryDef, compPanelModel);

 IModel paramsModel = new LoadableDetachableModel() {
protected Object load() {
return paramsList;
}
 };

 // Then add the list to the page.

 f.add(new ListView(paramsList, paramsModel) {

@Override
public ListView setReuseItems(boolean arg) {
// According to
 http://cwiki.apache.org/WICKET/using-listviews.html
// we need to add this or items will be removed and
 re-added,
// without being validated.
return super.setReuseItems(true);
}

@Override
protected void populateItem(ListItem item) {
Panel p = (Panel) item.getModelObject();
item.setModel(new CompoundPropertyModel(p));
item.add(p);
}

private void optimizedItemRemoval() {
// According to
 http://cwiki.apache.org/WICKET/forms-with-dynamic-elements.html
// this should be used to prevent components from
 forgetting content.
// Not sure how to yet.
}
 });

 // This is the method that returns the various panels:

 public List getParamPanels(QueryDef queryDef, ComponentPanelModel
 compModel)
 {

ListPanel params = new ArrayListPanel();
if (queryDef == null) {
return params;
}

ListQueryDefParam qdp =
 queryDefParamDao.getQueryDefParams(queryDef.getQueryDefId());

for (QueryDefParam p : qdp) {

if (TextField.equals(p.getName())) {
params.add(new TextFieldPanel(panel, new
 CompoundPropertyModel(compModel), p.getDescription()));
}
else if (CheckBox.equals(p.getName())) {
params.add(new CheckBoxPanel(panel,
 null, p.getDescription()));
}

}

return params;
 }

 f.add(new Button(save) {
public void onSubmit() {

// TODO Iterate through the list of panels, which may
 differ TextField,
 Check box etc.
// TODO For each one we need to be able to access the
 model objects value.

}
 });


 public class ComponentPanelModel {
private String textField;

public String getTextField() {
return textField;
}

public void setTextField(String textField) {
this.textField = textField

Re: ListChoice Crashing on 13th Load

2008-06-06 Thread wfroud

Thanks for the help, for anyone that reads this message stream I have
switched from the JDBC code to using the JDBCTemplate, my new DAO class is
as follows:

public class CategoryDao implements ICategoryDao {

private JdbcTemplate jt;

public void setDataSource(DataSource dataSource) {
this.jt = new JdbcTemplate(dataSource);
} 

public List getAllCategories() {

List results = this.jt.query(
SELECT Category_ID, Category FROM Category,
new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) 
throws SQLException {
return new 
Category(rs.getInt(Category_ID),
rs.getString(Category));
}
});

return results;
}
}

And it works perfectly.
-- 
View this message in context: 
http://www.nabble.com/ListChoice-Crashing-on-13th-Load-tp17672729p17687430.html
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



ListChoice Crashing on 13th Load

2008-06-05 Thread wfroud

Hi,

I've been having trouble getting my app to run for any reasonable period of
time without crashing. I've laid out a basic page that contains a 

ListChoice component, after loading this page 13 times (when I have more
components it's far less) it just hangs indefinitely.

I'm sure the problem is something to do with either storing heavy objects in
memory or a serialization issue (from all that I have read) but I 

can't work out why. 

I'm using Wicket version 1.2.6 in development mode with Java 5.

Here is my code:

public class Operations extends WebPage {

private String selection;

@SpringBean
private ICategoryDao categoryDao;

public void setCategoryDao(ICategoryDao categoryDao) {
this.categoryDao = categoryDao;
}

...

MyCategory catModel = new MyCategory();

ListChoice categories = new ListChoice(
categories,
new PropertyModel(catModel, category),
new LoadableDetachableModel() {
@Override
protected Object load() {
return categoryDao.getAllCategories();
}
}, 
new ChoiceRenderer(category, categoryId),
5); 

add(categories);

...
}


public class MyCategory { 

private Category category;

public Category getCategory() {
return category;
}

public void setCategory(Category category) {
this.category = category;
}

}   

public class CategoryDao implements ICategoryDao {

@SpringBean
private DataSource dataSource;

public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
} 

private Connection getConnection() {
return DataSourceUtils.getConnection(dataSource);
}

public List getAllCategories() {

List results = new ArrayList();

try {
PreparedStatement st = getConnection()
.prepareStatement(SELECT Category_ID, Category 
FROM Category);
try {
ResultSet rs = st.executeQuery();
while (rs.next()) {
results.add(
new 
Category(rs.getInt(Category_ID), rs.getString(Category))
);
}
return results;
} finally {
st.close();
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}

public class Category implements Serializable {
private int categoryId;
private String category;

public Category(int categoryId, String category) {
this.categoryId = categoryId;
this.category = category;
}

public String getCategory() {
return category;
}

public void setCategory(String category) {
this.category = category;
}

public int getCategoryId() {
return categoryId;
}

public void setCategoryId(int categoryId) {
this.categoryId = categoryId;
}
}

Please could you provide some code snippets or comments if you know why this
might be crashing.

Thanks very much for your time, much appreciated.

Regards, 

Will
-- 
View this message in context: 
http://www.nabble.com/ListChoice-Crashing-on-13th-Load-tp17672729p17672729.html
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Data Access Design for Pagination

2008-05-22 Thread wfroud

Hi,

I've been using the DefaultDataTable component in Wicket which allow me to
paginate through a few pages worth of multi column data.

I believe the general approach is to load all data from the database into
the session first (as a List of Domain Objects ?), then as navigation links
are clicked show subsets of this list?

I'm using Spring Beans Injection to inject the Data Access Object into a
subclass of SortableDataProvider (called QueryDataProvider).

Then within the QueryDataProviders constructor I'm calling a method in the
DataAccessObject to create the List of Data Objects. 

The DataProvider's iterator method then calls a subset of the List stored in
the DataAccessObject.  

I'm pretty sure this is an awful way of designing my data access, if I click
the nav links just a bit too fast I get the following error:

WicketMessage: After 1 minute the Pagemap null is still locked by:
Thread[http-8080-1,5,main], giving up trying to get the page for path:
16:entries:topToolbars:1:toolbar:span:navigator:navigation:1:pageLink

How should I be doing things differently? 

Thanks for any help, much appreciated.

Will
-- 
View this message in context: 
http://www.nabble.com/Data-Access-Design-for-Pagination-tp17404681p17404681.html
Sent from the Wicket - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]