You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Anna Kerekes <An...@onx.com> on 2004/10/04 21:57:48 UTC
input form
Hello,
I have a jsp (create.jsp), a form-bean (CreateMessageForm.java), and an action (CreateMessageAction.java).
Currently, the user inputs their info into create.jsp, hits 'submit', and the action gets the info from the form-bean
and does stuff with it. Instead, I would like to get some information( collections) from a database and populate "create.jsp" with them. So I would like to:
- get a collection from the database
- put this collection into the request
- populate create.jsp from the request object
- let the user edit the form (including the pre-populated parts)
- hit submit
- CreateMessageAction gets info from form-bean and does stuff...
Do I have to write a separate Action class for putting the collection (from database) into the request object? Or can I somehow incorporate this into my current CreateMessageAction class ?
please help,
Anna Kerekes
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: input form
Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Anna Kerekes" <An...@onx.com>
> I have a jsp (create.jsp), a form-bean (CreateMessageForm.java),
> and an action (CreateMessageAction.java).
> Currently, the user inputs their info into create.jsp, hits 'submit',
> and the action gets the info from the form-bean
> and does stuff with it. Instead, I would like to get some information(
collections)
> from a database and populate "create.jsp" with them. So I would like to:
If you're talking about pre-populating form elements with default values,
the solution involves never letting people go directly to your JSP, but
instead ALWAYS making them go through an Action. That's where you
prepopulate the form bean, and doing that means that when you forward to the
JSP containing Struts tags, the values will automatically be displayed.
If you're talking about Collections that become the list of options for a
<select> list, then those are appropriate to put in request or session
scope, or even application scope if they will be the same for all users. I
have a context listener that places a bunch of Maps in application scope,
and a Filter that places things in the request.
Either way, once you stop letting people go directly to your JSP, and ALWAYS
make them go through an Action, you suddenly have the opportunity to do any
set-up work you need to do before forwarding them to the JSP.
--
Wendy
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: input form
Posted by Shyam Anand <st...@yahoo.com>.
Hello,
Your CreateMessageAction class should extend
DispatchAction class, and then you should be able to
accomplish your requirement.
See this link:
http://struts.apache.org/api/org/apache/struts/actions/DispatchAction.html
You can have different methods in your DispatchAction
class like "get", "submit" etc.
So, you might have something like this:
public final ActionForward get(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
{
// retrieve collection for JSP and store it in the
request.
}
public final ActionForward submit(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
{
// do stuff that you do now in your
CreateMessageAction
}
You would also need to configure your
struts-config.xml accordingly.
eg. you might have:
<action path="/createMessage"
type="CreateMessageAction"
name="createMessageForm"
scope="request"
input="create.jsp"
validate="true" parameter="method">
<forward name="get"
path="/WEB-INF/pages/create.jsp"/>
<forward name="submit"
path="/WEB-INF/pages/result.jsp"/>
</action>
HTH,
Shyam
> Hello,
>
> I have a jsp (create.jsp), a form-bean
> (CreateMessageForm.java), and an action
> (CreateMessageAction.java).
>
> Currently, the user inputs their info into
> create.jsp, hits 'submit', and the action gets the
> info from the form-bean
> and does stuff with it. Instead, I would like to
> get some information( collections) from a database
> and populate "create.jsp" with them. So I would like
> to:
>
> - get a collection from the database
> - put this collection into the request
> - populate create.jsp from the request object
> - let the user edit the form (including the
> pre-populated parts)
> - hit submit
> - CreateMessageAction gets info from form-bean and
> does stuff...
>
> Do I have to write a separate Action class for
> putting the collection (from database) into the
> request object? Or can I somehow incorporate this
> into my current CreateMessageAction class ?
>
> please help,
> Anna Kerekes
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
>
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org