show details row's datatable - jsf

I've got a datatable in a .xhtml page, that shows products of a database.
Let's say that I can only see Name and Code for every row, how can I show more detail of the product in the same page?
Moreover, my product bean is in ViewScope, so i'm not able to show details in another .xhtml page (I've tried many times, but if in case you guys have a solution for this, that's good).
PS: I don't know anything about Javascript yet, so i'd prefer mostly solutions based on jsf and java :)

You mean that you want to display more fields at datatable?
Add more columns..
<h:dataTable value="#{pr.products}" var="p">
<h:column>
<f:facet name="header">Name</f:facet>
#{p.name}
</h:column>
<h:column>
<f:facet name="header">Code</f:facet>
#{p.code}
</h:column>
<h:column>
<f:facet name="header">Price</f:facet>
#{p.price}
</h:column>
........
</h:dataTable>
JSF example: http://www.mkyong.com/jsf2/jsf-2-datatable-example/
If you using primefaces see showcase: http://www.primefaces.org/showcase/ui/data/datatable/basic.xhtml
EDIT
If you want to make a dialog that shows the details of the selected product see at primefaces showcase the "selection" example.

Related

Setting the ID of an inputfield in dynamic columns Richfaces JSF-1.2 when not rendered

I've got dynamic columns. Some have Inputfields others don't.
Why do I have to set the Id of an Inputfield if I don't want to render it?
<rich:columns value="#{columnBean.columns}" var="column" index="ind" id="#{column.id}">
<f:facet name="header">
<h:inputText id="#{column.inputFilterId}" value="#{otherBean.filterValue[column.filterBy]}" onkeyup="filterKeyUp(event)" onclick="Event.stop(event);" />
</f:facet>
<h:outputText value="#{columnBean.lineItemHandler[line]}" rendered="#{columnBean.curCol[column.id]}"/>
</rich:columns>
I'm using JSF 1.2 and Richfaces 3.3.3 Final
I fixed it, just put a unique Id-Value from my Column Bean.
The better solution is to do this:
https://stackoverflow.com/a/18358949/5146922
THX BalusC

JSF 2: duplicate IDs inside p:dataList

i have a list of billable services per client and i'm trying to build a table where the user can select which ones shall actually be billed:
<p:dataList value="#{billController.billings}" var="billings">
<p:dataTable value='#{billings.billablesDataModel}' var='item' selection="#{billings.toBill}">
<f:facet name="header">
<h:outputText value="#{billings.client.id}" />
</f:facet>
[...]
</p:dataTable>
</p:dataList>
the problem is, that all the dataTables are rendered with the same ID attribute (j_idt9:j_idt13:0:j_idt14) which is automatically assigned by JSF. i'm suspecting this is causing that the selection doesn't work. (the backing bean billings.toBill is not updated/stays empty.)
i was trying to set the ID attribute of the dataTable manually like this:
<p:dataTable id="#{billings.client.id}" ...>
however, i get the following error:
java.lang.IllegalArgumentException: Empty id attribute is not allowed
(#{billings.client.id} is definitely set to the unique client's ID as i get the right output from an h:outputText for debug purposes.)
can you help me fixing this?
i'm using JSF Mojarra 2.1.1 and PrimeFaces 3.2 on a Tomcat 6.
You need to use p:column for content of datalist as documented in user's guide.
What if you loop over billController.billings via ui:repeat and not via p:dataList:
<ui:repeat var="billings" value="#{billController.billings}">
<p:dataTable value="#{billings.billablesDataModel}" var="item" selection="#{billings.toBill}">
[...]
</p:dataTable>
</ui:repeat>

JSF Datatable and SelectBooleanCheckBox

I have a scenario where I have to give an option to the user to select Applications and its related Profiles. The user should select at least one Application and One Profile and he can also select more than one. Each Application has its own Profiles and there can be multiple applications. My UserBean has a List of ApplicationVO and that ApplicationVO has isSelected (boolean), application id (int), application name(String) and Profile List. That Profile list has List of ProfileVO and ProfileVO has isSelected(boolean), profile id(int) and Profile name(String).
I am new to JSF and tried to use datatable and SelectBooleanCheckBox which works fine. But at this point I am not sure how to validate and display the error message in the same JSP with the remaining user entered data intact. Also I am not sure how to update the bean with the options checked/unchecked by the user.
When the user clicks Submit my validations should be:
At least one application should be selected
If an application is selected, at least one profile should be selected
Profile check boxes should be disabled until the application is selected
When the user unchecks the application check box, profiles check box should be disabled.
I have the following code. Please help me and can also suggest me if there are any other best way to accomplish the same.
<h:dataTable value="#{UserBean.applicationList}" var="appList">
<h:column>
<f:facet name="header">
<h:outputText value="Applications" />
</f:facet>
<h:selectBooleanCheckbox value="#{appList.isSelected}" label="#{appList.applicationName}"/>
<h:outputText value="#{appList.applicationName}" />
</h:column>
<h:column>
<f:facet name="header" >
<h:outputText value="Profiles" />
</f:facet>
<h:dataTable value="#{appList.profileList}" var="profileList">
<h:column>
<h:selectBooleanCheckbox value="#{profileList.isSelected}" />
<h:outputText value="#{profileList.profileName}" />
</h:column>
</h:dataTable>
</h:column>
</h:dataTable>
I was able to implement by validating in the bean and was able to get the selected values from the ApplicationList

JSF h:column tag not evaluating rendered attribute

I've got a JSF data table that conditionally displays each item based on a Boolean property of the item, as follows:
<h:dataTable value='#{sessionBean.items}' var='item'>
<h:column rendered='#{item.visible}'>
<h:outputText value='#{item.description}'/>
</h:column>
</h:dataTable>
My problem is that the rendered attribute does not seem to be referring to visible property in my item at all. I've put a tracing message in the getter for the property, and can confirm that the getter is not getting called at all. What really puzzles me though, is that the following works:
<h:dataTable value='#{sessionBean.items}' var='item'>
<h:column rendered='true'>
<h:outputText value='visible = #{item.visible}'/>
<h:outputText value='#{item.description}'/>
</h:column>
</h:dataTable>
That is, in this case all items are rendered, and the text "visible = true" or "visible = false" is successfully output for each. It is only in the column rendered attribute that the getter is not working.
Does anyone have any idea what might cause this behaviour, and what I should do to correct it?
Table columns (read: <td> elements which are all in the same column, which thus applies on all rows) cannot be rendered on a per-row basis. That's not really a JSF restriction, but more a HTML restriction. Ask yourself, how should the HTML end up to look like? What should the browser do with all those missing <td> elements on a per-row basis? Right, it makes no sense at all :)
Just move the row-based rendering to the cell contents:
<h:column>
<h:outputText value="#{item.description}" rendered="#{item.visible}"/>
</h:column>
Or make it a bean based rendering if you actually want to hide the whole column altogether:
<h:column rendered="#{sessionBean.visible}">
<h:outputText value="#{item.description}"/>
</h:column>

RichFaces rich:panel header not appearing

I specified this
<rich:panel>
<f:facet name="header">
Panel #1. Changing Style Synchronously
</f:facet>
Each component in the RichFaces has a pre-defined set of classes you can manipulate with. If defined, those
classes overwrite the ones come from the skin.
</rich:panel>
from the RichFaces demo, in my JSF page and no header appears, although I've nothing in my css which would interfere. What might be the reason for this?
Thanks
i dont see any problem with using f:facet
try
<f:facet name="header">
<div><h:graphicImage value="/images/search.png" />
<h:outputText value=" Action Logs Search" /></div>
</f:facet>
in order to regenerate the error you mentioned
Mine disappeared when I accidentally included the panel's facets in the panel form. The facets must be children of the modal panel:
<rich:panel>
<a4j:form> <!-- This is trouble! -->
<f:facet name="header">
Panel #1. Changing Style Synchronously
</f:facet>
Each component in the RichFaces has a pre-defined set of classes you can manipulate with. If defined, those
classes overwrite the ones come from the skin.
</a4j:form>
</rich:panel>
OK, do please feel free to comment on why the f:facet tag is not working, but I get my nice shiny headers when I change the code so it's like this instead:
<rich:panel header="header">
Each component in the RichFaces has a pre-defined set of classes you can manipulate with. If defined, those
classes overwrite the ones come from the skin.
</rich:panel>

Resources