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

  • Home
  • SEARCH
  • 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 9039327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:42:14+00:00 2026-06-16T09:42:14+00:00

I have a managed bean placed in view scope. Here is the bean: @ManagedBean(name

  • 0

I have a managed bean placed in view scope. Here is the bean:

@ManagedBean(name = "adminController")
@ViewScoped
public class AdminController extends BaseWebController implements Serializable {

    private static final long serialVersionUID = 1019716974557397635L;

    private transient CustomerDTO customerDTO;

    @PostConstruct
    public void init() {
        customerDTO = new CustomerDTO();
    }

    public void saveCustomer(ActionEvent event) {
        System.out.println(customerDTO.isActive());
        try {
            getServiceProvider().getCustomerService().addNewCustomer(customerDTO);
            getFacesContext().addMessage(null, FacesMessageUtils.getMessageForCustomerAddSuccess(getFacesContext()));
        } catch (Throwable throwable) {
            getFacesContext().addMessage(null, FacesMessageUtils.getMessageForCustomerAddError(getFacesContext()));
            printStackTrace(throwable);
        }       

    }

    public CustomerDTO getCustomerDTO() {
        return customerDTO;
    }

    public void setCustomerDTO(CustomerDTO customerDTO) {
        this.customerDTO = customerDTO;
    }   
}

The view is:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"
    xmlns:pe="http://primefaces.org/ui/extensions">

    <p:panel header="#{adbBundle['admin.addCustomerPanel.header']}"
        id="addCustomerPanel" toggleable="true">
        <p:panelGrid columns="2" id="addCustomerTable"
            styleClass="addCustomerTable">
            <f:facet name="header">
                <p:outputLabel id="header"
                    value="#{adbBundle['admin.addCustomerPanel.addCustomerTable.header']}" />
            </f:facet>

            <p:outputLabel for="customerName"
                value="#{adbBundle['admin.addCustomerPanel.addCustomerTable.customerName']}" />
            <h:panelGroup layout="block">
                <p:inputText id="customerName" styleClass="customerName"
                    autocomplete="off"
                    label="#{adbBundle['admin.addCustomerPanel.addCustomerTable.customerName']}"
                    value="#{adminController.customerDTO.customerName}" required="true" />
                <pe:tooltip for="customerName"
                    value="#{adbBundle['admin.addCustomerPanel.addCustomerTable.customerName.tooltip']}"
                    showEffect="slideToggle" hideEffect="slideToggle" showDelay="0"
                    myPosition="left center" atPosition="right center" />
            </h:panelGroup>

            <p:outputLabel for="customerId"
                value="#{adbBundle['admin.addCustomerPanel.addCustomerTable.customerId']}" />
            <h:panelGroup layout="block">
                <p:inputText id="customerId" autocomplete="off"
                    label="#{adbBundle['admin.addCustomerPanel.addCustomerTable.customerId']}"
                    value="#{adminController.customerDTO.customerId}" required="true">
                    <f:validator validatorId="customerIDValidator" />
                </p:inputText>
                <pe:tooltip for="customerId"
                    value="#{adbBundle['admin.addCustomerPanel.addCustomerTable.customerId.tooltip']}"
                    showEffect="slideToggle" hideEffect="slideToggle" showDelay="0"
                    myPosition="left center" atPosition="right center" />
            </h:panelGroup>

            <p:outputLabel for="activeStatus"
                value="#{adbBundle['admin.addCustomerPanel.addCustomerTable.activeStatus']}" />
            <h:panelGroup layout="block">
                <p:selectBooleanCheckbox id="activeStatus" value="#{adminController.customerDTO.active}" />  
            </h:panelGroup>

            <f:facet name="footer">
                <p:commandButton value="#{adbBundle['saveButton']}"
                    actionListener="#{adminController.saveCustomer}"
                    icon="ui-icon-check" update=":growl, @form" />
            </f:facet>
        </p:panelGrid>
    </p:panel>

</ui:composition>

The problem that I am facing is, after the actionListener successfully executed the input fields are holding the values.

The h:form is not visible in the aforementioned xhtml, it is placed in the parent page as:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    template="/WEB-INF/templates/globalTemplate.xhtml">

    <ui:define name="title">#{adbBundle['home']}</ui:define>
    <ui:define name="content">
        <p:growl id="growl" showDetail="true" />
        <h:form id="form">
            <ui:include src="/WEB-INF/includes/addCustomer.xhtml" />
        </h:form>
    </ui:define>

</ui:composition>

However if I add customerDTO = new CustomerDTO(); at the end of the actionListener saveCustomer, the inputs are reset.

Is it the way to clear the form? Or there is a better way to achieve this?

  • 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-16T09:42:15+00:00Added an answer on June 16, 2026 at 9:42 am

    To clear form data using ActionEvent on button

    public void clear(){
        customerDTO = new CustomerDTO();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a managed bean (SessionScope as follow) @ManagedBean(name=login) @SessionScoped public class Login implements
I have a managed bean called: @ManagedBean(name=configBean) @SessionScoped public class configBean implements Serializable {
i have an managed bean(session scope) like this: class Home {// as homeBean public
I have something like that: faces-config.xml <managed-bean> <managed-bean-name>aBean</managed-bean-name> <managed-bean-class>some.pack.Bean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> I have a
i have my managed bean like this : @ManagedBean @SessionScoped public class utilisateur implements
I have managed bean with session as managedbean-scope , now in constructor of the
I have code in a managed bean: public void setTestProp(String newProp) { FacesMessage yourFailure
I have a page that is backed by a ViewScoped Managed Bean. The page
We have a Spring managed bean with an @EJB field import org.springframework.security.web.authentication.logout.LogoutHandler; public class
I have a managed bean declared in session scope. There is a drop down

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.