*
The moose likes Other Application Frameworks and the fly likes Stripes: prepopulated forms question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Stripes: prepopulated forms question" Watch "Stripes: prepopulated forms question" New topic
Author

Stripes: prepopulated forms question

Gabriele Fabbri
Ranch Hand

Joined: Dec 05, 2008
Posts: 30
Hi all,

Stripes Framework 1.5

I'm getting a little problem trying populating a form with data retrieved from the database (MySQL).
I have implemented the Stipersist library and Hibernate, and I'm able to insert new data in db and read list of records, but I can't understand how to populate form fields for the update function: I'm getting an empty form, but if write some data and submit the record is updated correctly (so, it works).

I'm problably doing something wrong passing the paramenter from the list to the edit form...

Some code.

news_list.jsp



This link pass the news=IdNumber parameter, as explained in the Stripes book, to the action bean.
The action bean, on the edit event, simply forward to news_edit.jsp.

news_edit.jsp



This code is working properly, but form fields are not filled.

I also tried using:



... but I'm still getting empty fields.

Any idea?
Thanks.


OverZero Software
[url]www.overzero.it[/url]
Frederic Daoud
author
Ranch Hand

Joined: May 22, 2008
Posts: 71
Hi Gabriele,

Could you also post the code for NewsViewActionBean and NewsEditActionBean?

That will help find the cause of the problem.

Cheers,


Frederic Daoud
Author, Stripes...and Java Web Development is Fun Again
Stripes book
Gabriele Fabbri
Ranch Hand

Joined: Dec 05, 2008
Posts: 30
Hi Frederic,
it's nice to meet the author of the book I'm reading!

NewsViewActionBean




NewsEditActionBean

Frederic Daoud
author
Ranch Hand

Joined: May 22, 2008
Posts: 71
Gabriele Fabbri wrote:
it's nice to meet the author of the book I'm reading!


I hope you are enjoying the book!

Do you have a getter method for News in NewsBaseActionBean? As in



Otherwise the JSP will not be able to obtain the News object and prepopulate your form with <s:text name="news.title"/>.

As a side note, is there a particular reason why you are doing this in NewsViewActionBean and NewsEditActionBean?



As they are now, both methods are redundant and could be removed.

Let me know if you are still having problems.

Cheers,

Gabriele Fabbri
Ranch Hand

Joined: Dec 05, 2008
Posts: 30
Thank you for the fast reply Frederic.
Yes, your book is absolutely one of the most useful books I have read in 2008!

This is the code of the NewsBaseActionBean




I tried removing the @Override of the getNews method, as you suggested (I don't remember why I put it there...), but I'm still getting empty fields.


Frederic Daoud
author
Ranch Hand

Joined: May 22, 2008
Posts: 71
Thank you for your kind words, Gabriele!

I've reviewed your code and compared it with the sample code from the Stripes book. The only thing I can think of at the moment is that perhaps the value of ${news} is not being set in:



Could you post the complete code from news_list.jsp?

Cheers,
Gabriele Fabbri
Ranch Hand

Joined: Dec 05, 2008
Posts: 30
Of course!

This is the code of the news_list.jsp




Following the link "Modifica" (modify) the generated url is
http://localhost:8080/jpa/NewsView.action?edit=&news=6

If I understood, "6" correspond to the ID property of the News entity (obtained by the Stripersist TypeConverter), and it seems to work fine, because if I submit the Edit form I'm able to UPDATE the correct record.

Just to be sure, I would ask you a little clarification: in chapter 3 (page 54) you explain how to get a prepopulated form by submitting directly the ID of the object from the list page to the edit form. In this way I can get filled form fields, but in chapter 12 you say that, using Stripersist and Hibernate, it is possibly to submit the entity News as parameter of the link (as I'm doing now).
My doubt is if I have now to write form fields like <s:text name="news.titolo"/> or <s:text name="news.titolo" value="${news.titolo}"/> in the edit form.

Just a note: please forget differences on properties names between code in previous posts and this, I can ensure you that they are consistant

Thank you.
Frederic Daoud
author
Ranch Hand

Joined: May 22, 2008
Posts: 71
Gabriele,

So far, I don't see any problem with the source code that you have posted. I have a feeling that it is just a small detail somewhere that is preventing the form from being prepopulated. It should work as you have described.

If you can create a zip file of the source code for your example and email it to me so that I can reproduce the problem, I'll try to find what is missing.

Cheers,
Gabriele Fabbri
Ranch Hand

Joined: Dec 05, 2008
Posts: 30
Thank you Frederic for your attention, I really apreciate this.
I'll try to solve the issue tomorrow, in case I wont be able to find the solution by my self, I will send you the zipped source.

Regards,
Gabriele
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

So here is what I noticed. The edit method doesn't do anything but forward to a view. My first question is, does the type converter that Stripersist creates automatically populate the object from the database or should that be done in the edit method of the action bean?


GenRocket - Experts at Building Test Data
Frederic Daoud
author
Ranch Hand

Joined: May 22, 2008
Posts: 71
Gregg Bolinger wrote:So here is what I noticed. The edit method doesn't do anything but forward to a view. My first question is, does the type converter that Stripersist creates automatically populate the object from the database or should that be done in the edit method of the action bean?


If the class is annotated with JPA annotations (@Entity, @Id), the Stripersist type converter automatically populates the object.

I was going to ask Gabriele to post the code for the News class, but I figured that it was properly annotated since the update does work and the correct changes are made to the database.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Frederic Daoud wrote:
Gregg Bolinger wrote:So here is what I noticed. The edit method doesn't do anything but forward to a view. My first question is, does the type converter that Stripersist creates automatically populate the object from the database or should that be done in the edit method of the action bean?


If the class is annotated with JPA annotations (@Entity, @Id), the Stripersist type converter automatically populates the object.

I was going to ask Gabriele to post the code for the News class, but I figured that it was properly annotated since the update does work and the correct changes are made to the database.


[OFFTOPIC] This is scary because you have no control over it happening or not. One of a handful of reasons I'm not a big fan of Stripersist.[/OFFTOPIC]

That's what I thought but wanted to make sure I was correct. What I would do then is set a breakpoint in the edit method and look at the news property and see if it is populated and for whatever reason just not making it to the JSP. But other than that, I agree with Freddy that everything looks normal.
Frederic Daoud
author
Ranch Hand

Joined: May 22, 2008
Posts: 71
Hi Gabriele,

I finally found the problem: the link to edit the News item targets NewsListActionBean, but it should target NewsEditActionBean since this is the bean used in news_edit.jsp, in the <s:form beanclass=""> tag. Otherwise, Stripes does not find the News object, and that is why the form was always blank.

Here is the code to be changed:

news_list.jsp:



NewsEditActionBean.java:



The news_edit.jsp does not need any changes, and now displays a prepopulated form.

Cheers,
Gabriele Fabbri
Ranch Hand

Joined: Dec 05, 2008
Posts: 30
I confirm that it works perfectly.
Thank you very much Frederic to share you knowledge in a friendly way!

Cheers,


 
jQuery in Action, 2nd edition
 
subject: Stripes: prepopulated forms question
 
Similar Threads
One of My Favorite Stripes Features (A Complex Example)
Struts 2 checkboxlist error - list key could not be resolved
Struts form problem
[Stripes] forms: display errors from @ValidateNestedProperties
Frameworks? Do I need one? want one?