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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:32:10+00:00 2026-06-09T06:32:10+00:00

I am doing this in JSF 2.0. I have implemented add and view pages

  • 0

I am doing this in JSF 2.0. I have implemented add and view pages with same controller. I don’t know if it’s best practise to use same controller, is it? As in this example it uses single page for all add,edit, view but I have different pages. So when migrating from view page to edit page I want to preserve value but I can’t. How to preserve value between different pages in same controller? The output consoles shows the value of edit changes from true to false which I change to true in editLegendType function.

@ManagedBean
@ViewScoped
public class LegendController implements Serializable {

    LegendDTO legendDTO = new LegendDTO();
    String selectedLegend;
boolean edit;

public LegendController() {
      Logger.getLogger(LegendController.class.getName()).warning("The size of list" + edit);
    if (!edit) {
        legendDTO.getList().add(new Legend());
        Logger.getLogger(LegendController.class.getName()).warning("The size of list" + legendDTO.getList().size());
    }
}


//All function from here is to legend edit
public String editLegendType(LegendDTO dto) {
    edit = true;
    legendDTO = dto;
        Logger.getLogger(LegendController.class.getName()).warning("The size of list" + edit);
        return "addLegend";//from view page to addPage for edit.
    }
}
  • 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-06-09T06:32:11+00:00Added an answer on June 9, 2026 at 6:32 am

    Using the same controller for multiple Views is OK IMHO, if it prevents code duplication and the usability is improved by using separate views.

    Unfortunately, you cannot continue using the View scope. There are several alternatives though. You could either use the new custom Conversation scope, or fall back to Session scope. Both have pros and cons – with the conversation scope you will have to do the scope handling yourself. With the Session scope, you may unnecessarily put too much data in the session.

    So if I had to choose, I would rather use the conversation scope over session scope as the more tedious but more clean solution.

    EDIT: Please note that the conversation scope is not a JSF feature, it comes from CDI, meaning that you would have to change the annotation on your bean from @ManagedBean to @Named

    EDIT2: To use CDI on tomcat, you need to have it in your classpath. If you are using maven, add this to your .pom, otherwide, download and use the jar “manually”.

    <dependency>
      <groupId>org.jboss.weld.servlet</groupId>
       <artifactId>weld-servlet</artifactId>
       <version>1.1.9-Final</version>
    </dependency>
    

    Additionally, you would have to add this to your web.xml:

    <listener>
       <listener-class>
          org.jboss.weld.environment.servlet.Listener
       </listener-class>
    </listener>
    

    You may also need an empty beans.xml. Im not sure about that though.

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

Sidebar

Related Questions

I have trouble doing this... You may want to get the same result as
I'm doing this interface where I have a lot of buttons that are just
I have a JSF converter that I use for a SelectItem list containing several
Its been quite some time since i have started developing web pages using JSF
I have 2 jsf pages, each of them have a managed bean. I'm navigating
I've found various examples in jsf where folks have done this successfully; in these
I'm doing a JSF 2.0 application on Tomcat 6.x. I have a resource bundle
Am using JSF 1.2 . I have a servlet. When this servlet is hit,
Im doing this project where i need to download files through a webservice (images,
I am interested in doing this C code in Java: // sets n's ith

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.