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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:32:37+00:00 2026-05-27T16:32:37+00:00

I’m new in jsf and jpa technologies, and trying my first web application with

  • 0

I’m new in jsf and jpa technologies, and trying my first web application with them.

I created a form inside my jsf page which includes all of the table fields.
I want to be able to clean all of the inputs inside of the form. (by clicking ‘clean’ button , or after update/insert/delete action).

Inorder to clean the form I created a new object that all of it’s values will be reseted, but my problem now is when i try to leave from this page (by clicking back) i can’t because i have a null field ( which has @notNull), and also I’m really not sure that this is the right way to clear the form – does it mean that I need to clear the object also?

what is the write way to clean the form? should it also clear the object,entity fields (beacause the form and object are acually the same)?

This is my code:
CustomerDetails.htmlx:

<h:body>
    <h2><h:outputText value="Customer Details"/></h2>
    <h:form>
        <h:panelGrid columns="2" bgcolor="#eff5fa">
            <h:outputLabel value="Customer ID:"/>
            <h:inputText id="customerId" value="#{customer.details.customerId}">
                <f:ajax event="blur"  listener="#{customer.showRecord()}" execute="customerId" render="@all" /> 
            </h:inputText>
            <h:outputLabel value="Customer Name:"/>
            <h:inputText id="customerName" value="#{customer.details.name}"/>
            <h:outputLabel value="Credit Limit:"/>
            <h:inputText id="creditLimit" value="#{customer.details.creditLimit}"/>
            <h:outputLabel value="Discount Code"/>
            <h:selectOneMenu id="discountCode" value="#{customer.details.discount}">
                <f:selectItems value="#{customer.discountCodes}"/>
            </h:selectOneMenu>
            <h:outputLabel value="Email:"/>
            <h:inputText id="email" value="#{customer.details.email}"/>
            <h:outputLabel value="Phone:"/>
            <h:inputText id="phone" value="#{customer.details.phone}"/>
            <h:outputLabel value="Fax:"/>
            <h:inputText id="fax" value="#{customer.details.fax}"/>
            <h:outputLabel value="Address (Line 1):"/>
            <h:inputText id="address1" value="#{customer.details.addressline1}"/>
            <h:outputLabel value="Address (Line 2):"/>
            <h:inputText id="address2" value="#{customer.details.addressline2}"/>
            <h:outputLabel value="State:"/>
            <h:inputText id="state" value="#{customer.details.state}"/>
            <h:outputLabel value="City:"/>
            <h:inputText id="city" value="#{customer.details.city}"/>
            <h:outputLabel value="Zip:"/>
            <h:inputText id="zip" value="#{customer.details.zip}"/>
        </h:panelGrid>                                    
        <h:commandButton value="Clean" id="clean" action="#{customer.clean}"/>             
        <h:commandButton id="back" value="Back" action="#{customer.list}"/>
        <h:commandButton id="update" value="Update" action="#{customer.update}"/>            
        <h:commandButton id="delete" value="Delete" action="#{customer.delete}"/>
    </h:form>
    <p:messages showDetail="true" />
</h:body>

CustomerMBean.java:

public class CustomerMBean {
@EJB
private CustomerSessionBean customerSessionBean;
private Customer customer;

public CustomerMBean() {
}
public List getCustomers()
{
    return customerSessionBean.retrieve();
}
public Customer getDetails()
{
    //Can either do this for simplicity or fetch the details again from the
    //database using the Customer ID        
    return customer;
}  
public Customer showRecord()
{
   Integer test = customer.getCustomerId();
   customer = customerSessionBean.retrieveByCustomer(customer);

   if(customer == null)
   {
       customer = new Customer(test); 
       customer.setDiscount('H');
   }
   return customer;          
}    
public Customer clean()
{
    customer = new Customer();                
    customer.setDiscount('H');
    return customer;        
}    
public String showDetails(Customer customer)
{
    this.customer = customer;
    return "DETAILS";
}
public String update()
{       
    customer = customerSessionBean.update(customer);
    FacesContext context = FacesContext.getCurrentInstance();
    context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,
            "Sucessful", "Record successfully saved!"));
    return "SAVED";
}
public String delete()
{       
    customerSessionBean.delete(customer);
    FacesContext context = FacesContext.getCurrentInstance();
    context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,
            "Sucessful", "Record successfully deleted!"));
    return "DELETE";
}
public String list()
{
    System.out.println("###LIST###");
    return "LIST";
}
public javax.faces.model.SelectItem[] getDiscountCodes()
{
    SelectItem[] options = null;
    List<DiscountCode> discountCodes = customerSessionBean.getDiscountCodes();
    if (discountCodes != null && discountCodes.size() > 0)
    {
        int i = 0;
        options = new SelectItem[discountCodes.size()];
        for (DiscountCode dc : discountCodes)
        {
            options[i++] = new SelectItem(dc.getDiscountCode(),
                    dc.getDiscountCode() + " (" + dc.getRate() + "%)");
        }
    }
    return options;
}

}

Any help will be appriciated..

Thank’s 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-05-27T16:32:37+00:00Added an answer on May 27, 2026 at 4:32 pm

    Either add immediate="true" to the back button so that all non-immediate inputs will be skipped:

    <h:commandButton id="back" value="Back" action="#{customer.list}" immediate="true" />
    

    Or, much better, just make it a normal GET button:

    <h:button id="back" value="Back" outcome="list" />
    

    Unrelated to the concrete problem, read on about new JSF2 implicit navigation feature. Those ugly uppercased outcome values suggest that you’re still using the verbose JSF 1.x way of defining <navigation-case> elements in faces-config.xml.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a text area in my form which accepts all possible characters from
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.