JSF Pass option to another page

In JSF, how do you pass a parameter from one page to another without using managed beans?

eg.

<h:dataTable value="#{myObjects}" var="object">
<h:column>              
        <h:commandButton value="View Object" action="view-object"/>
</h:column>                                             
</h:dataTable>  

I want to pass an object, so the next page I can just do is # {object.displayValue}

thanks s.

+3
source share
1 answer

First of all, you cannot do this without using a managed bean.

The best approach would be to use DataModelas valuefor h:dataTable, so that you can get the currently selected String object DataModel#getRowData(). You only need to make sure that the bean saves the same model in a subsequent request. In other words, fill in the model in the bean constructor.

<h:form>
    <h:dataTable value="#{bean.model}" var="item">
        <h:column>              
            <h:commandButton value="View Object" action="#{bean.view}"/>
        </h:column>                                             
    </h:dataTable>
</h:form>

( ) bean, :

public class Bean {

    private DataModel model;
    private Item item;

    public Bean() {
        List<Item> list = new ArrayList<Item>();
        list.add(new Item(1, "value1"));
        list.add(new Item(2, "value2"));
        list.add(new Item(3, "value3"));
        model = new ListDataModel(list);
    }

    public String view() {
        item = (Item) model.getRowData();
        return "view";
    }

    public DataModel getModel() {
        return model;
    }

    public Item getItem() {
        return item;
    }

}

, JSF 1.x, 2.x, @ViewScoped bean .

:

<p>#{bean.item.value}</p>
+5

Source: https://habr.com/ru/post/1749307/


All Articles