开发者

JSF Rich scroallable Datatable Issue

In a scrollable datatable, which displays a collection of objects , I have to add one manual row as first row. That row contains inputText, through which user can able to enter some values and while hitting enter, those values will save and displays in bottom rows. I couldnt able to add this manual row as first 开发者_运维问答row. Below is the current code.

<rich:scrollableDataTable value="{resultList}" var="result">
<rich:column>
 <f:facet name="header">Name</f:facet>
<h:outputText value="#{result.name}" />
</rich:column>
<rich:column>
 <f:facet name="header">Category</f:facet>
<h:outputText value="#{result.category}" />
</rich:column>
</rich:scrollableDataTable>

The above code is for just displaying the values from the backend.

JSF Rich scroallable Datatable Issue


1) For that you have to use bind rich:scrollableDataTable with the instance of HtmlScrollableDataTable in the backing bean.

In backing bean, create instance of it with accessor methods & then you can initialize it accordingly by adding the inputText components. Add actionListeners to these input components & then in listeners, you can add these inputText values as outputText to the table again as rows accordingly.

2) Else you can use inputText rather then outputText & disabling the subsequent rows other then 1st, so only data may get displayed - preventing input.

<rich:scrollableDataTable value="{resultList}" var="result">
<rich:column>
 <f:facet name="header">Name</f:facet>
<h:inputText value="#{result.name}" disabled ="#{!result.isFirstRow}"/>
</rich:column>
<rich:column>
 <f:facet name="header">Category</f:facet>
<h:inputText value="#{result.category}" disabled ="#{!result.isFirstRow}"/>
</rich:column>
</rich:scrollableDataTable>

Backing Bean :

//---

public void initialize(){

     resultList.add(new Result("", "", true)); // Setting 1st input row enabled
} 

public void inputListener(ActionEvent event){


     // appending object based on input to the resultList

     resultList.add(new Result(inputName, inputValue, false));

     // added a boolean field to identify rows added later & to make them enable/disable accordingly
}

//---

I am not familiar with Richfaces, but tried to achieve it, as I was doing it with IceFaces.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