• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Stripes: prepopulated forms question

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gabriele,

Could you also post the code for NewsViewActionBean and NewsEditActionBean?

That will help find the cause of the problem.

Cheers,
 
Gabriele Fabbri
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Frederic,
it's nice to meet the author of the book I'm reading!

NewsViewActionBean




NewsEditActionBean

 
Frederic Daoud
author
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Frederic Daoud
author
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I confirm that it works perfectly.
Thank you very much Frederic to share you knowledge in a friendly way!

Cheers,


 
This is my favorite show. And this is my favorite tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic