Here's an error that is not straightforward to troubleshoot in Struts: you have a Struts Action that works fine. Now you are ready to add validation to the web page. You override the validate() method from the ActionForm but when you try to run you action again you get and error like this: Error 500: No input attribute for mapping path /myActionIt's because Struts is trying to do the validation for you before it calls your Struts Action. For Struts to automatically run validate() you have to have the "input" property on your <action> tag. That would contain a JSP if you are not using Struts Tiles. If you use Tiles you can simply add validate="false" in your action to fix this problem: <action path = "/myAction" Then your Struts Action must manually call the ActionForm.validate() method:
if(ACT_SELECT.equals(cmd)) Sometimes you'll want to perform an action, perhaps load a second dropdown list, when a users picks an option from a select list. For that you'll need to use the onchange event: <nested:select
property="signatureClient.clientId" With struts, the name of the HTML FORM is the name that you assigned when you defined the form-bean in the Struts config file and referenced in your action: <form-bean name="veriservMenuForm"
Select Lists In Struts there are often many ways to do the same thing. Take select lists: Here are two ways to do the same thing. One is obviously much simpler. The long way:<nested:select property="user.signatureClient.clientId" > <option value="0">Select a Client</option> <nested:present property="clientOptions" > <nested:define id="clientList" property="clientOptions" /> <html:options collection="clientList" labelProperty="clientName" property="clientId" /> </nested:present> </nested:select> This short way: <nested:select property="user.signatureClient.clientId"> <nested:optionsCollection property="clientOptions" value="clientId" label="clientName" /> </nested:select> Checkbox can be used for any boolean property on
your bean:
<nested:checkbox property="../activeCheckbox" value="true" /> The value passed back to struts must be "true", "yes", or "on". Struts will automatically make the box checked if the underlying property is true, and when the form is submitted Struts will automatically translate the Strings listed above into a boolean true. All other values will be false. The biggest thing to remember is that in order to allow users to uncheck options after they have been saved, you must override the reset method on your ActionForm: public void reset(
ActionMapping mapping, HttpServletRequest request) The other problem you are likely to run into is that the model property you have mapped to the database is probably a String or Integer. That needs to be mapped to a boolean property on your ActionForm (or a data transfer object) to use with the Struts checkbox. You might add methods like these to your Action or ActionForm: private void setActiveCheckbox(
EmailTemplateCrudForm emailTemplateCrudForm ) private String readActiveCheckbox(
EmailTemplateCrudForm emailTemplateCrudForm ) |
|

Powered by Amazon EC2 (Elastic Compute Cloud)