|
JavaOnRails
A java web framework like Rails doesIntroductionAction mappingLook at this URI: /jmap/main/login/some-hint-like-a-id
This controller class should be extends from the net.javaonrails.webnav.jmap.controller.ControllerBase. The ControllerBase provide many basic methods to connect the servlet context with controller. And the ControllerBase also provide a jsp file render method. You may refer to the source code of this class, or, you can refer to the example code net.javaonrails.webnav.jmap.test.controller.Main.java.
public void Login() in the Main class. A String 'some-hint-like-a-id' will be passed to the controller field urlHint. You can use getUrlHint() to get it. Form values validating and mappingIf you leave the controller method Login without annotation, the default java bean class will been looking for in this rule: The default form bean class full name will be (package.prefixname.)bean.(servlet-path-name).(response-method-name). The bean. is a fixed name that will be added automatically. So, the last example URI: /jmap/main/login/some-hint-like-a-id will be mapped to a java bean class name: (package.prefixname.)bean.main.Login.java. This bean should extends the BasicBean or FileUploadBean. These base class supply more default behave and helper method to support developers. You can add an annotation @CreateBean to the controller class method Login to control the form value bean creating rule. These annotation attributes are:
If you donot like this default rule name, you also can assign another one use these annotation attributes. After the bean has been created, initFormValues(ControllerBase) method will be called by the servlet. The developer also can override this method and call super.initFormValues let the base class map the form values and validating the fields. Then, another bean class method will be called, execute(), the developer can override this method. In the time, the bean instance has been initialized and form values has been validated and set. You can sit and check these values do some database operation, retrive business data put them into List or Map in this inherited class instance. The servlet will put this instance into the HttpServletRequest attribute use the default name or any other name you assigned in @CreateBean(requestAttrName="some_name_you_like"), so that jsp file can easily get them back like this <c:foreach var="user" items="${MainLogin.usersList}">. At last, the controller method Login() will be called by the servlet. So, before the controller method be called, the form data and business data had been prepared and ready to go. Your code just check the bean's status if some error occurred and make a render call to write out the response. As you know, the Rails controller structure has a little problem: all uri mapping methods are defined in it, if you do not execute a strict developing specification, programmers may write all business code in the controller class so that class is too long to review. I suggest that you may write the business code out of the controller class, maybe the bean's execute() method is a good choice. You may refer to the example page in the source package. There is a java bean to map the web request form values for /main/login page and bean's class is net.javaonrails.webnav.test.bean.main.Login. You can find the class Login is extends from BasicBean. The form bean should be extended from the BasicBean or FileUploadBean. Actually, the FileUploadBean extends the BasicBean and override the initFormValues method to handle the multipart/form-data form enctype. If your bean should accept the file upload form data, you should declare the bean to extend the FileUploadBean. Until now, I provide @Required, @MaxLength, @MinLength, @RulePattern field annotations to mark the form field validation rules. You can refer to the bean class Login in source code and take a look at the field loginName for example. You can find these annotations' defination in the package net.javaonrails.webnav.jmap.validator. And now, i'm checking the JaValid to replace my own implement validators. |