Package ui.formposting

Source Code of ui.formposting.Controller$ValidatedNameForm

/*
* Copyright 2004-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Header:$
*/
package ui.formposting;

import java.io.Serializable;
import javax.servlet.http.HttpServletRequest;

import org.apache.beehive.netui.pageflow.PageFlowController;
import org.apache.beehive.netui.pageflow.Forward;
import org.apache.beehive.netui.pageflow.FormData;
import org.apache.beehive.netui.pageflow.annotations.Jpf;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

@Jpf.Controller(
    forwards={
        @Jpf.Forward(name="basicFormSuccess", path="basicForm.jsp"),
        @Jpf.Forward(name="outputFormSuccess", path="outputForm.jsp"),
        @Jpf.Forward(name="validatedFormSuccess", path="validatedForm.jsp")
    },
    simpleActions={
        @Jpf.SimpleAction(name="begin", path="index.jsp")
    },
    messageBundles={
        @Jpf.MessageBundle(bundlePath="org.apache.beehive.samples.netui.resources.formposting.messages")
    }
)
public class Controller
    extends PageFlowController {

    @Jpf.Action()
    public Forward showBasicForm() {
        return new Forward("basicFormSuccess");
    }

    @Jpf.Action()
    public Forward postBasicForm(NameForm form) {
        return new Forward("basicFormSuccess");
    }

    @Jpf.Action()
    public Forward showOutputForm() {
        NameForm outputForm = new NameForm();
        outputForm.setName("Frank");
        return new Forward("outputFormSuccess", outputForm);
    }

    @Jpf.Action()
    public Forward postOutputForm(NameForm form) {
        return new Forward("outputFormSuccess", form);
    }

    @Jpf.Action()
    public Forward showValidatedForm() {
        return new Forward("validatedFormSuccess");
    }

    @Jpf.Action(
        validationErrorForward=@Jpf.Forward(name="failure", navigateTo=Jpf.NavigateTo.currentPage)
    )
    public Forward postValidatedForm(ValidatedNameForm form) {
        return new Forward("validatedFormSuccess");
    }

    public static class NameForm
        extends FormData
        implements Serializable {

        private String _name = null;

        public String getName() {
            return _name;
        }

        public void setName(String name) {
            _name = name;
        }
    }

    public static class ValidatedNameForm
        extends NameForm {

        private static final String REQUIRED_NAME = "Frank";

        public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest servletRequest) {
            ActionErrors errors = null;
            if(!REQUIRED_NAME.equals(getName())) {
                errors = new ActionErrors();
                errors.add("name", new ActionMessage("formposting.invalidname"));
            }

            return errors;
        }
    }
}
TOP

Related Classes of ui.formposting.Controller$ValidatedNameForm

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.