I wouldn't have action as a form bean property (thus no need to define getAction in your form bean), its not really part of you form more of a mechanism for selecting a dispatch action.
//jsp <script language="javascript" type="text/javascript"> function lookup(form) { form.elements['action'].value = 'lookup'; form.submit(); } </script>
<html:form action="/process.do"> <input type="hidden" name="action" value="submit">
<html:select property="mydropdown" onchange="lookup(this.form)"> ... </html:select>
<html:submit /> </html:form>
//action servlet public final class MyAction extends DispatchAction {
/** *Is called when paramater named action has the value of 'lookup' */ public final ActionForward lookup( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ...
} /** *Is called when paramater named action has the value of 'submit' */ public final ActionForward submit( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ...
}
}
///struts config
<action path="/process" parameter="action" name="myActionForm" type="com.sparrow.struts.MyAction" ....
On Saturday, July 12, 2003, at 11:11 PM, Shyam A wrote:
Mark,
Thanks a lot for your mails. I have used "action" as a form bean property and not as a parameter in struts-config. Unfortunately, the Javascript function doesn't seem to work...it does not set the value of the ActionForm property, "action".
When I tried to print out the value of the "action" property in my ActionClass,
I got a null value.
I tried the following code in my Action class and I got a null value. String action = ((ActionForm) form).getAction();
Wonder if I have missed something.
Shyam
Mark Lowe <[EMAIL PROTECTED]> wrote: Its better that this is posted to the list as well, after all its a good question and hopefully an adequate answer.
function lookup(form) { form.elements['action'].value = "lookup"; form.submit(); } //-->
...
[input]
//struts config
name="myForm" redirect="false" parameter=""action" />
The only thing you'd have to watch would be if the client didn't support javascript then you'd lose lookup, this would make a case for having action as a form bean property and have some relevantly named form elements in noscript tags. If lookup isn't mission critical then i guess you could let this slide.
On Friday, July 11, 2003, at 08:44 PM, Shyam A wrote:
Mark,
Thanks for your mail. I understand that DispatchAction class includes multiple execute methods for different actions. However, I still have some doubts.
You mentioned using tags in JSP:
Are these used instead of using "Submit" buttons ? i.e use and in conjunction instead of ? Can be used for a drop- down?
I guess my problem is still unresolved. As I mentioned in my earlier mail, I have a drop-down associated with an ActionForm property "crn".
None
I would like to trigger an action called "Lookup" when the drop-down is clicked .i.e, associate the clicking of the drop-down with the "action" property of the ActionForm class. I don't know how to set the "action" property of the ActionForm class when the drop-down is selected, based on which appropriate method of the DispatchAction class would be executed.
Any help would be greatly appreciated.
Thanks, Shyam
Mark Lowe wrote: check out dispatch actions..
you can have multiple execute methods with dispatch action ...
Your Action class extends DispatchAction instead of action (check the docs)
public final ActionForward submit( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception { ... }
public final ActionForward lookup( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception { ... }
in struts config the parameter attibute need to know the name of the
parameter your about to send, the value of which is your execute method
name..
scope="request" parameter="action"> ...
and then in jsp
HTH Mark
On Friday, July 11, 2003, at 08:00 PM, Shyam A wrote:
James,"Submit"
Thanks for your mail. I guess I need to elaborate a little bit. My HTML form can be submitted in 2ways. 1. Clicking the "Submit" button. 2. Clicking the drop-down
Clicking the drop-down triggers a different action than clicking the "Submit" button. Selecting a value in the drop-down would submit the form and populate some of the other fields in the form. This is done before theofbutton is clicked. So, I need to distinguish the action of clicking the drop-down from clicking the "Submit" button and I called it "Lookup".
Both actions would be identified with a single property in the ActionForm class - action.
eg:
I would like to set this "action" property value to "Lookup" on clicking the drop-down using Javascript. I guess a hidden field would not serve the purpose as I already have "action" property defined for the Submit button.
Look forward to your help/suggestions.
Thanks, Shyam
James Mitchell wrote:
You will need to create a hidden field named "action", with a value"Lookup":like
My question to you is....why "Lookup"? What does that have to do with your form?
Here's a sample:
function submitForm(form) { form.action.value="Lookup"; form.submit(); return true; }
[input] Test Test2
On Friday 11 July 2003 14:15, Shyam A wrote:Hi,
I have an HTML form with Submit and Cancel buttons, and a drop down list, which when clicked submits the form. I use Javascript to submit the form when the dropdown list is clicked. I have a property called "action" defined in my ActionForm class that identifies the Submit and Cancel buttons in the HTML form. When the drop-down is clicked, I wouldto set the value of this "action" property to "Lookup".
My Javascript function is given below:
################
function submitForm(form) { form.action.value="Lookup"; form.submit(); return true; } #################
and I invoke this function in my HTML form as shown below:
#########################
Test
###########################
But, the value of the property "action" is not set to "Lookup".
Any help would be greatly appreciated.
Thanks, Shyam
--------------------------------- Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month!
-- James Mitchell Software Developer/Struts Evangelist http://www.struts-atlanta.org 678-910-8017 AIM:jmitchtx
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------- Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month!
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month!
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------- Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month!
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]