Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6030119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:59:21+00:00 2026-05-23T04:59:21+00:00

Can anyone clarify how we can use in general, or a in real world

  • 0

Can anyone clarify how we can use in general, or a in real world example, this snippet?

<f:metadata>
    <f:viewParam id="id" value="#{bean.id}" />
    <f:viewAction action="#{bean.init}" />
</f:metadata>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:59:22+00:00Added an answer on May 23, 2026 at 4:59 am

    Process GET parameters

    The <f:viewParam> manages the setting, conversion and validation of GET parameters. It’s like the <h:inputText>, but then for GET parameters.

    The following example

    <f:metadata>
        <f:viewParam name="id" value="#{bean.id}" />
    </f:metadata>
    

    does basically the following:

    • Get the request parameter value by name id.
    • Convert and validate it if necessary (you can use required, validator and converter attributes and nest a <f:converter> and <f:validator> in it like as with <h:inputText>)
    • If conversion and validation succeeds, then set it as a bean property represented by #{bean.id} value, or if the value attribute is absent, then set it as request attribtue on name id so that it’s available by #{id} in the view.

    So when you open the page as foo.xhtml?id=10 then the parameter value 10 get set in the bean this way, right before the view is rendered.

    As to validation, the following example sets the param to required="true" and allows only values between 10 and 20. Any validation failure will result in a message being displayed.

    <f:metadata>
        <f:viewParam id="id" name="id" value="#{bean.id}" required="true">
            <f:validateLongRange minimum="10" maximum="20" />
        </f:viewParam>
    </f:metadata>
    <h:message for="id" />
    

    Performing business action on GET parameters

    You can use the <f:viewAction> for this.

    <f:metadata>
        <f:viewParam id="id" name="id" value="#{bean.id}" required="true">
            <f:validateLongRange minimum="10" maximum="20" />
        </f:viewParam>
        <f:viewAction action="#{bean.onload}" />
    </f:metadata>
    <h:message for="id" />
    

    with

    public void onload() {
        // ...
    }
    

    The <f:viewAction> is however new since JSF 2.2 (the <f:viewParam> already exists since JSF 2.0). If you can’t upgrade, then your best bet is using <f:event> instead.

    <f:event type="preRenderView" listener="#{bean.onload}" />
    

    This is however invoked on every request. You need to explicitly check if the request isn’t a postback:

    public void onload() {
        if (!FacesContext.getCurrentInstance().isPostback()) {
            // ...
        }
    }
    

    When you would like to skip "Conversion/Validation failed" cases as well, then do as follows:

    public void onload() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        if (!facesContext.isPostback() && !facesContext.isValidationFailed()) {
            // ...
        }
    }
    

    Using <f:event> this way is in essence a workaround/hack, that’s exactly why the <f:viewAction> was introduced in JSF 2.2.


    Pass view parameters to next view

    You can "pass-through" the view parameters in navigation links by setting includeViewParams attribute to true or by adding includeViewParams=true request parameter.

    <h:link outcome="next" includeViewParams="true">
    <!-- Or -->
    <h:link outcome="next?includeViewParams=true">
    

    which generates with the above <f:metadata> example basically the following link

    <a href="next.xhtml?id=10">
    

    with the original parameter value.

    This approach only requires that next.xhtml has also a <f:viewParam> on the very same parameter, otherwise it won’t be passed through.


    Use GET forms in JSF

    The <f:viewParam> can also be used in combination with "plain HTML" GET forms.

    <f:metadata>
        <f:viewParam id="query" name="query" value="#{bean.query}" />
        <f:viewAction action="#{bean.search}" />
    </f:metadata>
    ...
    <form>
        <label for="query">Query</label>
        <input type="text" name="query" value="#{empty bean.query ? param.query : bean.query}" />
        <input type="submit" value="Search" />
        <h:message for="query" />
    </form>
    ...
    <h:dataTable value="#{bean.results}" var="result" rendered="#{not empty bean.results}">
         ...
    </h:dataTable>
    

    With basically this @RequestScoped bean:

    private String query;
    private List<Result> results;
    
    public void search() {
        results = service.search(query);
    }
    

    Note that the <h:message> is for the <f:viewParam>, not the plain HTML <input type="text">! Also note that the input value displays #{param.query} when #{bean.query} is empty, because the submitted value would otherwise not show up at all when there’s a validation or conversion error. Please note that this construct is invalid for JSF input components (it is doing that "under the covers" already).


    See also:

    • ViewParam vs @ManagedProperty(value = "#{param.id}")
    • Communication in JSF 2.0 – Processing GET request parameters
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone just clarify this for me, I was under the impression that to
Can anyone tell me what's wrong with this code? class Dataset < ActiveRecord::Base has_many
Can anyone clarify/elucidate the situation with respect to -[NSNotificationCenter addObserver:selector:name:object:] ? What types of
(I've tried posting this on YUI message group but without any luck) Can anyone
Can anyone please clarify what the differences are between the two? The Javadoc is
can anyone help me in trying to check whether JavaScript is enabled in client
Can anyone tell me whether Helvetica is a browser base font? If so, it
Can anyone recommend a good cheat sheet for gbd? I'm experienced with windbg commands,
Can anyone tell me why ActionScript 3, a statically typed language, doesn't have generics?
Can anyone help? I have been using the entity framework and its going well

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.