Why using ValueExpression.setValue?

UI Components for JSF
Post Reply
Babas007
Posts: 251
Joined: 24 May 2011, 09:42

10 Jul 2017, 15:22

Hi,

I was wondering why sometimes in PF code, we do something like this:

Code: Select all

	ValueExpression selectionVE = this.getValueExpression("selection");

        if(selectionVE != null) {
            selectionVE.setValue(context.getELContext(), this.getLocalSelection());

            this.setSelection(null);
        }
Here is my situation, I have a composite containing a datatable with a selection attribute. In case, selection attribute is not set, it leads to an exception:
java.lang.NullPointerException:

javax.faces.component.UIComponentBase$AttributesMap.put(UIComponentBase.java:2479)
javax.faces.component.UIComponentBase$AttributesMap.put(UIComponentBase.java:2336)
com.sun.faces.el.CompositeComponentAttributesELResolver$ExpressionEvalMap.put(CompositeComponentAttributesELResolver.java:415)
com.sun.faces.el.CompositeComponentAttributesELResolver$ExpressionEvalMap.put(CompositeComponentAttributesELResolver.java:331)
javax.el.MapELResolver.setValue(MapELResolver.java:84)
com.sun.faces.el.DemuxCompositeELResolver._setValue(DemuxCompositeELResolver.java:255)
com.sun.faces.el.DemuxCompositeELResolver.setValue(DemuxCompositeELResolver.java:281)
org.apache.el.parser.AstValue.setValue(AstValue.java:202)
org.apache.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:257)
com.sun.faces.facelets.el.ContextualCompositeValueExpression.setValue(ContextualCompositeValueExpression.java:172)
com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
org.primefaces.component.datatable.DataTable.processUpdates(DataTable.java:780)
javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291)
javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291)
javax.faces.component.UIForm.processUpdates(UIForm.java:281)
javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291)
org.primefaces.component.panel.Panel.processUpdates(Panel.java:306)
The behavior is already strange to me, it use MapElResolver to set value of selection... I just want to make there is a good reason of using ValueExpression.setValue?

Thanks for your help

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

10 Jul 2017, 15:31

To set the selection to the bean.
Not sure whats wrong in your case.
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

Babas007
Posts: 251
Joined: 24 May 2011, 09:42

10 Jul 2017, 16:29

I think I see what's going on, the problem is in Datatable.processUpdates:

Code: Select all

@Override
    public void processUpdates(FacesContext context) {
        super.processUpdates(context);

        ValueExpression selectionVE = this.getValueExpression("selection");

        if(selectionVE != null) {
            selectionVE.setValue(context.getELContext(), this.getLocalSelection());

            this.setSelection(null);
        }
 }
In my case, selectionVE is not null as it is defined in a composite and equals "#{cc.attrs.selection}", I guess, should be:

Code: Select all

@Override
    public void processUpdates(FacesContext context) {
        super.processUpdates(context);

        if (isSelectionEnabled()) {
            ValueExpression selectionVE = this.getValueExpression("selection");
            selectionVE.setValue(context.getELContext(), this.getLocalSelection());

            this.setSelection(null);
        }
 }

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

10 Jul 2017, 16:32

Makes sense. Would be great if you could provide a Issue+PR. It's a simple fix.
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

Babas007
Posts: 251
Joined: 24 May 2011, 09:42

11 Jul 2017, 10:52

I will, I'll make some test before though

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 26 guests