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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:44:10+00:00 2026-05-27T06:44:10+00:00

I’m using Mojarra 2.0.3 on JBoss AS 6 with Primefaces 2.2.1 + Hibernate. I’ve

  • 0

I’m using Mojarra 2.0.3 on JBoss AS 6 with Primefaces 2.2.1 + Hibernate.

I’ve got a master-detail-view with p:datatable and p:dialog for Person (prename, lastname).

Code of Person.java:

@Entity
public class Person implements Serializable {

private static final long serialVersionUID = 279906432340876832L;
@Id
@GeneratedValue(strategy = javax.persistence.GenerationType.AUTO)
private Long id;

private String prename;
private String lastname;

    // getter and setter...
}

With a “create”-button a new instance can be created, with the “edit”-button, a selected item can be edited.

Code of .xhtml:

<h:form id="personForm">

    <!-- 2 Buttons to open create/edit Dialog -->
    <p:panel id="tableButtons">
        <p:commandButton value="create" action="#{personBean.showCreateView}"
            update="personForm:detailPanel" oncomplete="personDialog.show()" />
        <p:commandButton value="edit" action="#{personBean.showEditView}"
            update="personForm:detailPanel" oncomplete="personDialog.show()"
            rendered="#{personBean.rowSelected}" />
    </p:panel>

    <!--  DataTable for list-View -->
    <p:dataTable var="item" styleClass="table"
        value="#{personBean.personList}" id="personTable" paginator="true"
        selectionMode="single" selection="#{personBean.selectedPerson}"
        rowSelectListener="#{personBean.select}"
        onRowSelectUpdate="personForm:tableButtons"
        rowUnselectListener="#{personBean.unselect}"
        onRowUnselectUpdate="personForm:tableButtons" rows="10">
        <p:column sortBy="#{item.prename}">
            <f:facet name="header">
                <h:outputText value="prename" />
            </f:facet>
            <h:outputText value="#{item.prename}" />
        </p:column>
        <p:column sortBy="#{item.lastname}">
            <f:facet name="header">
                <h:outputText value="lastname" />
            </f:facet>
            <h:outputText value="#{item.lastname}" />
        </p:column>
    </p:dataTable>

    <!--  Dialog for detailed-View -->
    <p:dialog id="personDialog" widgetVar="personDialog">
        <p:panel id="detailPanel">
            <h:panelGrid cellpadding="4">
                <h:outputText value="prename: " />
                <h:inputText value="#{personBean.selectedPerson.prename}" />
                <h:outputText value="lastname: " />
                <h:inputText value="#{personBean.selectedPerson.lastname}" />
            </h:panelGrid>
            <p:commandButton value="persist"
                actionListener="#{personBean.persist}"
                rendered="#{personBean.createView}" update="personForm"
                oncomplete="personDialog.hide()" />
            <p:commandButton value="save" actionListener="#{personBean.merge}"
                update="personForm" rendered="#{personBean.editView}"
                oncomplete="personDialog.hide()" />
        </p:panel>
    </p:dialog>

</h:form>

The managedBean holds 2 boolean attributes createView/editView which appear in the render-attribute of the dialogs commandbuttons, a List for the DataTable, “selectedPerson” for Detail-View and another boolean to trigger edit-Button in case of row-selection in the DataTable.

Code of Managed-Bean:

@ManagedBean(name = "personBean")
@ViewScoped
public class PersonMBean {

private List<Person> personList;
private Person selectedPerson;

// row in the table has been selected
private boolean rowSelected;

// only render the active View
private boolean createView;
private boolean editView;
// ... displayView and more possible

@EJB
private CRUDService crudService;

public PersonMBean() {
    personList = new ArrayList<Person>();
    selectedPerson = new Person();
}

// CRUD-options
public String persist(ActionEvent actionEvent) {
    crudService.persist(selectedPerson);
    return null;
}
public String merge(ActionEvent actionEvent) {
    selectedPerson = crudService.merge(selectedPerson);
    return null;
}

// switch between Views
public String showCreateView() {
    selectedPerson = new Person();
    createView = true;
    editView = false;
    return null;
}
public String showEditView() {
    createView = false;
    editView = true;
    return null;
}

public List<Person> getPersonList() {
    return crudService.getAllPerson();
}

public Person getSelectedPerson() {
    if (selectedPerson == null) {
        selectedPerson = new Person();
    }
    return selectedPerson;
}

public String select(SelectEvent event) {
    setRowSelected(true);
    return null;
}

public String unselect(UnselectEvent event) {
    setRowSelected(false);
    return null;
}

// getter + setter
public void setPersonList(List<Person> personList) {this.personList = personList;}
public void setSelectedPerson(Person selectedPerson) {this.selectedPerson = selectedPerson;}
public boolean isRowSelected() {return rowSelected;}
public void setRowSelected(boolean rowSelected) {this.rowSelected = rowSelected;}
public void setCreateView(boolean createView) {this.createView = createView;}
public boolean isCreateView() {return createView;}
public void setEditView(boolean editView) {this.editView = editView;}
public boolean isEditView() {return editView;}

}

The problem is that while a single create/edit Person is successfull, after that a create-Action inserts an empty row and an edit-Action inserts a row with wrong values. When I reload the page, again the first action is ok, the second one fails… 🙁

I suppose that the PersonMBean.selectedPerson has got an obsolete state but I can not figure it out nor can I find a solution to solve it.

p.s. crudService just calls em.persist + em.merge

Code of CRUDService:

@Stateless
public class CRUDService {

@PersistenceContext
EntityManager em;

public <T> T persist(T t) {
    this.em.persist(t);
    return t;
}

public <T> T merge(T t) {
    return this.em.merge(t);
}

@SuppressWarnings("unchecked")
public List<Person> getAllPerson() {
    Query q = em.createQuery("from Person");
    return q.getResultList();
}
}

The web.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID"
version="3.0">
<context-param>
    <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
    <param-value>false</param-value>
</context-param>
<servlet>
    <servlet-name>facesServlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>

I’m really struggling on this one, hope you can help me.

If anything is wrong with formatting / style please let me know so I can update it.

  • 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-27T06:44:11+00:00Added an answer on May 27, 2026 at 6:44 am

    Check out http://www.jaxio.com/en/celerio.html it outputs JSF + Primefaces master/detail pages that can be used as an example

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I've got a string that has curly quotes in it. I'd like to replace
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.