1

I am trying to create a modal to send user-selected requests to an email address; however, I am having trouble getting the user-selected requests. I keep getting the null value passed through fooBean.setSelected(id).


Versions:

  • BootsFaces: 1.3.0
  • Java: 1.8.0
  • JSF: 2.0
  • Browser: Internet Explorer 11.2x

MCVE of thisThing.xhtml:

<b:dataTable value="#{fooBean.newRequests}"
    var="foo"
    onselect="ajax:fooBean.setSelected(id)"
    ondeselect="ajax:fooBean.setSelected(id)"
    selectedItems="row"
    selection-mode="multiple"
    selectedRows="#{foo.selected}"
    saveState="false">

    <b:dataTableColumn label="Select">
        <b:selectBooleanCheckbox value="#{foo.selected}" />
    </b:dataTableColumn>

    <b:dataTableColumn label="Status" value="#{foo.status}" />

    <b:dataTableColumn label="Request Number"
        value="#{foo.requestNumber}"
        data-type="string" />

    <b:dataTableColumn label="ID" value="#{foo.id}" />

    <b:dataTableColumn value="#{foo.storeName}"
        label="Store Name" />
</b:dataTable>

MCVE of fooBean.java:

@ManagedBean(name="fooBean")
@ViewScoped
public class fooBean extends BeanBase implements Serializable {
    
    private List<FooRecord> fooRecords = new ArrayList<FooRecord>();
    private List<FooRecord> selectedFooRecords = new ArrayList<FooRecord>();
    
    // ...
    
    public void setSelected(String requestId) {
        // This is not how I really do it, but it gives an idea
        // with what I intend to do.
        this.fooRecords.stream().filter(...).toggleSelection();
        this.selectedFooRecords.stream().filter(...).toggleSelection();
    }
}

Update:

I found out that I had the method called as getSelect instead of getSelected, so I fixed it and that part is done. I just remembered the real issue which is why a null parameter is being passed instead of the requestId. When I debug through the fooBean.getSelected(String requestId), it shows null being passed through as parameter. I have even tried:

<!-- Using varName.property -->
onselect="ajax:fooBean.setSelected(foo.id)"

<!-- Using just the property name -->
onselect="ajax:fooBean.setSelected(id)"

<!-- Using the loop variable -->
onselect="ajax:fooBean.setSelected(foo)"

Update 2:

Fired function with null parameter

How do I pass foo.id to the function?

Community
  • 1
  • 1
Sometowngeek
  • 597
  • 1
  • 6
  • 27

1 Answers1

0

There are only three parameters you can pass to the bean method:

  • The loop variable. In your example, that's foo. This parameter only works if the attribute selected-items is set to rows. Caveat: if you activate column or cell select mode, this parameter is still passed to the server, and it seems to be valid. Only that every attribute of this object is null.
  • typeOfSelection. This is either "row", "column" or "item". It determines what the user has selected. That, in turn, is determined by the attribute selected-items, so you hardly ever have to use this parameter. Just omit it from the parameter list.
  • indexes tells the JSF bean which rows, columns or cells have been selected. Note that in the first two cases this is either an individual number or - if multiple items have been selected - a comma separated list. If you've set selected-items="cell", indexes is a comma-separated list of objects containing the row and column index.

I suppose indexes or foo is the most useful parameter in your case.

Final remark: we'd like to add more flexibility, but this requires much more understanding of the internal API of JSF than even we have. Truth to tell, I'm not even sure we can pass arbitrary bean values without modifying the JSF engine itself. If anybody knows how to do that, please leave a message at our bug tracker.

Update: Maybe the problem is caused by the modal. The modal is rendered at load time, but shown later, when the user has selected a row. Thing is, the modal isn't re-rendered automatically unless you add the content of the modal to the update attribute.

Stephan Rauh
  • 3,069
  • 2
  • 18
  • 37
  • Don't hesitate to reach out if you run into problems (webmast1 at beyondjava dot de). Otherwise, feel free to upvote my answer. :) – Stephan Rauh Dec 12 '18 at 22:42
  • I tried passing through the loop variable itself and I still got `null` passed back. :-\ – Sometowngeek Dec 21 '18 at 20:47
  • Maybe a better question would be: **I would like `fooBean` to store the selected rows so I can use it to send the collection via email.** The bonus question would be **How can I have the user click a button to select/deselect all?** I kind of feel the answer is plain obvious, but I have been having hard time getting it through my head lately. – Sometowngeek Dec 27 '18 at 19:32
  • I'd email you, but I can't send emails to external parties at work (although I can post non-sensitive MCVE on here... kind of ironic). – Sometowngeek Dec 27 '18 at 19:33
  • I assumed you'd already opened a bug ticker on our bug tracker. The question was similar. Scroll to the end of [this discussion](https://github.com/TheCoder4eu/BootsFaces-OSP/issues/1049) to find a solution. Hope it helps! – Stephan Rauh Dec 27 '18 at 20:11
  • I'll try the workaround. And no... My handle on github is [Sometowngeek](https://github.com/sometowngeek) :) – Sometowngeek Dec 28 '18 at 16:58
  • Calling the server-side function via onselect="ajax:fooBean.function(foo)" fires the function, but it still sends null in. I am using IE 11.2.x. Encouraging users to use an alternative browser is not an option for my employer. In other words, the suggested solution doesn't seem to work. Just added the snapshot to the question. – Sometowngeek Dec 31 '18 at 16:40
  • If you want, I can post it as an issue on Github. I just posted it here in case anyone else might know how how to fix this. – Sometowngeek Dec 31 '18 at 16:41
  • Oops - your trying to pass the value to a modal? In this case, you probably have to update the modal after the AJAX request. You know, the modal is rendered at load time. At this time, the user hasn't selected the row yet. -- If that still doesn't help, yes, please open an issue. So we can discuss at GitHub at length and simply offer the solution at StackOverflow. – Stephan Rauh Dec 31 '18 at 21:19
  • It looks like this is the same issue I am having... [Github - BootsFaces - Issue #878](https://github.com/TheCoder4eu/BootsFaces-OSP/issues/878). I will post another comment in that issue. If you prefer, I can open a new one. – Sometowngeek Jan 01 '19 at 03:34