Hi Robert,

In a way, the Model-Class is also the controller.

The model has an execute() method, which is your chance to "do things" - like 
load data from JDBC.

I imagine there's more on this in the Magnolia documentation, but generally 
speaking the sequence of events for each request is something like this:

- The model-class is instantiated by the rendering engine
- setXXX() methods are called on the model-instance by the rendering engine, 
passing in any GET or POST parameters from the request, mapping them by name
- execute() is called on the model-instance
- the template is rendered, passing the model-instance in the template variable 
"model"

So, this leads to following general "pattern" you can use to implement 
functionality like the one you describe:

- include the necessary fields for your form. Maybe also include a hidden field 
like "command" with value "reservationCommand" or something like that
- add getter/setter functions in your model for your form-fields
- in your model's execute() method, check the submitted form data. If the data 
was submitted (ie if "command" contains the value "reservationCommand") then 
invoke makeReservation() from your execute() method
- otherwise, invoke loadSelectData()
- store the results of your method-calls in the model for use by the template, 
and provide getter methods for the template to access the data 
- in the template, you can react to the values present in the model, and 
display error-messages, success-messages, or simply show the form



Regards from Vienna,

Richard



-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] 
Im Auftrag von Magnolia Forums (on behalf of Robert Bowen)
Gesendet: Donnerstag, 16. Februar 2012 10:11
An: Magnolia User List
Betreff: [magnolia-user] Re: Integrate with small web app

Hello and thanks for all of the helpful responses!

The Magnolia project I was working on was put on the back-burner. But I 
recently remembered that I had left this task unfinished. So I checked back on 
the forum and found out I had even more posts!

So as suggested I have made a class that extends RenderingModelImpl. Upon 
testing it I got a "class does not have a constructor" error. So I created a 
default constructor and was going to test it but the server I need to upload to 
was acting funny and I was unable to upload or test. I'll let you know.

In the meantime I'd like to ask a couple more questions:

1. I'd like to use this class in two different way: when the user clicks on the 
link for Reservations, I want to call the MyRenderingModelImpl.loadSelectData() 
method, which will work much like a Spring MVC referenceData() method - load 
data to populate some selects on the form.

Then when the user clicks on the form submit button I want to call the 
MyRenderingModelImpl.makeReservation() method, which takes the form data, does 
some look-ups in the database and puts the result in the request.

Both of these methods would use custom tables, located in the same database as 
Magnolia data. So in my class I have methods to get a JDBC connection, etc. 

So my question is this: in the examples you talk about calling these methods 
from the .ftl page using the "model" variable. But how would I do what I 
describe above, namely, calling the loadSelectData() and makeReservation() 
methods when the user clicks a link/submit button?

To me what I need here is a some sort of Controller class. But since I need to 
use a class that extends the RenderingModelImpl class, which is a Model class, 
I'm a litle confused. I just want to make sure I am going about this the right 
way.

2. When you tell Magnolia that that "modelClass" for a template is your custom 
class that implements the RenderingModelImpl, does that mean that my class is 
now responsible for the "flow" of data? Do I need to do anything with the 
execute() or getContent() methods to make sure the correct .ftl page is shown, 
etc?

Thanks for the assistance!

-- 
Context is everything: 
http://forum.magnolia-cms.com/forum/thread.html?threadId=3f254fa9-4506-4830-8eee-44a5f18da5c4


----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------





----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to