0

I managed to create very simple example of sending Object between JSF pages:

First page:

@Named
@ViewScoped
public class Pricing
{

    public Pricing()
    {
        int ww = 3;

        PricingFormData obj = new PricingFormData(334, "Lalalala");


        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("yourKey", obj);
    }

Second page:

@Named
@ViewScoped
public class PricingCalculator implements Serializable
{
    PricingFormData get;

    public PricingCalculator()
    {
        get = (PricingFormData) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("yourKey");
    }
}

Custom Object:

public class PricingFormData
{
    private int id;
    private String name;

    public PricingFormData(int id, String name)
    {
        this.id = id;
        this.name = name;
    }

    public int getId()
    {
        return id;
    }

    public void setId(int id)
    {
        this.id = id;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

}

This code works but I have several questions which I want to ask:

The code is working in View scope. What will happen if multiple users are clicking on the pages? Are these Objects are going to be mixed? Do I need to use some unique ID for Object key for example session ID. But here I don't have session.

What will happen if the Objects are too many(multiple users are working on the web site)? When the objects will be disposed?

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
Peter Penzov
  • 7,110
  • 86
  • 300
  • 595
  • I think this is the answer you actually need: http://stackoverflow.com/q/25694423 – BalusC Aug 12 '15 at 12:12
  • I see that you attempted something in your previous question: http://stackoverflow.com/questions/31951545/passing-hashmap-between-viewscoped-beans-via-a-redirect This is clearly a duplicate of above. Now you know the right approach, what do you want to do with the current question? – BalusC Aug 12 '15 at 12:24
  • Just to confirm that custom objects are not going to mix when multiple users click on the pages. – Peter Penzov Aug 12 '15 at 12:58
  • @BalusC I found on Google how to use Flash with _@RequestScoped bean. Can I use flash with ViewScope? http://jugojava.blogspot.com/2011/06/jsf2-flash-scope-example.html – Peter Penzov Aug 12 '15 at 13:06
  • Just click the duplicate link and read its answer? – BalusC Aug 12 '15 at 13:08
  • @BalusC one additional question. Can I use Flash for 3 pages? In every page I need to modify the custom object. Did you tested it? – Peter Penzov Aug 12 '15 at 14:43
  • Your question in its current form didn't cover that fact. Why should I test it? – BalusC Aug 12 '15 at 14:47
  • Do you know what will be the result? – Peter Penzov Aug 12 '15 at 14:52
  • Yes. If you want to know it too based on pure theory, carefully read http://stackoverflow.com/q/7031885 – BalusC Aug 12 '15 at 14:58

0 Answers0