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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:57:13+00:00 2026-05-26T21:57:13+00:00

I am currently learning Java EE using JBoss and I am kind of stuck

  • 0

I am currently learning Java EE using JBoss and I am kind of stuck with a simple problem. Even though it should be common I did not find a solution in the internet.

I want to display a list of contacts and if a contact is selected a details page opens and the contact information can be edited.

The contact is a JPA Entity. Creating new contacts and displaying a list of contacts and a details page works fine. However I have trouble updating the contact information.

If a contact is clicked I open a details page and pass the id as get parameter. Now the following JSF code is executed:

<f:metadata>
  <f:viewParam name="contactID" value="#{contactUpdate.contactID}" />
</f:metadata>


<h:form>
  <h:outputLabel for="firstName" value="First Name:" />
  <h:inputText id="firstName" value="#{contactUpdate.contact.firstName}" />
  <h:commandButton id="register" action="#{contactUpdate.updateContact()}" value="Update" />
</h:form>

That is the bean (getter and setters removed):

@Stateful
@Named
@RequestScoped
public class ContactUpdate {

@Inject
private EntityManager em;

private Contact contact;
private long contactID;


public void updateContact(){
    EntityTransaction transaction = em.getTransaction();
    transaction.begin();
    transaction.commit();
}

public void setContactID(long contactID) {
    this.contactID = contactID;

    setContact(em.find(Contact.class, contactID));
}

}

If I update it, the contact is null. I assume that the request scope is too short and already cleared. Is it possible to set the contactID upon commit?

I thought it would also be possible to use @ViewScoped, but doing so the <f:viewParam> does not work anymore.

  • 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-26T21:57:13+00:00Added an answer on May 26, 2026 at 9:57 pm

    Because you’re preparing the contact in a setter of a view parameter, you need to pass the contact ID back as request parameter so that the request scoped bean can prepare it properly:

    <h:commandButton id="register" action="#{contactUpdate.updateContact()}" value="Update">
        <f:param name="contactID" value="#{contactUpdate.contactID}" />
    </h:commandButton>
    

    But better would be to not do any business logic in setters (and definitely also not in getters) and use <f:event type="preRenderView"> instead. This way the @ViewScoped will work as expected.

    See also:

    • 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

I'm currently learning Java, using a combination of the Head First Java book and
I am learning Java using the book Java: The Complete Reference. Currently I am
As I'm currently learning Django / Python, I've not really been using the concept
im currently learning stacks in java and have a quick question. what will the
I am currently learning about basic networking in java. I have been playing around
I'm currently learning to develop for the .net compact framework using c# in VS2008
I'm currently learning Java EE, or more specifically, Servlets and .jsp. In my programming,
I have starting learning Java and android application development side-by-side. Currently, I a String-array
I am currently using IOS SDK 4.0.2 and learning how to do UIAutomation. Unfortunately
I'm currently learning game programming using a framework called libgdx. It allows users to

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.