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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:22:43+00:00 2026-05-26T11:22:43+00:00

I used to initialize certain properties of an entity object with pre-defined values as

  • 0

I used to initialize certain properties of an entity object with pre-defined values as early as its instantiation in a @PostConstruct method of a jsf managed bean (or even the managed bean’s constructor). I can no longer preserve this functionality when porting the project to Seam with the managed bean gone (wondering also how it would be in JSF 2.2 without managed beans).

The entity class:

@Entity
@Name("task") // this line in Seam version
public class Task implements Serializable {

    private Integer id;
    private String subject;
    private Date creationDate;
    private Date completionDate;
    private Category category;
    private User user;

    public Task() {
    }

    public Task(Date creationDate) {
        this.creationDate = creationDate;
        this.user = user;
    }

    // getters & setters, etc.
}

The JSF Managed Bean

public class TaskBean extends BaseBean {

    // Super class provides the logged in user object and a default category object

    private Task task = new Task(java.util.Calendar.getInstance().getTime(), this.user);

    @PostConstruct
    public void initTaskBean() {
        if (certainConditionMet) 
            task.setCategory(defaultCategory);
    }

    // Other managed bean business...
}

The JSF page

<h:form>
<h:panelGrid columns="2">
    Date: <h:outputText value="#{taskBean.task.creationDate}">
            <f:convertDateTime pattern="dd/MM/yyyy" />
           </h:outputText>
    User:  <h:outputText value="#{taskBean.task.user.name}" />
    Subject: <h:inputText value="#{taskBean.task.subject}" id="subjectField" />
    Category: <h:selectOneMenu value="#{taskBean.task.category}" id="catMenu">
                <f:selectItems value="#{taskBean.categories}" />
              </h:selectOneMenu>
    // remaining stuff
</h:panelGrid>
</h:form>

The Stateless Session Bean in Seam version also assuming the responsibility of the jsf managed bean

@Name("taskAction")
@Stateless
public class TaskAction implements TaskActionLocal {

    @PersistenceContext
    private EntityManager em;

    @In private FacesMessages facesMessages;
    @In User user;
    @In Category defaultCategory
    @Logger private Log log;

    @In
    // private Task task = new Task(java.util.Calendar.getInstance().getTime(), user)
    // the above didn't work so 
    private Task task; 

    @PostConstruct
    public void baslarken() {
        System.out.println("TaskAction PostConstructed");
        task = new task(java.util.Calendar.getInstance().getTime(), user);
        if (certainConditionMet) 
                task.setCategory(defaultCategory);

        // the above won't work either. Date and User always blank on the ui form
    }

    // other business methods, etc
}

Seam version of the form:

<h:form id="todo" styleClass="edit">
    <rich:panel>
        <f:facet name="header">Task To Do</f:facet>

        <s:decorate id="dateField" template="layout/edit.xhtml">
            <ui:define name="label">Date:</ui:define>
            <h:outputText value="#{task.creationDate}"/>
        </s:decorate>

        <s:decorate id="userField" template="layout/edit.xhtml">
            <ui:define name="label">User:</ui:define>
            <h:outputText value="#{task.user.name}"/>
        </s:decorate>

        <s:decorate id="subjectField" template="layout/edit.xhtml">
            <ui:define name="label">Başlık</ui:define>
            <h:inputText id="subject" required="true" value="#{task.subject}" >
            <a4j:support event="onblur" reRender="subjectField" bypassupdates="true" ajaxSingle="true" />
            </h:inputText>
        </s:decorate>

        <!-- other components, etc -->
    </rich:panel>
</h:form>

I need advice on how to make the task object to hold the date and logged in user data (and preferably a default category) pre-populated when instantiated.

  • 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-26T11:22:43+00:00Added an answer on May 26, 2026 at 11:22 am

    First im sorry but i cannot find a comment link on this answer?? ( so moderators feel free to move this post;) )

    Extending the entityhome class as a session bean should be possible yes. But if its the right thing to do i’m not sure. I would more likely create a new session bean that serves my purpose more exact.

    For the factory invocation. You will call this the same way from a jsf page as any other name. I.e. value=”#{createNewTask.id}”. Or you can inject it into another class. Take a look at the seam doc. Its really well written.

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

Sidebar

Related Questions

When {0} is used to initialize an object, what does it mean? I can't
I understand that Encoding can be used to initialize object to perform any type
I have a cellarray whose values are used to initialize corresponding structs. cellarr =
Do Nib files automatically initialize certain properties? In most objective-c code I've seen, you
memset is sometimes used to initialize data in a constructor like the example below.
More specifically, is List(T)(IEnumerable(T)) thread-safe if the IEnumerable used to initialize the list is
I used the LINQ to SQL designer in Visual Studio to create an object
I used to initialize my structures in this way: struct A a = {0};
It seems to me that there is a certain kind of method that we
I know that the compiler will sometimes initialize memory with certain patterns such as

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.