aspose file tools*
The moose likes JSF and the fly likes MVC with JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "MVC with JSF" Watch "MVC with JSF" New topic
Author

MVC with JSF

Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Hi,

I'm struggling to build a web page using a bean while applying the MVC pattern (I've read that it is rather the Model2 pattern... )

I attached an ActionListener to catch the event from my JSP page. Page1.java receives the event.

I would like to modify the Bean from the controler. Then, the view (JSP) could update itself by getting values from the model.

However, If I do a bind to the value from the model, the view will also be able to update the Model, which is not good at all !!

How can I make sure the view update itselfs from the model, without being able to modify the model. I would like the model to change only upon controller's requests.

jsp:


java ActionListener:


Even If I remove the action listener, the view will be able to update the Model !!!

Anyone knows how to respect the Model 2 pattern with jsp(V) / jsf(C) / bean(M)

Thanks,
Alex

[ May 17, 2005: Message edited by: Gregg Bolinger ]
[ May 17, 2005: Message edited by: Alex Turcot ]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

You don't have to use binding. The only time you want to use binding is if you want to manipulate the actual JSF Comnponent in Java code. Otherwise, using the value attribute will suffice. Then, your managed bean gets updated from the jsp and you can then have your managed bean move all your info into your model if that is what you want to do upon some action event.


GenRocket - Experts at Building Test Data
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Hi,

thanks for your response... I made some severe typos, I edited my 1st post...

ok, so If I don<t use binding i could rather declare properties in the managed-beans.xml...

I could do something like that ? :


and then use value="#{param.myValue}" for my textbox in jsp ?

Is that what you mean ?

Thx,
Alex
[ May 17, 2005: Message edited by: Alex Turcot ]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

The only time you need to use managed-properties is when you need to give some property an initial value when the page loads the first time. Is this what you are trying to do?

Maybe if you said what you are doing as far as the form/application goes it would make more sense to me.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Look at this







That's all you need. Does that make more sense?
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Hi,

Below I added simple code from what I'm doing.
I want the view to get its data from the Bean.
I want the events to be captured in an eventListener.
I want the eventListener to be the only one modyfing the bean(setMyValue).
If I type something in my textbox, I dont want the model to be updated. This should rather trigger an event and the controller will update the model.


my simple Bean:


my jsp:


Listener:


Thanks,
Alex
[ May 17, 2005: Message edited by: Alex Turcot ]
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
ok so I wouldn't really need a Listener to write in a Model ?
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Just so its clear... my primary goal with all this is to respect the Model 2 pattern (or MVC).
 
 
subject: MVC with JSF