• 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

Perform the Same Action "with" and "without" a Form

 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a "list" of articles to be retrieved from the database and displayed.

The first time I display the list, I simply sort the list by posting date in descending order (without providing a form) when I query the database.

Thereafter, users are offered opportunities on top of the list of articles to choose 'sort' criteria from a drop down menu and to choose 'order', which is either ascending or descending, with a GO button. That is to
say, the same action (ListArticle) is called with a 'form' consisting of two menus.

And, in my Java class that extends Action, I did the following:

String sort = request.getParameter( "sort" );
String order = request.getParameter( "order" );

Those are the same action. There is actually an empty form the first time the action is called. And there is a form consisting of two menus the second time the action is called.

I define a form in struts-config.xml like:

<form-bean
name="sortForm"
type="org.apache.struts.validator.DynaActionForm">
<form-property
name="sort"
initialValue="postDate"
type="java.lang.String"/>
<form-property
name="order"
initialValue="DESC"
type="java.lang.String"/>
.. Other properties here
</form-bean>

Then, I define action mapping using this form bean:

<action
roles="administrator,editor,contributor"
path="/article/ListArticles"
type="org.myOrg.myProj.message.ListArticle"
name="sortForm"
scope="request"
validate="false">
<forward
name="success"
path=".article.Form"/>
</action>

Nonetheless, the property of the 'initialValue' attribute inside the <form-property ....> tag (i.e. initialValue="postDate" and initialValue="DESC" ) do not seem to become the default values when the sortForm is not submitted.

I know the query method works well because there is no problem when I perform the action "with" a form (sortForm is submitted).

Do I have to use BeanUtils to get the properties? But, it does not seem to work either. The query method (with sort and order among its parameters) that retrieves articles from the database does not recognize the sort criteria.

Need your diagnostic help.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you trying to avoid the ActionForm???
 
Tell me how it all turns out. Here is a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic