I need to display components and data dynamically. Below code I am trying to populate list of select boxes. Trying to populate values from var within forEach.
<c:forEach items="${bean.dynamicParamsBean.editableComoBoxes}" var="editableComboBox">
<h:selectOneMenu value="#{editableComboBox.param}">
<f:selectItems value="#{editableComboBox.dataProvider}" />
</h:selectOneMenu>
</c:forEach>
This works fine except f:selectItems where my select box is not populating any data. editableComboBox.dataProvider returns list of SelectItem objects.
This exact code works fine if I don't use loop and in turn var, directly populating select box values by referencing to bean.
Is there any workaround and alternative to resolve this issue?
Related
I am currently having a minor problem with the rendered attribute of column in my dataTable using PrimeFaces 4.0. I have a column in my table which should not always be displayed, so I used its rendered attribute and fetching the value from my backing bean. This is the 6th and last column. The dataTable is inside a p:dialog which will be shown at the end of the method.
The rendered attribute seems to work correctly because when showColumn is false, the column will not be shown and vice versa, but there's an issue. As seen in the image, the "No records found." message can't seem to reach until the last column. When I try to remove the rendered attribute, or manually set it to true (not using the backing bean value), the "No records found." message will reach until the last column as expected.
The entire dialog/form containing these elements seem to be updated correctly after the ajax request.
Backing Bean method:
public void getStatus(final MyClass foo, boolean showColumn) {
updateForm(foo);
setShowColumn(showColumn);
RequestContext.getCurrentInstance().execute("dailyStatus.show();");
}
Column Portion in xhtml:
<p:column headerText="Problematic Column" styleClass="tablecenter" rendered="#{myMBean.showColumn}">
<p:commandLink id="view"
action="#{myMBean.doSomething}" update="#form"
rendered="#{obj.status.equals('FAILED')? 'true' : 'false'}"
onclick="spin_start()" oncomplete="spin_stop()">
<h:graphicImage name="images/restart.png" styleClass="icon" />
</p:commandLink>
</p:column>
As Displayed on the Table:
For PrimeFaces 4.0 there is a 'solution' where I resorted to a hack-ish fix to the problem using jQuery. For recent PrimeFaces versions this is already fixed
When the dynamic column needs to be displayed, I use flags in my backing bean then call this method. (and the list for the datatable should be null or empty, as mentioned in the issue)
RequestContext.getCurrentInstance().execute("$('[id=\"myForm:myDataTable\"] tr.ui-widget-content td').attr('colspan', 6);");
This forces the single td's colspan on the row after the header row to reach up to the last header column. Hope this helps others that encounter this issue in the future!
When I use just plain h:dataTable:
<h:dataTable var="office"
value="#{reportController.data}" width="100%"
id="titleRpt" styleClass="data" border="1" cellpadding="2"
columnClasses="none,rightAlign,rightAlign,rightAlign,rightAlign,rightAlign,rightAlign,rightAlign"
headerClass="tableHeader"
rowClasses="oddRow,evenRow"
cellspacing="0" rendered="#{reportController.doDisplay and reportController.reportType eq 'T'}">
I get the following output:
However, once I change h:dataTable to p:dataTable (same code except for the p), I get the following:
How do I get PrimeFaces to automatically set the column widths based on the data within (which is dynamic and retrieved from the DB)? I am using the smoothness theme.
The reason I have to go with the PrimeFaces version and not the plain JSF one is because I need to have data export functionality and p:dataExporter requires that it be nested inside a p:dataTable and not an h one.
I am using primefaces 3.5
I have a p:selectonemenu in one of the column in datatable. and also I have a submit button on another column of same datatable. When I do a submit the row will get removed.
Here when I am selecting 'Other' then do a submit action and updating the form, the p:selectonemenu items in other rows is getting 'other' as first value. What is way to set 'other' to last value everytime
<p:column headerText="Buyer Response" style="white-space:pre-line;">
<p:selectOneMenu value="#{buyerInProcessBean.subject}"
id="buyerResponseId" >
<f:selectItems
value="#{buyerInProcessBean.subjectMap[trans.decisionrule.ruleId]}"
var="subject" itemLabel="#{subject}" itemValue="#{subject}"></f:selectItems>
<f:selectItem itemLabel="Other" itemValue="Other" ></f:selectItem>
</p:selectOneMenu>
</p:column>
Since you have
<p:selectOneMenu value="#{buyerInProcessBean.subject}">
The subject is shared between all rows, of course, other select menus will have the same value as the one selected (other in your case). For that, I suggest a simple fix, you have to move the subject attribute to the objects you are iterating on.
Another fix, is to set the subject attribute to "Other" once your method executed on submit is finished. But with this, even the changed selectmenu will lose "Other" as value.
So in conclusion, you have to change your logic, so that subject won't be shared between rows
I am using rich faces data table tag in my jsf:
<r:dataTable id="dataTable" var="user" preserveDataModel="false"
value="#{ListUsersManagedBean.users}" rows="10"
rowId="#{user.firstName}" rowKeyVar="index"
width="500" style="float:centre" reRender="ds" columnClasses="center">
Here i have configured rowsize as 10 in static way.I want to give the user a dropdown in the table so he can select number of rows 100,200,300,400 etc below the column.How can i do this.Or any better solution?
Thanks
You can do that by binding a variable to rows like rows = #{yourBean.noOfRows} and same to the combo box, and reRender your datatable onChange of comboBox.
This can be done if you are strict to use <rich:dataTable> or you can use jQuery datatable easy to integrate and easy to use for the functionality you need.
<h:dataTable width="100%" border="1" cellspacing="0"
cellpadding="2" style="border-collapse:collapse;display:block"
styleClass="Header" value="#{adminBean.displayResults}"
var="aResult" binding="#{adminBean.browseResultsHTMLDataTable}">
This is what i am trying to do. I have a dynamic list of data, which i try to display in the HTML Table format using h:dataTable (the bounded value is an arrayList). The table has got a radio button for each row it displays (boolean w/ h:selectOneRadio ) now when i select the radio button in one of these rows, i want to get the values of the row that is selected for which i try to use binding attribute. But i get Row Unavailable exception - is my approach wrong? any suggestions?
Selecting rows by radio button in a datatable is a tricky task since the radio buttons aren't grouped. Long story short: Select row by radio button.
I think you can use <t:selectOneRadio> with layout="spread" and then <t:radio> on each row.