On the way to componentization (4) -- Understanding the front-end status of JSF's advantages

Source: Internet
Author: User

Add the tail left in the previous article: jsp is used as the page when you first read the JSF book. The # {xx} mark cannot be directly written on the page, it must be embedded in a tag (as depressing as ognl in struts2 ). Later I learned that this is a jsp issue, not a JSF issue. Now we all use facelets for JSF display, and JSF2.0 makes this standardization the first choice. Therefore, write # {someAction. dosomething (Hello)} directly on the page. It is completely OK. This method is called when the page is loaded.

Then let's take a look at the backend to know what the frontend has:

 

<H: form>
<H: selectOneMenu value = "# {someAction. choise}">
<F: selectItem itemLabel = "a" itemValue = "123"/> <f: selectItem itemLabel = "B" itemValue = "456"/>
</H: selectOneMenu>
</H: form>


The code above is a drop-down box at the end of the client. When the customer selects an option and submits the final form, the selected value is set to the choise attribute of someAction. You can try to use firebug or other browser Tools to add an option on the client itself, give a value that is not originally available, and then submit it. You will find that JSF will find that the submitted value is no longer in the alternative list, so an exception is thrown. The JSF page is componentized, And the backend program can know something on the front-end page during running, so it can automatically perform verification.

 


Verification is a typical example, but there are many other advantages to know the status of the front-end. For example, when submitting a form, you can easily know the original value of an input box.

 

JSF1 itself is quite disgusting in handling the options in the drop-down box. When you have a set in the background action and want to generate options based on this set, it will cause some trouble. Fortunately, seam solves this problem, so the following effects can be achieved after the same reference:


<H: form>
<H: selectOneMenu value = "# {someAction. choise}">
<Jsf: selectItems value = "# {someAction. options}" var = "o" label = "# {o}"/>
</H: selectOneMenu>
</H: form>


Here, the options are generated based on the choise set in someAction.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.