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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:37:02+00:00 2026-05-29T19:37:02+00:00

My goal is to present a jsf page that has Create, Retrieve and Update

  • 0

My goal is to present a jsf page that has Create, Retrieve and Update features.
I decided to create different CDI beans and different composite components for each of this operations and then put it all together in the page.

So far so good, but i just finished and i discovered a really confusing bug, and i don’t know how to fix it:

The CDI bean tool that does the CREATE operation is a @RequestScoped bean, so the input fields clean them selves after the request.(See the image bellow)

enter image description here

I have no problem at all with it(Just that warning i cant get rid off), it works fine.

The next gadget i created is a data table that can also edit the data. To do it i needed to use a @SessionScopped CDI bean.(See image below)

enter image description here

Here comes the problem:
When the page is rendered the @SessionScoped bean caches the data in the session, but when new data is inserted, using the @RequestScoped bean,the data goes to the data base but the datatable does not display the new entered values, because are not in the session.

So what should i do?
Here i will show you the two beans:

THE CREATE BEAN

@Named("subjectControllerCreate")
@RequestScoped
public class SubjectControllerCreate implements Serializable {

    private Subject currentSubject;
    @EJB
    private SubjectFacade ejbFacade;

    //INITIALIZATION
    public SubjectControllerCreate() {
        currentSubject = new Subject();
    }


    //CREATE


       public String create() {
            try {         
                    currentSubject.setCreationDate(new Date());
                    getSubjectFacade().create(currentSubject);//Adds the current subject to the database!
                    JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("SubjectCreated"));
                    return "";//Can perform a redirect here if we want
                //}
                //return null;
            } catch (Exception e) {
                JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
                return null;
            }
        }

THE UPDATE BEAN

@Named("subjectControllerUpdate")
@SessionScoped
public class SubjectControllerUpdate implements Serializable {

    //Using DataModel<Subject> instead of List<Subject> is necessary in order to be able to get the current row.
    private DataModel<Subject> subjects;    
    @EJB
    private SubjectFacade ejbFacade;

    //INITIALIZATION   
    @PostConstruct
    public void init() {
       subjects = new ListDataModel<Subject>(getSubjectFacade().findAll());
    }

    //RETRIEVE
    public DataModel<Subject> retrieve() {
        return subjects;
    }

    //UPDATE
    public void update() {
        getSubjectFacade().edit(subjects.getRowData());
    }

    //HELP METHODS
    //RETURN THE FACADE FOR DATA MANIPULATION(Best practice)
    private SubjectFacade getSubjectFacade() {
        return ejbFacade;
    }

    //GETTERS AND SETTERS
    public DataModel<Subject> getSubjects() {
        return subjects;
    }

    public void setSubjects(DataModel<Subject> subjects) {
        this.subjects = subjects;
    }        
}

Is it maybe possible to make the data table send some ajax request when detects that the Create dialog closes, to get the rest of the newly entered data?
If yes how could i do it?

This is the markup for my datatable:

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

    <h:form>
        <p:dataTable id="allSubjects" var="subject" value="#{subjectControllerUpdate.subjects}" paginator="true" rows="7" >
            <p:ajax event="rowEdit" listener="#{subjectControllerUpdate.update()}"/>
            <p:column headerText="Name" sortBy="#{subject.name}" style="width:200px" >
                <p:cellEditor>  
                    <f:facet name="output">  
                        <h:outputText value="#{subject.name}"/>  
                    </f:facet>  
                    <f:facet name="input">  
                        <p:inputText value="#{subject.name}" style="width:100%"/>  
                    </f:facet>  
                </p:cellEditor>  
            </p:column>

            <p:column sortBy="#{subject.description}" headerText="Description">               
                <p:cellEditor>  
                    <f:facet name="output">  
                        <h:outputText value="#{subject.description}"/>  
                    </f:facet>  
                    <f:facet name="input">  
                        <p:inputText value="#{subject.description}" style="width:100%"/>  
                    </f:facet>  
                </p:cellEditor>    
            </p:column>

            <p:column sortBy="#{subject.credits}" headerText="Credits" style="width:50px">
                <p:cellEditor>  
                    <f:facet name="output">  
                        <h:outputText value="#{subject.credits}"/>  
                    </f:facet>  
                    <f:facet name="input">  
                        <p:inputText value="#{subject.credits}" style="width:100%"/>  
                    </f:facet>  
                </p:cellEditor>
            </p:column>

            <p:column headerText="Options" style="width:50px">                   
                <p:rowEditor />
            </p:column>         
        </p:dataTable>
    </h:form>    

</html>

Ill appreciate your help

  • 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-29T19:37:04+00:00Added an answer on May 29, 2026 at 7:37 pm

    Can’t you just inject the @SessionScoped bean into the @RequestScoped bean and when create is clicked, call a method refresh in the @SessionScoped bean?

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

Sidebar

Related Questions

with the following routes I try to achive the goal, that I can present
Goal: Create Photomosaics programmatically using .NET and C#. Main reason I'd like to do
My goal here is to create a very simple template language. At the moment,
my goal is to write a stored proc that can collect all field values
The goal: To create a .NET dll i can reference from inside SQL Server
What would be best practice to handle removal of db row that has FK
My goal is to handle the Unicode characters present in the file name, such
I know this question has been posed several times, but my goal is slightly
I got a bunch of data in a database. The goal is to present
I have a query. I am developing a site that has a search engine.

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.