Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Struts Simple Form Help (Getting NULL)

843836Sep 13 2003 — edited Sep 16 2003
Hey guys,
Im having a bit of trouble with something I thaught was quite simple. I am basically getting a null value from a form text field in struts and I have no IDEA why.. So all im basically trying to do is attempt to get a text field value, but its not even going in my form bean (when print a flag there i get null)...its confusing me because Ive checked it countless times and Ive done it copy-book!. Any help is more than appreciated:

1) This is my simple search JSP (with the form) search.jsp
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<!-- 
    Action property: our reference to the ActionMapping in StrutsConfig 
    Action mapping: /SearchSubmit
    From here two objects called: ActionForm and Action.
-->
<html:errors/>
<html:form action="/SearchSubmit" focus="keywords">
<p class="mainbody">
    Search:<br>
    <html:text property="keywords" size="7" styleClass="mainsidebar" /><br>
    <html:submit />
</p>
</html:form>
2) Here is my form bean: SearchForm.java
package inStock.struts.actions;
import org.apache.struts.action.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
public class SearchForm extends ActionForm {  
    private String keywords; 
    /** Get keywords form field */
    public String getKeywords() {
            return (this.keywords);
    } 
    /** Set keywords form field */
    void setKeywords(String keywords) {
        this.keywords = keywords;
    }
    /** Our validate */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request){
        System.out.println("FLAG: in SearchForm: validate(), Keywords is: " + keywords); //THIS ALWAYS PRINTS NULL! :(
        ActionErrors errors = new ActionErrors();
        if((keywords == null)|| (keywords.length() < 1)){
            errors.add ("keywords", new ActionError("SearchForm.keywords.required"));
        }        
        return errors;
    }
}
3) My action class: SearchAction.java (but it doesnt even get there)
(doesnt even get here)
4) Finally the code in my struts config
<struts-config>
...
    <form-beans>
         <form-bean name="searchForm" type="inStock.struts.actions.SearchForm" />
    </form-beans>
...
    <global-forwards>
        <forward name="searchsucess" path="/pages/Search.jsp" />
    </global-forwards>
....
    <action-mappings>
        <action path="/SearchSubmit" type="inStock.struts.actions.SearchAction" name="searchForm" scope="request" validate="true" input="/pages/includes/aux_includes/search.jsp" />
    </action-mappings>
...
</struts-config>
Again I have no idea why, but it always gets NULL in the SearchForm.java... please help this is getting quite annoying.. and im sure its something stupid! Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 14 2003
Added on Sep 13 2003
6 comments
946 views