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

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.

主站蜘蛛池模板: 翼城县| 琼结县| 井研县| 双牌县| 建阳市| 龙岩市| 大厂| 西峡县| 霍林郭勒市| 宁河县| 迭部县| 广宁县| 平江县| 梁山县| 广灵县| 江孜县| 西乌珠穆沁旗| 全椒县| 绥德县| 额济纳旗| 安阳县| 东至县| 常宁市| 色达县| 建水县| 比如县| 孟村| 伊通| 平罗县| 宣城市| 辽阳市| 彭水| 千阳县| 平遥县| 农安县| 石林| 宜兰县| 天长市| 彭水| 罗源县| 巍山|