You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Matthew J. Vincent" <vi...@cs.usm.maine.edu> on 2004/01/23 17:15:13 UTC

Strust Search/Results/Display HELP!

Ok.  I guess I'm missing something - or it just won't sink in.  This really
isn't that long.

For simplicity, let's say I have a 4 page application.

1. Index
2. Search for an Item
3. Search Results List of Matching items
4. Details of an Item

All of these "pages" needs to gather data from a database (not the problem)
and display to them to the end user.

A typical scenario for a user would be:

1. User goes to http://localhost:8888/protoype they will land on the index
page that really needs to be an Action because it looks up data from the
database.
2. They click search which also gathers data from the database to display a
form.
3. They fill the form in and click Search.
4. They see the matching search results.
5. They pick the matching search result and the Item is displayed.

Each page is essentially an action that forwards it's results to a jsp page.

However, here is the problem I am having.  When an error occurs, I need to
have that error displayed to the end user and have them on the previous
page.

For example, Step 2 to Step 3 from above - if the user does not type in a
required field or there are no results, they need to be told this and placed
back on Step 2 with:
1. the form values filled out with what they submitted
2. this page needs to gather the data from the database again (in case more
data has been added).

So I'm not sure of:

1. What do I need to put in the struts-config.xml file (specifically in the
Action Mappings section)

      <action path="/search"
              type="SearchAction">
         <forward name="success" path="/search.jsp"/>
         <forward name="failure" path="/appError.jsp"/>
      </action>
      <action path = "/searchResults"
              type = "SearchResultsAction"
              name = "strainSearchForm"
              validate = "true"  <---------- I know will call the validate
method
              input = "/search.do"> <---------- can this be an Action?
         <forward name="success" path="/searchResults.jsp"/>
         <forward name="failure" path="/search.do"/>  <---------- If this is
search.jsp, the data from the database is not regathered
         <forward name="error" path="/appError.jsp"/>
      </action>


2. Should I have 1 action or is having multiple actions ok?  If just 1
action, how do I set this up?

3. What is the best approach for this type of scenario?  I can solve this
fine with a straight Servlet and JSP approach, but what is the "Struts way"?

Hubert and Wendy have answered my questions, but I am recovering from a cold
and nothing is getting into my brain.

Thanks for the help.  Be gentle and explain slowly.  :)


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Struts Search/Results/Display

Posted by Hubert Rabago <ja...@yahoo.com>.
> --- "Matthew J. Vincent" <vi...@cs.usm.maine.edu> wrote:
> > Re: Strust Search/Results/Display HELP!
> > 
> > Thanks for the help.  Be gentle and explain slowly.  :)
> > 

Also, people will help you even if your question is "gentle" and doesn't shout.
:)


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Strust Search/Results/Display HELP!

Posted by Hubert Rabago <ja...@yahoo.com>.
For your steps 2 to 4:

in your struts-config:

<form-bean name="myForm" type="com.my.form.MyForm"/>
...
<action path="/pageWithForm" type="com.my.action.PreparePageAction">
    <forward name="showForm" path="/form.jsp">
</action>
<action path="/formDestination" 
    type="com.my.action.PreparePageAction"
    name="myForm"
    input="/form.jsp">
    ...  <!-- show page for step 4 -->
</action>


in your jsp:
<html:form action="/formDestination">
    <html:text property="someMyFormProperty"/>
    <html:text property="otherMyFormProperty"/>
    <html:submit/>
</html:form>
<%-- also use the struts tags to display error messages --%>


In your case, you may need to use input="/pageWithForm.do" since you need to prep
the form, but there are other ways to do that, like placing your <SELECT>'s
options collection in session or app scope.  However, I *have* used this approach
before and it worked for me.

hth,
Hubert

--- "Matthew J. Vincent" <vi...@cs.usm.maine.edu> wrote:
> Ok.  I guess I'm missing something - or it just won't sink in.  This really
> isn't that long.
> 
> For simplicity, let's say I have a 4 page application.
> 
> 1. Index
> 2. Search for an Item
> 3. Search Results List of Matching items
> 4. Details of an Item
> 
> All of these "pages" needs to gather data from a database (not the problem)
> and display to them to the end user.
> 
> A typical scenario for a user would be:
> 
> 1. User goes to http://localhost:8888/protoype they will land on the index
> page that really needs to be an Action because it looks up data from the
> database.
> 2. They click search which also gathers data from the database to display a
> form.
> 3. They fill the form in and click Search.
> 4. They see the matching search results.
> 5. They pick the matching search result and the Item is displayed.
> 
> Each page is essentially an action that forwards it's results to a jsp page.
> 
> However, here is the problem I am having.  When an error occurs, I need to
> have that error displayed to the end user and have them on the previous
> page.
> 
> For example, Step 2 to Step 3 from above - if the user does not type in a
> required field or there are no results, they need to be told this and placed
> back on Step 2 with:
> 1. the form values filled out with what they submitted
> 2. this page needs to gather the data from the database again (in case more
> data has been added).
> 
> So I'm not sure of:
> 
> 1. What do I need to put in the struts-config.xml file (specifically in the
> Action Mappings section)
> 
>       <action path="/search"
>               type="SearchAction">
>          <forward name="success" path="/search.jsp"/>
>          <forward name="failure" path="/appError.jsp"/>
>       </action>
>       <action path = "/searchResults"
>               type = "SearchResultsAction"
>               name = "strainSearchForm"
>               validate = "true"  <---------- I know will call the validate
> method
>               input = "/search.do"> <---------- can this be an Action?
>          <forward name="success" path="/searchResults.jsp"/>
>          <forward name="failure" path="/search.do"/>  <---------- If this is
> search.jsp, the data from the database is not regathered
>          <forward name="error" path="/appError.jsp"/>
>       </action>
> 
> 
> 2. Should I have 1 action or is having multiple actions ok?  If just 1
> action, how do I set this up?
> 
> 3. What is the best approach for this type of scenario?  I can solve this
> fine with a straight Servlet and JSP approach, but what is the "Struts way"?
> 
> Hubert and Wendy have answered my questions, but I am recovering from a cold
> and nothing is getting into my brain.
> 
> Thanks for the help.  Be gentle and explain slowly.  :)
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org