How can i transfer a column value to my managed bean? - jsf

I am using a datatable in JSF:
<h:dataTable var="dataItem" value="#{operationsBean.creneauxMedecin}" border="1">
<f:facet name="header">
<h:outputText value="Rendez-vous de #{operationsBean.medecin.titre} #{operationsBean.medecin.prenom} #{operationsBean.medecin.nom} le #{operationsBean.txtJour}"></h:outputText>
</f:facet>
<h:column>
<f:facet name="header">
<h:outputText value="Créneau horaire"></h:outputText>
</f:facet>
<h:outputText id="id" value="#{dataItem.hdebut}h#{dataItem.mdebut}-#{dataItem.hfin}h#{dataItem.mfin}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Client"/>
</f:facet>
<h:outputText value="#{operationsBean.clt }"/>
</h:column>
</h:dataTable>
Please how can i transfer a column's(((dataItem.id))) value to my managed bean ?
N.B dataItem is a datatable row that contains(id,version,hdebut,mdebut....)

You have to implement an action listener method in your managed bean and call that via a command link and pass a param as part of the tag, if you google you can see many examples.
<h:commandLink value="click me" actionListener="#{managedbean.actionListenerMethod}">
<f:param name="paramInternalId" value="#{dataTableIter.id}" />
</h:commandLink>
http://docs.oracle.com/javaee/5/tutorial/doc/bnaqd.html#bnaqj

Related

JSF Datatable duplication header

I'm new of JSF, i'm trying to create a datatable but have a problem with this!
This is my code:
JSF file (Datatable):
<h:form>
<h:dataTable value="#{hsinfo.tableContent}" var="o"
styleClass="table"
headerClass="table-header"
rowClasses="table-odd-row,table-even-row">
<h:column>
<f:facet name="header">SBD</f:facet>
<h:outputText value="#{o.sbd}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">Họ Tên</f:facet>
<h:outputText value = "#{o.ten}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">Ngày Sinh</f:facet>
<h:outputText value = "#{o.ngaysinh}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">Giới Tính</f:facet>
<h:outputText value = "#{o.gioitinh}"></h:outputText>
</h:column>
</h:dataTable>
</h:form>
I don't know why if i just use #{o.sbd}, the code have error, but if i use <h:outputText value="#{o.sbd}">, the header row is not appeared and the column name duplicated each row like this :

Implementing colorpicker in jsf

I am using richfaces but it lacks colorpicker componenet. I found colorpicker in standbox
release of richfaces but I am unable to use it. How do I use it? Are there any other alternative colorpicker component?
<rich:dataTable id="addeditdtable"
value="#{Lecontroller.LeType.LeList}" var="Le" >
<rich:column>
<f:facet name="header">
<h:outputText value="Upper Range"/>
</f:facet>
<h:inputText value="#{Le.upperrange}"/>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="Color"/>
</f:facet>
<h:inputText class="makemecolorpicker" value="#{Le.color}"/>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="ADD/Delete"/>
</f:facet>
<a4j:commandLink value="Add"
actionListener="#{Lecontroller.addLeDTO()}"
render="Leform:addeditdtable"/>
<h:outputText value=" / "/>
<a4j:commandLink value="Delete"
actionListener="#{Lecontroller.removeLeDTO(Le)}"
render="Leform:addeditdtable"/>
</rich:column>
</rich:dataTable>
This is rich datatable or jsf datatable with dynamic row addition. One of the column represents colorpicker where I should be able to pick a colour and save it.

Why <h:dataTable> make all rows as same as "selected row" value?

I've ArrayList Collection carry the values properly , but the problem when i rendered it in h:dataTable tag the rows become all same value like in the picture.
<h:dataTable value="#{contactController.contacts }" var="contact"
rowClasses="oddRow, evenRow" styleClass="contactTable"
headerClass="headerTable" columnClasses="normal,centered"
rendered="#{not empty contactController.contacts }">
<h:column>
<f:facet name="header">
<h:column>
<h:outputText value="Name" />
</h:column>
</f:facet>
<h:outputText
value="#{contactController.contact.firstName }#{ contactController.contact.secondName }" />
</h:column>
<h:column>
<f:facet name="header">
<h:column>
<h:outputText value="Action" />
</h:column>
</f:facet>
<h:panelGrid columns="2">
<h:commandLink value="remove"
action="#{contactController.remove }">
<f:setPropertyActionListener value="#{contact }"
target="#{contactController.selectedContact }" />
</h:commandLink>
<h:commandLink value="edit" action="#{contactController.read}">
<f:setPropertyActionListener value="#{contact }"
target="#{contactController.selectedContact }" />
</h:commandLink>
</h:panelGrid>
</h:column>
</h:dataTable>
Any suggestion? .
I think there are two problems with your code.
First you don't need the bean's name in your columns. Simply use the content of the var attribute (in your case "contact" and not "contactController.contact")
Second: The h:column inside f:facet is not correct. Put the h:outputText directly into f:facet.
Change your first column this way:
<h:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{contact.firstName} #{contact.secondName }" />
</h:column>

