<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    開花流水

    空山無人,水流花開。

    BlogJava 首頁 新隨筆 聯系 聚合 管理
      79 Posts :: 42 Stories :: 160 Comments :: 0 Trackbacks

    <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
    <%@ page contentType="text/html;charset=utf-8" pageEncoding="UTF-8"%>

    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <!-- RichFaces tag library declaration -->
    <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
    <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
    <html>
     <f:view>
      <head>
       <title>JSF in Action - Validator examples</title>
      </head>
      <body>
       <h1>
        Validator examples
       </h1>


       <h:form>
        <table border="1" cellspacing="0" cellpadding="5">
         <tr>
          <td>
           <b>Validator(s)</b>
          </td>
          <td>
           <b>Comments</b>
          </td>
          <td>
           <b>Input</b>
          </td>
          <td>
           <b>Errors</b>
          </td>
         </tr>
         <tr>
          <td>
           Validation method
          </td>
          <td>
           validator=testForm.validateEmail
          </td>
          <td>
           <h:inputText id="methodInput"
            validator="#{testForm.validateEmail}" />
          </td>
          <td>
           <h:message for="methodInput" style="color: red" />
          </td>
         </tr>
         <tr>
          <td>
           None (component property)
          </td>
          <td>
           required="true"
          </td>
          <td>
           <h:selectOneMenu id="RequiredInput" required="true">
            <f:selectItem itemValue="" itemLabel="" />
            <f:selectItem itemValue="1" itemLabel="dogs" />
            <f:selectItem itemValue="2" itemLabel="birds" />
            <f:selectItem itemValue="3" itemLabel="hamsters" />
           </h:selectOneMenu>
          </td>
          <td>
           <h:message for="RequiredInput" style="color: red" />
          </td>
         </tr>
         <tr>
          <td>
           Length
          </td>
          <td>
           minimum="2"
           <br>
           maxmimum="10"
          </td>
          <td>
           <h:inputText id="LengthInput">
            <f:validateLength minimum="2" maximum="10" />
           </h:inputText>
          </td>
          <td>
           <h:message for="LengthInput" style="color: red" />
          </td>
         </tr>
         <tr>
          <td>
           LongRange
          </td>
          <td>
           minimum="5"
           <br>
           maxmimum="999999"
          </td>
          <td>
           <h:inputText id="LongRangeInput">
            <f:validateLongRange minimum="5" maximum="999999" />
           </h:inputText>
          </td>
          <td>
           <h:message for="LongRangeInput" style="color: red" />
          </td>
         </tr>
         <tr>
          <td>
           DoubleRange
          </td>
          <td>
           minimum="5.1"
           <br>
           maxmimum="6.76"
          </td>
          <td>
           <h:selectOneRadio id="DoubleRangeInput">
            <f:selectItem itemValue="5.0" itemLabel="5.0" />
            <f:selectItem itemValue="6.1" itemLabel="6.1" />
            <f:selectItem itemValue="6.8" itemLabel="6.8" />
            <f:validateDoubleRange minimum="5.1" maximum="6.76" />
           </h:selectOneRadio>
          </td>
          <td>
           <h:message for="DoubleRangeInput" style="color: red" />
          </td>
         </tr>
         <tr>
          <td>
           Length, LongRange
          </td>
          <td>
           required="true"
           <br>
           Length minimum="2"
           <br>
           Length maxmimum="3"
           <br>
           LongRange minimum="10"
           <br>
           LongRange maxmimum="999"
          </td>
          <td>
           <h:inputText id="MultiInput" required="true">
            <f:validateLength minimum="2" maximum="3" />
            <f:validateLongRange minimum="10" maximum="999" />
           </h:inputText>
          </td>
          <td>
           <h:message for="MultiInput" style="color: red" />
          </td>
         </tr>
        </table>
        <p>
         <h:commandButton value="Go!" />
       </h:form>
      </body>
     </f:view>


    </html>

    posted on 2009-06-05 13:57 開花流水 閱讀(1023) 評論(2)  編輯  收藏 所屬分類: java技術

    Feedback

    # re: jsf驗證的例子 2009-06-05 13:59 空山戊
    import java.io.*;
    import javax.faces.event.ActionEvent;
    import javax.faces.context.*;
    import java.util.*;
    import javax.faces.component.*;
    import javax.faces.application.*;
    import javax.faces.model.*;
    import javax.faces.component.html.*;
    import javax.faces.event.*;
    import javax.faces.lifecycle.*;
    import javax.faces.FactoryFinder;
    import javax.faces.lifecycle.Lifecycle;
    import javax.faces.component.UICommand;
    import javax.faces.validator.*;

    @SuppressWarnings("serial")
    public class TestForm implements Serializable
    {
    private int counter;
    private String message = "What time is love?";
    private String loggingMessage;
    private boolean toggleFlag = false;
    private int number;
    private String string;
    private javax.faces.component.UIData testTable;
    private double doubleValue = 0.056;
    private javax.faces.model.SelectItem[] colors;
    private transient UserConverter userConverter = new UserConverter();
    private UIPanel converterPanel = null;
    private UserBean user;
    private javax.faces.component.UIViewRoot view;
    private javax.faces.component.html.HtmlPanelGrid changePanel;
    private javax.faces.component.html.HtmlOutputText outputText;
    private javax.faces.component.html.HtmlDataTable dataTable;
    private javax.faces.application.Application application;
    private boolean addMessages = true;

    // Actions

    public TestForm()
    {
    colors = new SelectItem[5];
    colors[0] = new SelectItem("0", "blue");
    colors[1] = new SelectItem("1", "red");
    colors[2] = new SelectItem("2", "green");
    colors[3] = new SelectItem("3", "black");
    colors[4] = new SelectItem("4", "purple");

    UIOutput output = (UIOutput)getApplication().createComponent("javax.faces.Output");

    LifecycleFactory lifecycleFactory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
    Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
    lifecycle.addPhaseListener(
    new PhaseListener()
    {
    public void beforePhase(PhaseEvent event)
    {
    // refreshList();
    }

    public void afterPhase(PhaseEvent event)
    {
    }

    public PhaseId getPhaseId()
    {
    return PhaseId.RENDER_RESPONSE;
    }
    });

    }

    public UICommand getTestCommand()
    {
    UICommand command = (UICommand)getApplication().
    createComponent(HtmlCommandButton.COMPONENT_TYPE);
    command.addActionListener(new ActionListener()
    {
    public void processAction(ActionEvent event) throws AbortProcessingException
    {
    FacesContext.getCurrentInstance().getExternalContext().
    log("User fired action for command " + event.getComponent());
    }
    });
    command.setValueBinding("value",
    getApplication().createValueBinding("#{myBean.userName}"));
    command.setValueBinding("title",
    getApplication().createValueBinding("#{myBundle.userNameTitle}"));

    LongRangeValidator myValidator = (LongRangeValidator)
    application.createValidator(LongRangeValidator.VALIDATOR_ID);
    myValidator.setMinimum(0);
    myValidator.setMaximum(555);
    UIInput input = new UIInput();
    input.addValidator(getApplication().createValidator(LongRangeValidator.VALIDATOR_ID));
    return null;
    }

    public String toggleNextOrPrevious()
    {
    toggleFlag = !toggleFlag;
    if (toggleFlag)
    {
    return "next";
    }
    else
    {
    return "previous";
    }
    }

    public String incrementCounter()
    {
    counter++;
    return "success";
    }

    public String loadInbox()
    {
    return "inbox";
    }

    public String logout()
    {
    return "logout";
    }

    public void incrementCounter(ActionEvent e)
    {
    counter++;
    }

    // Properties

    public int getCounter()
    {
    return counter;
    }

    public void setCounter(int counter)
    {
    this.counter = counter;
    }

    public String getMessage()
    {
    return message;
    }

    public void setMessage(String message)
    {
    this.message = message;
    }

    public String getLoggingMessage()
    {
    return loggingMessage;
    }

    public void setLoggingMessage(String loggingMessage)
    {
    this.loggingMessage = loggingMessage;
    }

    public boolean getTrueProperty()
    {
    return true;
    }

    public boolean getFalseProperty()
    {
    return false;
    }

    public int getNumber()
    {
    return number;
    }

    public void setNumber(int number)
    {
    this.number = number;
    }

    public String getString()
    {
    return string;
    }

    public void setString(String string)
    {
    this.string = string;
    }

    public void setConverterPanel(UIPanel panel)
    {
    this.converterPanel = panel;
    }

    public UIPanel getConverterPanel()
    {
    if (converterPanel == null)
    {
    converterPanel = (UIPanel)FacesContext.getCurrentInstance().getApplication().createComponent(HtmlPanelGrid.COMPONENT_TYPE);
    UIOutput output = (UIOutput)FacesContext.getCurrentInstance().getApplication().createComponent(HtmlOutputText.COMPONENT_TYPE);
    output.setValue("foo2");
    converterPanel.getChildren().add(output);
    }
    return converterPanel;
    }

    // Event handlers

    public void toggleLocale(ActionEvent e)
    {
    FacesContext context = FacesContext.getCurrentInstance();
    UIViewRoot view = context.getViewRoot();
    if (view.getLocale().equals(Locale.ENGLISH))
    {
    view.setLocale(new Locale("es", "ES"));
    }
    else
    {
    view.setLocale(Locale.ENGLISH);
    }
    }

    public void validateEmail(FacesContext context, UIComponent component,
    Object value)
    {
    EditableValueHolder input = (EditableValueHolder)component;
    context.getExternalContext().log("inside validateEmail");
    if (((String)value).indexOf("@") > -1)
    {
    input.setValid(true);
    }
    else
    {
    context.addMessage(component.getClientId(context),
    new FacesMessage("Invalid e-mail address", null));
    input.setValid(false);
    }
    }

    public void testCommand(ActionEvent e)
    {
    Map project = (Map)testTable.getRowData();
    message = (String)project.get("name");
    }

    public javax.faces.component.UIData getTestTable()
    {
    return testTable;
    }
    public void setTestTable(javax.faces.component.UIData testTable)
    {
    this.testTable = testTable;
    }
    public double getDoubleValue()
    {
    return doubleValue;
    }
    public void setDoubleValue(double doubleValue)
    {
    this.doubleValue = doubleValue;
    }
    public javax.faces.model.SelectItem[] getColors()
    {
    return colors;
    }
    public void setColors(javax.faces.model.SelectItem[] colors)
    {
    this.colors = colors;
    }
    public UserConverter getUserConverter() {
    return userConverter;
    }
    public void setUserConverter(UserConverter userConverter) {
    this.userConverter = userConverter;
    }

    protected void createComponent(Application app, List children,
    String componentType, String converterType)
    {
    /*
    HtmlOutputText outputText = application.createComponent(
    HtmlOutputText.COMPONENT_TYPE);

    UIComponent component = app.createComponent(componentType);
    if ((component instanceof UIOutput) && !(component instanceof UISelectBoolean))
    {
    if (componentType.indexOf("Select") > -1)
    {
    return;
    /* for (int i = 0; i < 50; i++)
    {
    UISelectItem item = new UISelectItem();
    item.setItemLabel(String.valueOf(i));
    item.setItemValue(String.valueOf(i));
    component.getChildren().add(item);
    }*/
    }
    /* UIOutput label = new UIOutput();
    label.setValue(componentType);
    children.add(label);


    ((UIOutput)component).setValue(new Date());
    //new User("foo", "foo", RoleType.BUSINESS_ANALYST));
    ((UIOutput)component).setConverter(app.createConverter(converterType));
    children.add(component);
    }
    }

    public void testConverters(ActionEvent e)
    {
    List children = converterPanel.getChildren();
    children.clear();
    Application app = FacesContext.getCurrentInstance().getApplication();
    Iterator componentTypes = app.getComponentTypes();
    while (componentTypes.hasNext())
    {
    createComponent(app, children, (String)componentTypes.next(), "DateTime");
    }
    }
    */
    public void addMessages(ActionEvent e)
    {
    FacesContext context = FacesContext.getCurrentInstance();
    if (addMessages)
    {
    context.addMessage(null, new FacesMessage("Your order has been processed successfully.", ""));
    context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN,
    "Free shipping limit exceeded.",
    "We had to charge your card an extra $25 for shipping."));
    }
    }
    public UserBean getUser()
    {
    return user;
    }
    public void setUser(UserBean user)
    {
    this.user = user;
    }
    public javax.faces.component.UIViewRoot getView()
    {
    return view;
    }
    public void setView(javax.faces.component.UIViewRoot view)
    {
    this.view = view;
    }

    public void sendMessage(ActionEvent e)
    {
    FacesContext context = FacesContext.getCurrentInstance();
    UIViewRoot view = context.getViewRoot();
    HtmlOutputText output =
    (HtmlOutputText)view.findComponent("messageForm:outputMessage");
    output.setStyle("color:blue");
    output.setValue("Who's the Mann?");
    }

    public void processValueChanged(ValueChangeEvent event)
    // throws AbortProcessingException
    {
    /* UIInput sender = (UIInput)event.getComponent();
    sender.setReadonly(true);
    changePanel.setRendered(true);*/
    }

    public javax.faces.component.html.HtmlPanelGrid getChangePanel()
    {
    return changePanel;
    }
    public void setChangePanel(javax.faces.component.html.HtmlPanelGrid changePanel)
    {
    this.changePanel = changePanel;
    }
    public javax.faces.component.html.HtmlOutputText getOutputText()
    {
    return outputText;
    }
    public void setOutputText(javax.faces.component.html.HtmlOutputText outputText)
    {
    this.outputText = outputText;
    }
    public javax.faces.component.html.HtmlDataTable getDataTable()
    {
    if (dataTable == null)
    {
    String numberStrings[] = new String[] {"one", "two", "three"};
    FacesContext facesContext = FacesContext.getCurrentInstance();
    dataTable = (HtmlDataTable)facesContext.getApplication().createComponent(
    HtmlDataTable.COMPONENT_TYPE);
    DataModel myDataModel = new ArrayDataModel(numberStrings);
    myDataModel.addDataModelListener(new DataModelListener()
    {

    public void rowSelected(DataModelEvent e)
    {
    FacesContext.getCurrentInstance().getExternalContext().
    log("phase: " + e.getRowIndex() + "; row seleted:" + e.getRowIndex());
    }
    });
    dataTable.setValue(myDataModel);
    }
    return dataTable;
    }

    public void setDataTable(javax.faces.component.html.HtmlDataTable dataTable)
    {
    this.dataTable = dataTable;
    }
    public javax.faces.application.Application getApplication()
    {
    return FacesContext.getCurrentInstance().getApplication();
    }
    public void setApplication(javax.faces.application.Application application)
    {
    this.application = application;
    }
    public boolean isAddMessages()
    {
    return addMessages;
    }
    public void setAddMessages(boolean addMessages)
    {
    this.addMessages = addMessages;
    }

    public void deleteUser(ActionEvent e)
    {
    UserBean user = (UserBean)testTable.getRowData();
    ArrayList userList = (ArrayList)testTable.getValue();
    userList.remove(user);
    }

    public String testImmediate()
    {
    FacesContext.getCurrentInstance().getExternalContext().log("Input value = " + message);
    return null;
    }

    }
      回復  更多評論
      

    # re: jsf驗證的例子 2011-05-02 22:33 代寫文章
    ://www.daixie9.com">www.daixie99.com  回復  更多評論
      

    主站蜘蛛池模板: 永久免费不卡在线观看黄网站| 曰批全过程免费视频在线观看| 中文字幕亚洲综合久久2| 成年性生交大片免费看| 欧洲乱码伦视频免费国产| 亚洲av中文无码乱人伦在线咪咕| 无码国产精品久久一区免费 | 高清国语自产拍免费视频国产 | AV在线亚洲男人的天堂| 日韩插啊免费视频在线观看| 亚洲国产无线乱码在线观看| 亚洲成AV人片在WWW色猫咪 | 日韩亚洲人成在线| 无码乱人伦一区二区亚洲一| 在线观看免费毛片| 免费H网站在线观看的| 黄色视频在线免费观看| 亚洲AV永久无码天堂影院| 亚洲精品在线免费看| 久久精品夜色国产亚洲av| 国产亚洲视频在线播放| 国产精品99久久免费| 在线a级毛片免费视频| 1000部禁片黄的免费看| 精品一区二区三区免费| 中文字幕免费播放| 一区二区三区免费精品视频| 国产成人人综合亚洲欧美丁香花 | 亚洲XX00视频| 亚洲熟伦熟女新五十路熟妇| 亚洲国产精品视频| 亚洲国产成人久久综合区| 亚洲av无码成人精品区在线播放 | 91麻豆最新在线人成免费观看 | 全免费a级毛片免费**视频| 永久免费AV无码国产网站| 18禁止观看免费私人影院| 成人爽A毛片免费看| 国产成人啪精品视频免费网| 国产精品jizz在线观看免费| 亚洲国产av无码精品|