1

In a f:attribute I use to calculate the value, but I see it is calculated only when it is called.
I need to specify the value using variable consumed during the visualization, so if it asks for the value not during the production of the component where the f:attribute refer, the value will be not correct.
I hope correctly specify my problem. How can I force the evaluation of attribute value?

Thanks if someone answer me!
The xhtml is:

<rich:scrollableDataTable
        value="#{myBean.getScrollData(frm,sez)}"
        var="eachRow"
        rows="20"
    >
<rich:columns value="#{sez.getElements()}" var="info"
            index="index" sortable="false"
            >
<h:inputText id="txtf#{info.getId()}" value="#{eachRow.data[info]}"
    valueChangeListener="#{myBean.handle}"
    >
    <f:attribute name="xxx" value="#{eachRow.getId()}"/>
</h:inputText>
</rich:columns>
</rich:scrollableDataTable>  

the myBean java is:

public void handle(ValueChangeEvent e){
    Object value = e.getNewValue();
    if ((value==null || value.equals("")) && e.getOldValue()==null) return;
    String xxx = e.getComponent().getAttributes().get("xxx").toString();
    System.out.println("handle("+xxx+","+value+")");
}  

the ScrollData java is:

private String id="";
public String getId(){ return id;}  

id is a property of ScrollData read from DB.

I see the xxx value is inspected only during post, so the eachRow is positioned on the last record of the table... and it's wrong.
This mechanism goes ok when not used in DataTable and I see the getId() method is called during the creation of the page (it's correct).

Giant2
  • 461
  • 1
  • 4
  • 15
  • For example in a richtable eachrow have the same controller but using the f:attribute with the value of the key (for each row) it is possible to identify correctly the row and data (in handler and other things). – Giant2 Jun 01 '12 at 11:10
  • Post the code detailing exactly what you want, otherwise the question is unclear – Óscar López Jun 01 '12 at 11:17
  • @ÓscarLópez I posted the code. Any idea? I'm believing of a bug of rich:scrollDataTable – Giant2 Jun 04 '12 at 07:37

1 Answers1

0

This is expected behaviour. The <f:attribute> is a taghandler which is tied to its single parent UIComponent and processed during view build time. Effectively, when the JSF UI components are to be parsed based on XHTML markup, all taghandlers are evaluated and applied. In your case, the JSF component tree contains only one <h:inputText> component which is reused during every row iteration during the view render time. The <f:attribute> is not re-evaluated during the view render time. So it holds still only the value which was available during the view build time, i.e. it contains null.

There are several ways to achieve the functional requirement anyway, one of them is to just evaluate #{eachRow} programmatically by Application#evaluateExpressionGet() in the value change listener method.

public void handle(ValueChangeEvent e) {
    FacesContext context = FacesContext.getCurrentInstance();
    EachRow eachRow = context.getApplication().evaluateExpressionGet(context, "#{eachRow}", EachRow.class);
    // ...
}

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks @BalusC but it doesn't work. Even the approach you suggest me return the last row and not the correct row. I try to change a value on the 3rd row and the handle was called; so I see in the debug eachRow value and see the record is of the last row (the 4th), exactly the same I obtained before. – Giant2 Jun 05 '12 at 07:34
  • That'll be a RichFaces specific issue. It works with standard JSF datatable and the PrimeFaces one. – BalusC Jun 05 '12 at 11:18
  • Solved! The problem was on TableModel I used. It position at the end of data everytime. – Giant2 Jun 05 '12 at 12:55