Null Pointer exception while getting request parameters

<h:dataTable id="dt1" value="#{StudentMark.stuList}" var="stuList" bgcolor="#9AC8E6" border="10" cellpadding="5" cellspacing="3" rows="18" width="120%" dir="LTR" frame="hsides>
<h:column>
<f:facet name="header">
<h:outputText style=""value="Student Number" />
</f:facet>
<h:outputText style="" value="#{stuList.stuNumber}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Date"/>
</f:facet>
<h:outputText value="#{stuList.date}">
<f:convertDateTime type="date" pattern="dd-MM-yyyy"/></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Name"/>
</f:facet>
<h:outputText value="#{stuList.stuName}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Division"/>
</f:facet>
<h:outputText value="#{stuList.division}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Annual Marks"/>
</f:facet>
<h:outputText value="#{stuList.annualMark}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Student History"/>
</f:facet>
<h:form>
<h:commandButton id = "historyBtn" value="Student History" action="#{stuBean.showHistory}">
<f:param name="sNumber" value="#{stuBean.stuNumber}" />
<f:param name="sName" value="#{stuBean.stuName}" />
</h:commandButton></h:form>
</h:column>
</h:dataTable>
When i try to get the parameters passed using
FacesContext context = FacesContext.getCurrentInstance();
Map requestMap = context.getExternalContext().getRequestParameterMap();
String studentNum = (String) requestMap.get("sNumber");
String studentName = (String) requestMap.get("sName");
its showing "null" in studentName and studentNum thereby resulting with a null pointer exception.
Any ideas to resolve this???
I've resolved my issue.
The mistake made was I've trying to pass the parameters at the page load itself,tried making the param value as value="#{stuList.stuNumber}" and got the error resolved.
<h:form>
<h:commandLink id = "historyBtn" value="Student History" action="#{stuBean.showHistory}">
<f:param name="sNumber" value="#{stuList.stuNumber}" />
<f:param name="sName" value="#{stuList.stuName}" />
</h:commandLink></h:form>
Thanks for all the professionals for their time.
You are mixing POST and GET requests. h:form and h:commandbutton are for POST requests. f:param is for GET requests. If you want a GET request use h:button or h:link
For a quick overview of GET support look here it also explains how you can bind the parameter to a bean without having to go to the request parameter map.
I think f:param works only in h:commandLink and h:outputLink but not in h:commandButton.

JSF - Pagination implementation using Tomahawk

I am trying to implement Pagination in JSF using Tomahawk. When the page is loaded, the table in the first page is populated with data. But, when I click on Next or Prev the table is empty. I don't see any javascript error in the browser. Following is the code from the jsp. Please let me know if I am missing something:
<t:dataTable id="tableid" value="#{SiteSearchCriteria.siteList}"
var="item" border="1" rows="5" rowIndexVar="rowIndex"
rowClasses="trobg1,trobg2">
<h:column>
<f:facet name="header">
<h:outputText value="siteName"></h:outputText>
</f:facet>
<h:outputLabel value="#{item.siteName}"></h:outputLabel>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="siteCLLI"></h:outputText>
</f:facet>
<h:outputLabel value="#{item.siteCLLI}"></h:outputLabel>
</h:column>
</t:dataTable>
<t:dataScroller id="dataScrollerId" for="tableid" fastStep="10"
pageIndexVar="pageIndex" renderFacetsIfSinglePage="true"
pageCountVar="pageCount" paginator="true" paginatorMaxPages="9"
immediate="true">
<f:facet name="first">
<t:outputText value="First"></t:outputText>
</f:facet>
<f:facet name="last">
<t:outputText value="Last"></t:outputText>
</f:facet>
<f:facet name="previous">
<t:outputText value="Previous"></t:outputText>
</f:facet>
<f:facet name="next">
<t:outputText value="Next"></t:outputText>
</f:facet>
</t:dataScroller>
The backing bean that I was using was in "request" scope. Hence, the data was not visible when I clicked on "Next". Changed the scope of backing bean to "Session" and things started to work.

Resources