官术网_书友最值得收藏!

  • Jakarta EE Cookbook
  • Elder Moraes
  • 210字
  • 2021-06-24 16:12:37

How it works...

From the code in the preceding section, we see that the UserBean class manages the communication between the UI and the server. Once you instantiate the user object, it is available for both of them.

That's why, when you run it, Name | E-mail is already filled (the user object is instantiated when the UserBean class is created by the server).

We associated the userAction() method from the UserBean class with the Validate button of the UI:

<h:commandButton value="Validate" action="#{userBean.userAction()}"/>

You can create other methods in UserBean and do the same to empower your application.

The whole core of our recipe is represented by just a single line in the UI:

<h:inputText id="userNameEmail" value="#{userBean.user}" converter="userConverter" validator="userValidator"/>

So, our two implemented interfaces used here are userConverter and userValidator.

Basically, the UserConverter class (with the getAsString and getAsObject methods) converts an object into/from a string and vice versa, according to the logic defined by you.

We have just mentioned it in the preceding code snippet:

value="#{userBean.user}"

The server uses the userConverter object, calls the getAsString method, and prints the result using the preceding expression language.

Finally, the UserValidator class is automatically called when you submit the form, by calling its validate method, and applying the rules defined by you.

主站蜘蛛池模板: 滨海县| 陇川县| 泰来县| 固原市| 尼木县| 盐边县| 天津市| 德州市| 泰和县| 姜堰市| 宁波市| 浑源县| 教育| 泰顺县| 竹山县| 边坝县| 铁岭县| 婺源县| 湘潭市| 镇原县| 凤台县| 新乐市| 观塘区| 确山县| 锡林浩特市| 铜鼓县| 承德市| 抚顺市| 临沧市| 石狮市| 万全县| 绵竹市| 抚远县| 民勤县| 缙云县| 汕尾市| 广宗县| 长沙市| 工布江达县| 长岛县| 佛山市|