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 8650549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:50:59+00:00 2026-06-12T13:50:59+00:00

I have one form with several components, some of them have their own validations

  • 0

I have one form with several components, some of them have their own validations and/or are mandatory. Then I also have several selectOneMenu components that have the same three selectItem elements in their lists. I have defined three commandButton in order to select the same values for all the lists (one commandButton per possible value).

The JSF section

<table>
    <tr>
        <td>
            <h:outputText value="ID:" />
        </td>
        <td>
            <h:inputText value="#{MyClass.id}" id="inTxt_id" required="true">
                <f:validator validatorId="CheckIDPattern" />
            </h:inpuText>
            <h:message for="inTxt_id" errorClass="error" />
        </td>
    </tr>
</table>
<table>
    <tr>
        <td>
            <h:commandButton value="Select all opt1" action="#{MyClass.selectOpt1}" />
            <h:commandButton value="Select all opt2" action="#{MyClass.selectOpt2}" />
            <h:commandButton value="Select all opt3" action="#{MyClass.selectOpt3}" />
        </td>
    </tr>
    <tr>
        <td>
            <h:outputText value="List 1:" />
        </td>
        <td>
            <h:selectOneMenu value="#{MyClass.list1Val}">
                <f:selectItems value="#{MyClass.listOfOptions}" />
            </h:selectOneMenu>
        </td>
    <tr>
        <td>
            <h:outputText value="List 2:" />
        </td>
        <td>
            <h:selectOneMenu value="#{MyClass.list2Val}">
                <f:selectItems value="#{MyClass.listOfOptions}" />
            </h:selectOneMenu>
        </td>
    </tr>
    <tr>
         //Many other selectOneMenu components...
    </tr>
</table>
<h:commandButton action="#{MyClass.saveLists}" value="Submit" />

MyClass.java

public String selectOpt1(){
    this.list1Val = 1;
    this.list2Val = 1;
    //...
    return "";
}

//The same idea for selectOpt2 and selectOpt3.

In this context, if my user presses one of my “select all” buttons without filling the ID inputText, it receives the error message, but I don’t want it because I suppose they haven’t finished filling the form. I just want the validations to be executed when the user presses the “Save Lists” button.

I’ve tried adding immediate="true" to my “select all” buttons, it works but it doesn’t update the view from model and then the user doesn’t see the values have changed… so it really doesn’t work.

What do I want to achieve? I just want the validations to be performed when the last button (submit). So my user could use these “select all” buttons without filling previously the mandatory components.

I hope you understand my context. Feel free to ask for any clarification.
Thanks in advance.

  • 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-06-12T13:51:00+00:00Added an answer on June 12, 2026 at 1:51 pm

    If you’re using @ViewScoped bean you could do the following changes:

    First change your selectOpt1 method to type void:

    public void selectOpt1() 
    {
        this.list1Val = 1;
        this.list2Val = 1;
        //...
    }
    

    Give an id to the component you want to update upon selecting items. I assume List 1 in this case:

    <h:selectOneMenu id="list1" value="#{MyClass.list1Val}">
        //...
    </h:selectOneMenu>
    

    And in your button, add an f:ajax tag that partially submits only that component for processing:

    <h:commandButton value="Select all opt1" action="#{MyClass.selectOpt1}">
        <f:ajax execute="@this" render="list1" />
    </h:commandButton>
    

    If you plan to update multiple components, you may add their id separated by space:

    <f:ajax execute="@this" render="list1 list2" />
    

    I hope it helps.

    Edit

    Well, sorry, I didn’t noticed you’re using JSF 1.x. In this case it wouldn’t work.

    You could use a library such as RichFaces to add ajax functionality though. Please, check out these topics:

    • ajax behaviour in jsf 1.2

    • how do i call a jsf action method (in JSF 1.2) using Ajax?

    RichFaces

    As you mentioned you’re using RichFaces you could switch the f:ajax tag to a4j:support:

    <h:commandButton value="Select all opt1" action="#{MyClass.selectOpt1}">
        <a4j:support event="onclick" reRender=":list1" ajaxSingle="true" />
    </h:commandButton>
    

    Or like this using the a4j:commandButton:

    <a4j:commandButton value="Select all opt1" reRender=":list1" ajaxSingle="true" />
    

    For more info on this behavior, please take a look at this.

    Regards.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an InfoPath form with several fields on, the problem is that one
My goal is to have one main richtextbox in the form, and then several
I have one form that has several elements and two submit buttons, one is
I have several different submit buttons on my JSP in one form tag that
I have one form with several text fields and one button. When i enter
I have one form in a PHP (5.2.9-1) application that causes IIS (Microsoft-IIS/6.0) to
i have one form which have some input box and some select box. i
I need to make the program which have one form that contains PNG image
I have one windows form file that each time I open it in Visual
I have a package that has several components in it that would benefit greatly

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.