html:submit button
Hello, I have a problem and I can't fingure out the solution to it. Here is my case: I have a list of products (PoductBean) on my .jsp and each one of it have two buttons (html:submit) : Button1 -- Display Information for this product Button2 -- Use the information to do something else My question is: How can I decide which product has been selected so as to display its information on my next page? From what I have seen the html:submit tag does not contain any attributes to pass request parameters. Thank U in advance, Konstantina
Re: html:submit button
Hi Rob, I tried this solution but the thing is that the value is set as the label of the button. Isn't there a more elegant way to do this? As far as the radio buttons concerned, my submit buttons do not apply only to the name of product but to some other configuration parameters too. So I have 10 lines of config parameters and two buttons under these. Thank you for your instant reply, Konstantina - Original Message - From: rob [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Thursday, February 21, 2002 12:32 PM Subject: Re: html:submit button You can setup a property in your form bean to receive the value of the button and just pack the button value with the product id (since if I understand correctly you have a button for every product entry) ie. html:submit property=button value=view produc list:productid/ and html:submit property=button value=do something else:productid/ in your action you can retrieve the property and compare it. if (form.getButton().startsWith(view product list)) { String value = form.getButton(); tokenize out the id with StringTokenizer or something. .. do the view product list stuff ...; } if (form.getButton().equals(do something else)) { same as above just do the something else } If I understand correctly the above is one solution although I might suggest using a radio button(s) for product selection and then only one pair of buttons. - Original Message - From: Konstantina Stamopoulou [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Thursday, February 21, 2002 9:02 PM Subject: html:submit button Hello, I have a problem and I can't fingure out the solution to it. Here is my case: I have a list of products (PoductBean) on my .jsp and each one of it have two buttons (html:submit) : Button1 -- Display Information for this product Button2 -- Use the information to do something else My question is: How can I decide which product has been selected so as to display its information on my next page? From what I have seen the html:submit tag does not contain any attributes to pass request parameters. Thank U in advance, Konstantina -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: html:submit button
On your jsp html:submit property=X value=X/ html:submit property=Y value=Y/ On Action Page String button1=request.getParameter(X); String button1=request.getParameter(Y); if(button1 != null){ //X was clicked //do whatever like forward to another actionpage } else if(button2 != null){ //Y was clicked //do whatever like forward to another actionpage } else { //neither was clicked } From: Konstantina Stamopoulou [EMAIL PROTECTED] Reply-To: Struts Users Mailing List [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED], rob [EMAIL PROTECTED] Subject: Re: html:submit button Date: Thu, 21 Feb 2002 13:23:27 +0200 Hi Rob, I tried this solution but the thing is that the value is set as the label of the button. Isn't there a more elegant way to do this? As far as the radio buttons concerned, my submit buttons do not apply only to the name of product but to some other configuration parameters too. So I have 10 lines of config parameters and two buttons under these. Thank you for your instant reply, Konstantina - Original Message - From: rob [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Thursday, February 21, 2002 12:32 PM Subject: Re: html:submit button You can setup a property in your form bean to receive the value of the button and just pack the button value with the product id (since if I understand correctly you have a button for every product entry) ie. html:submit property=button value=view produc list:productid/ and html:submit property=button value=do something else:productid/ in your action you can retrieve the property and compare it. if (form.getButton().startsWith(view product list)) { String value = form.getButton(); tokenize out the id with StringTokenizer or something. .. do the view product list stuff ...; } if (form.getButton().equals(do something else)) { same as above just do the something else } If I understand correctly the above is one solution although I might suggest using a radio button(s) for product selection and then only one pair of buttons. - Original Message - From: Konstantina Stamopoulou [EMAIL PROTECTED] To: Struts Users Mailing List [EMAIL PROTECTED] Sent: Thursday, February 21, 2002 9:02 PM Subject: html:submit button Hello, I have a problem and I can't fingure out the solution to it. Here is my case: I have a list of products (PoductBean) on my .jsp and each one of it have two buttons (html:submit) : Button1 -- Display Information for this product Button2 -- Use the information to do something else My question is: How can I decide which product has been selected so as to display its information on my next page? From what I have seen the html:submit tag does not contain any attributes to pass request parameters. Thank U in advance, Konstantina -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] _ Join the worlds largest e-mail service with MSN Hotmail. http://www.hotmail.com -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: html:submit button
Hi Konstantina, I don;t know if you have a solution yet, but I have two separate ones for you. The first is more struts oriented. If you have the following in your JSP: !-- JSP Snippet-- html:submit property=btnProcess bean:message key=button.processSuspends / /html:submit html:submit property=btnViewOrg bean:message key=button.viewOrg / /html:submit html:submit property=btnViewProd bean:message key=button.viewProd / /html:submit !-- End of JSP Snippet-- //you need to create 3 attributes in your ActionForm object that's being populated when this form gets submitted, called // with associated getters and setters... boolean btnProcess, btnViewOrg, btnViewProd; // then in the Action.perform(), simply look at the variables to see which one is true boolean isProcess=false, isViewProd=false, isViewOrg=false; // Get and cast a reference to the ActionForm object for use MyActionForm theForm=(MyActionForm)form; // What button was pushed String process = (theForm.getBtnProcess().equals(null)?:theForm.getBtnProcess()); String viewOrg = (theForm.getBtnViewOrg().equals(null)?:theForm.getBtnViewOrg()); String viewProd = (theForm.getBtnViewProd().equals(null)?:theForm.getBtnViewProd()); The following code will also work // Getting what button was pressed looping through parameters String button_pressed = null; Enumeration e = request.getParameterNames(); while (e.hasMoreElements()) { String param = (String) e.nextElement(); if (param.startsWith(btn)) { button_pressed = param; break; } } System.out.println(button_pressed=+button_pressed); John Mattos Sr. Developer and Architect iNDEMAND 345 Hudson St. 16th Floor New York, New York 10014 -Original Message- From: Konstantina Stamopoulou [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 21, 2002 5:02 AM To: Struts Users Mailing List Subject: html:submit button Hello, I have a problem and I can't fingure out the solution to it. Here is my case: I have a list of products (PoductBean) on my .jsp and each one of it have two buttons (html:submit) : Button1 -- Display Information for this product Button2 -- Use the information to do something else My question is: How can I decide which product has been selected so as to display its information on my next page? From what I have seen the html:submit tag does not contain any attributes to pass request parameters. Thank U in advance, Konstantina -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: html:submit button
Hi John, I was suggested to use the tag html:hidden where I can store any information I want without this to be visible to the user and it works. I really appreciate the detail of your answer. Have a nice day, Konstantina - Original Message - From: Mattos, John [EMAIL PROTECTED] To: 'Struts Users Mailing List' [EMAIL PROTECTED] Sent: Thursday, February 21, 2002 3:56 PM Subject: RE: html:submit button Hi Konstantina, I don;t know if you have a solution yet, but I have two separate ones for you. The first is more struts oriented. If you have the following in your JSP: !-- JSP Snippet-- html:submit property=btnProcess bean:message key=button.processSuspends / /html:submit html:submit property=btnViewOrg bean:message key=button.viewOrg / /html:submit html:submit property=btnViewProd bean:message key=button.viewProd / /html:submit !-- End of JSP Snippet-- file://you need to create 3 attributes in your ActionForm object that's being populated when this form gets submitted, called // with associated getters and setters... boolean btnProcess, btnViewOrg, btnViewProd; // then in the Action.perform(), simply look at the variables to see which one is true boolean isProcess=false, isViewProd=false, isViewOrg=false; // Get and cast a reference to the ActionForm object for use MyActionForm theForm=(MyActionForm)form; // What button was pushed String process = (theForm.getBtnProcess().equals(null)?:theForm.getBtnProcess()); String viewOrg = (theForm.getBtnViewOrg().equals(null)?:theForm.getBtnViewOrg()); String viewProd = (theForm.getBtnViewProd().equals(null)?:theForm.getBtnViewProd()); The following code will also work // Getting what button was pressed looping through parameters String button_pressed = null; Enumeration e = request.getParameterNames(); while (e.hasMoreElements()) { String param = (String) e.nextElement(); if (param.startsWith(btn)) { button_pressed = param; break; } } System.out.println(button_pressed=+button_pressed); John Mattos Sr. Developer and Architect iNDEMAND 345 Hudson St. 16th Floor New York, New York 10014 -Original Message- From: Konstantina Stamopoulou [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 21, 2002 5:02 AM To: Struts Users Mailing List Subject: html:submit button Hello, I have a problem and I can't fingure out the solution to it. Here is my case: I have a list of products (PoductBean) on my .jsp and each one of it have two buttons (html:submit) : Button1 -- Display Information for this product Button2 -- Use the information to do something else My question is: How can I decide which product has been selected so as to display its information on my next page? From what I have seen the html:submit tag does not contain any attributes to pass request parameters. Thank U in advance, Konstantina -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: html:submit button
Hi Konstantina, The html:submit is used to pass the parameters of the html:form it applies to. Whatever properties you include in your form, they are included in the request parameter. Here is an example: html:form action=/viewElementDesign.do bean:message key='mainMenu.viewDesignPatterns'/ html:select property=type size=3 html:option value=-- Select --/html:option html:option value=requiredparentRequiredParent/html:option html:option value=requiredchiildRequiredChild/html:option /html:select html:submit bean:message key='button.continue'/ /html:submit /html:form Christian/ -Original Message- From: Konstantina Stamopoulou [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 21, 2002 5:02 AM To: Struts Users Mailing List Subject: html:submit button Hello, I have a problem and I can't fingure out the solution to it. Here is my case: I have a list of products (PoductBean) on my .jsp and each one of it have two buttons (html:submit) : Button1 -- Display Information for this product Button2 -- Use the information to do something else My question is: How can I decide which product has been selected so as to display its information on my next page? From what I have seen the html:submit tag does not contain any attributes to pass request parameters. Thank U in advance, Konstantina
RE: html:submit button
Hi Konstantina, Since you haven't supplied enough details, I'll assume that you have a table, and each row contains info on one product, plus two buttons, one for displaying info and one for do something with the product. In this case you then make each button look like an array, in your form bean, declare something like: private int editIndex = -1; private int infoIndex = -1; private String editString = ; private String infoString = ; public String getEditString(int index) { return editString; } public final void setEditString(int index, String editString){ this.editString = editString; this.editIndex = index; } public int getEditIndex () { return editIndex; } public String getInfoString(int index) { return infoString; } public final void setInfoString(int index, String infoString){ this.infoString = infoString; this.infoIndex = index; } public int getInfoIndex() { return infoIndex; } In your jsp, inside your iterate, you woud use: html:submit indexed=true property=editCmd value=Edit / html:submit indexed=true property=infoCmd value=Info / When submitted you can use getInfoString and getEditString to see which button was pressed (the pressed button will have a value other than ) and then use the appropriate get index to see which item was selected. -- Larry Maturo [EMAIL PROTECTED] -Original Message- From: Konstantina Stamopoulou [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 21, 2002 4:02 AM To: Struts Users Mailing List Subject: html:submit button Hello, I have a problem and I can't fingure out the solution to it. Here is my case: I have a list of products (PoductBean) on my .jsp and each one of it have two buttons (html:submit) : Button1 -- Display Information for this product Button2 -- Use the information to do something else My question is: How can I decide which product has been selected so as to display its information on my next page? From what I have seen the html:submit tag does not contain any attributes to pass request parameters. Thank U in advance, Konstantina -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: html:submit button
Thank U for your reply and for the code details! I used this approach to see which button was pressed and the html: hidden tag to pass the product id. Thank U all for your help! Konstantina - Original Message - From: Maturo, Larry [EMAIL PROTECTED] To: 'Struts Users Mailing List' [EMAIL PROTECTED] Sent: Thursday, February 21, 2002 5:30 PM Subject: RE: html:submit button Hi Konstantina, Since you haven't supplied enough details, I'll assume that you have a table, and each row contains info on one product, plus two buttons, one for displaying info and one for do something with the product. In this case you then make each button look like an array, in your form bean, declare something like: private int editIndex = -1; private int infoIndex = -1; private String editString = ; private String infoString = ; public String getEditString(int index) { return editString; } public final void setEditString(int index, String editString){ this.editString = editString; this.editIndex = index; } public int getEditIndex () { return editIndex; } public String getInfoString(int index) { return infoString; } public final void setInfoString(int index, String infoString){ this.infoString = infoString; this.infoIndex = index; } public int getInfoIndex() { return infoIndex; } In your jsp, inside your iterate, you woud use: html:submit indexed=true property=editCmd value=Edit / html:submit indexed=true property=infoCmd value=Info / When submitted you can use getInfoString and getEditString to see which button was pressed (the pressed button will have a value other than ) and then use the appropriate get index to see which item was selected. -- Larry Maturo [EMAIL PROTECTED] -Original Message- From: Konstantina Stamopoulou [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 21, 2002 4:02 AM To: Struts Users Mailing List Subject: html:submit button Hello, I have a problem and I can't fingure out the solution to it. Here is my case: I have a list of products (PoductBean) on my .jsp and each one of it have two buttons (html:submit) : Button1 -- Display Information for this product Button2 -- Use the information to do something else My question is: How can I decide which product has been selected so as to display its information on my next page? From what I have seen the html:submit tag does not contain any attributes to pass request parameters. Thank U in advance, Konstantina -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]