DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23097>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23097

Redisplaying data user has entered within a form

           Summary: Redisplaying data user has entered within a form
           Product: Struts
           Version: 1.1 Final
          Platform: Sun
        OS/Version: Solaris
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Standard Actions
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


Hi All,

I have a problem redisplaying form fields a user enters within a html form.

I use the validate method to validate form entry fields through ActionForms.
and validate business logic in LookupDispatchAction classes.

Has anyone experienced this problem, and is there any solution to this
matter.

Cheers
Rodney



CODE:
Below the code you see is part of an application I am building.
The problem here lies in the fact that in all cases,
field data does not get redisplayed within the form the user has entered data 
in.

eg. if you enter a invalid data within a numeric data field (this instance ACN)
    then the ActionForm issues a error message gets issued (works)
    but the ACN previously entered does not get redisplayed in the form.

eg. if you enter a valid ACN or Organisation Name within the fields to do 
searches,
    and no data is applicable to the search criteria entered a error message 
gets issued (works)
    but no ACN/Organisation Name gets redisplayed in the form where the data 
was entered.



Part 1: Sample Configuration (struts-config.xml)

<form-bean name="company.OrganisationNameSearchActionForm"
           
type="net.natdata.application.itf.insolvency.company.OrganisationNameSearchActio
nForm" />

<global-forwards>
        <forward name="error"
               path="/Error.jsp" />
</global-forwards>

<action path="/company/OrganisationNameSearch"
        
type="net.natdata.application.itf.insolvency.company.OrganisationNameSearchActio
n"
        name="company.OrganisationNameSearchActionForm"
        input="/company/OrganisationNameSearch.jsp"
        scope="request"
        validate="true"
        parameter="method">
        <forward name="next"    path="/company/OrganisationBrowse.jsp" 
redirect="false" />
        <forward name="failure" path="/company/OrganisationNameSearch.jsp" 
redirect="false" />
</action>

<action path="/company/OrganisationBrowse"
        
type="net.natdata.application.itf.insolvency.company.OrganisationBrowseAction"
        name="company.OrganisationBrowseActionForm"
        input="/company/OrganisationBrowse.jsp"
        scope="request"
        validate="true"
        parameter="method">
        <forward name="previous"    path="/company/OrganisationNameSearch.jsp" 
redirect="false" />
        <forward name="next"        path="/company/OrganisationDetails.jsp" 
redirect="false" />
        <forward name="bill"        path="/BillingAction.do" redirect="false" />
        <forward name="failure"     path="/company/OrganisationBrowse.jsp" 
redirect="false" />
</action>

<controller nocache="true"
            
processorClass="net.natdata.application.itf.framework.NDCRequestProcessor" />

<message-resources parameter="resources.application" />



PART 2: Application form code (validation and reset methods)

public class OrganisationNameSearchActionForm extends ActionForm {

    // Get and Set methods
    ....
    
    public ActionErrors validate(ActionMapping actionMapping, 
HttpServletRequest httpServletRequest) {
        ActionErrors errors = new ActionErrors();
        
        if(method.equals("Next")) {
            if((organisationName == null) || (organisationName.trim().equals
(""))) {
                errors.add("organisationName", new ActionError
("error.organisationName.required"));
            }
            
            if((ACN != null) && (!ACN.trim().equals(""))) {
                try {
                    Integer.parseInt(ACN);
                }
                catch(NumberFormatException e) {
                    errors.add("ACN", new ActionError("error.ACN.format"));
                }
            }
        }
        
        return errors;
    }
    
    public void reset(ActionMapping mapping, HttpServletRequest request) {
        this.method = null;
        this.organisationName = null;
        this.ACN = null;
    }
}

Part 3: Action Code (Sample)

public class OrganisationNameSearchAction extends LookupDispatchAction {
    protected java.util.Map getKeyMethodMap() {
        Map map = new HashMap();
        map.put("button.next", "next");
        return map;
    }
    
    public ActionForward next(ActionMapping mapping, ActionForm form,
                              HttpServletRequest request, HttpServletResponse 
response)
                              throws IOException, ServletException {
        boolean error = false;
        boolean failure = false;
        String target = "next";
        ActionErrors actionErrors = new ActionErrors();
        
        try {
            HttpSession session = request.getSession(false);
            if(session != null) {
                OrganisationNameSearchMessageDTO organisationNameSearchResult = 
performOrganisationNameSearch(form, session);
                if(organisationNameSearchResult == null) {
                    error = true;
                }
                else if(organisationNameSearchResult.getRequestRejectionGroup
() != null) {
                    if(organisationNameSearchResult.getRequestRejectionGroup
().getRejectionDetailsSegment() != null) {
                        failure = true;
                    }
                }
                
                if(!error && !failure) {
                    processResults(organisationNameSearchResult, session);
                    target = "next";
                }
                else if(failure) {
                    String errorMsg = 
organisationNameSearchResult.getRejectionMessage();
                    actionErrors.add(ActionErrors.GLOBAL_ERROR, new ActionError
("errorMessage", errorMsg));
                    target = "failure";
                }
                else {
                    target = "error";
                }
            }
            else {
                actionErrors.add(ActionErrors.GLOBAL_ERROR, new ActionError
("error.noSession"));
                target = "error";
            }
        }
        catch(Exception e) {
            target = "error";
        }
        finally {
            // Save errors if needed and forward to the appropriate page to 
display
            if(!actionErrors.isEmpty()) {
                saveErrors(request, actionErrors);
            }
            return (ActionForward)mapping.findForward(target);
        }
    }
    
    ....
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to