I need to display only selected rows in <ui:repeat> from search result. Here's my code:
<h:inputText value="#{user.lname}" required="false" class="defaultText1 c_8" title="Search by user"></h:inputText>
<h:commandButton id="submit" name="submit" action="#{user.retrieveMembersByName}" />
<ui:repeat id="dtable" var="u" value="#{user.getUserList()}" varStatus="status" rendered="#{not empty user.dataList}">
<li>
#{u.memberId}
<a href="#" >#{u.groupId}</a>
#{u.fname}
#{u.mname}
</li>
</ui:repeat>
Right now it's displaying all rows. If I put <ui:repeat value="#{user.dataList}">, it will show me only searched single row. However, I want to show all rows and only if I search then it should show single row. Or can I make the searched row highlighted?
Check for some condition and display an element with additional class to 'highlight' the result. If you want, change the other elements' class as well, i.e. to hide them.
The view:
<h:form>
<h:inputText value="#{userBean.userName}" required="true" />
<h:commandButton value="Search" action="#{userBean.search}" />
<ui:fragment rendered="#{not empty userBean.userList}">
<ul>
<ui:repeat value="#{userBean.userList}" var="user">
<li class="#{fn:contains(user.name, userBean.userName) ? 'highlight' : 'grayed'}">#{user.name}</li>
</ui:repeat>
</ul>
</ui:fragment>
</h:form>
This can be done with EL 2.2 method call with parameters as well, instead of using a JSTL function.
The bean:
#ManagedBean
#ViewScoped
public class UserBean implements Serializable {
private List<User> userList;//getter
private String userName;//getter+setter
public String search() {
//load data and handle exceptions, if needed, do business job
userList = userDAO.find(userName);
}
}
Related
I am facing problem, rendering a commanlink from within a datatable. Here is my code
<h:form class="form-horizontal" rendered="#{ticketStatusController.role eq 'Coordinator'}">
<h:dataTable value="#{taskListController.candidateUserTaskList}" var="thisTask1" id="list" cellspacing="0" rowClasses="odd, even" styleClass="table table-striped table-bordered">
<h:column><f:facet name="header">Name</f:facet><strong>#{thisTask1.name}</strong></h:column>
<h:column><f:facet name="header">Description</f:facet>#{thisTask1.description}</h:column>
<h:column><f:facet name="header">Actions</f:facet>
<h:commandLink value="complete" action="#{taskListController.getFormKey(task)}" class="btn btn-small" style="margin-left:10px" >
<f:param name="task" value="#{thisTask1}" />
</h:commandLink>
</h:column>
</h:dataTable>
</h:form>
The outputlink is calling a method name getFormkey, Here is the code:
#Named("taskListController")
#RequestScoped
public class TicketStatusController implements Serializable {
public String getFormKey(Task task) {
//buisness logic
}
}
The commandlink, upon clicking, not going to the method, instead it shows #. What could be wrong here?
I have such structure:
<p:treeTable value="#{cmpDocumentTree.root}" var="v" id="#{tableId}" selectionMode="single"
selection="#{cmpDocumentTree.selectedNode}">
<p:ajax event="expand" listener="#{cmpDocumentTree.onNodeExpand}" />
<p:ajax event="collapse" listener="#{cmpDocumentTree.onNodeCollapse}" />
<p:ajax event="select" listener="#{crudBean.edit(cmpDocumentTree.selectedNode.data)}"
update=":#{formDialogUpdate}" oncomplete="#{formDialog}.show()" />
<p:column headerText="Nazwa" sortBy="#{v.name}" style="min-width: 200px;">
<h:outputText value="#{v.name}" />
</p:column>
<p:column headerText="Pliki" width="300">
<ui:repeat var="_file1" value="#{v.files}">
<h:commandLink value="#{_file1.originalFilename}">
<p:fileDownload
value="#{fileDownloadController.getFile(_file1.originalFilename, _file1.storedFilename, _file1.contentType)}" />
</h:commandLink>
<br />
</ui:repeat>
</p:column>
</p:treeTable>
But - p:fileDownload doesn't work. The fileDownloadController.getFile(...) method is not fired at all.
When I put the same method inside p:dataTable, then it works perfectly.
EDIT:
v.files comes from ComDocument entity - it is relation one-to-many document-to-files.
#Entity
#Table(name = "com_documents", schema = "public")
#SequenceGenerator(name = "COM_DOCUMENTS_SEQ", sequenceName = "COM_DOCUMENTS_SEQ", allocationSize = 1)
public class ComDocument implements EntityInt, java.io.Serializable {
(...)
#OneToMany(fetch = FetchType.EAGER, mappedBy = "document", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ComDocumentFile> files;
public void setFiles(List<ComDocumentFile> files) {
this.files = files;
}
public List<ComDocumentFile> getFiles() {
return files;
}
Could you help me? Thanks.
I've never had any luck with the FileDownload working inside an ajax request. I have not bothered to dig into the source as it is never a show stopper (and it really doesn't make sense to use it as an ajax request--you're getting a complete file, not updating a page).
The simple solution here is to make sure that your command button has "ajax=false"
<p:commandLink value="#{_file1.originalFilename}" ajax="false">
<p:fileDownload
value="#{fileDownloadController.getFile(_file1.originalFilename, file1.storedFilename, _file1.contentType)}" />
</p:commandLink>
http://www.primefaces.org/showcase/ui/fileDownload.jsf
You'll notice all the examples have the ajax functionality disabled. If you're using h:commandButton for style I suggest using p:commandLink and styling it to be a button.
Best of luck, I'm pretty sure this will fix it. Also--make sure your "download objects" are final. You need to make sure that the data-source is referring to the same reference and not creating a new instance on each request.
I have an issue with radio button. i have a 2 set of radio buttons and one command button in a field set.Based on the selection of radio button, respected value will be displayed through ajax call. But issue is always the first button is gettting considred in the command button action, thats why always first values is getting displayed,however the second radio button is selected.Here is my code
//test.xhtml
<h:panelGroup id="demandDashBoardPanelGroupID">
<fieldset>
<legend style="font-family:Arial;font-size: 12px;">Demand Dashboard</legend>
<table>
<tr>
<td>
<h:selectOneRadio immediate="true" id="groupbyid" value="#{demandManagedBean.selectedRadioButton}" styleClass="labelstyle">
<f:selectItem itemLabel="Group By Creation Date Time" itemValue="1" />
<f:selectItem itemLabel="Group By Location" itemValue="2" />
</h:selectOneRadio>
</td>
<td>
<h:commandButton id="fetchbuttonID" value="Fetch"
style="font-size:13px;width:60px;height:25px;" action="#{demandManagedBean.displayDemandRequestsTable}">
<f:setPropertyActionListener target="#{demandManagedBean.selectedRadioButtonParam}" value="#{demandManagedBean.selectedRadioButton}"/>
<f:ajax render=":parentformid:demandrequestpanelgrpid" immediate="true"/>
</h:commandButton>
</td>
</tr>
</table>
</fieldset>
</h:panelGroup>
<h:panelGroup id="demandrequestpanelgrpid" rendered="#{demandManagedBean.renderedFieldSet}">
<fieldset id="demandrequestfieldsetid">
<legend style="font-family:Arial;font-size: 12px;">Demand Requests</legend>
<h:outputText rendered="#{demandManagedBean.renderCreationdateDmdtable}" value="first table"/>
<h:outputText rendered="#{demandManagedBean.renderDmdLocationTable}" value="second table"/>
</fieldset>
</h:panelGroup>
//backing bean action
public void displayDemandRequestsTable(){
if(selectedRadioButtonParam!= null && selectedRadioButtonParam.endsWith("1")){
renderCreationdateDmdtable = true;
renderDmdLocationTable = false;
}else if(selectedRadioButtonParam!= null && selectedRadioButtonParam.endsWith("2")){
renderCreationdateDmdtable = false;
renderDmdLocationTable = true;
}
renderedFieldSet = true;
}
You don't need the f:setPropertyActionListener here to get the selected value into your backing bean. Just add an execute attribute to your f:ajax tag and remove the immediate=true:
<h:commandButton ...>
<f:ajax render=":parentformid:demandrequestpanelgrpid" execute="#form" />
</h:commandButton>
You could also just give the id of the component to be executed instead of the whole form:
<h:commandButton ...>
<f:ajax render=":parentformid:demandrequestpanelgrpid" execute="groupbyid" />
</h:commandButton>
Also make sure that the selectedRadioButton is properly initialized in your backing bean and that the bean is at least in #ViewScoped.
UPDATE:
If you remove the f:setPropertyActionListener then the selectedRadioButtonParam will not be set. Then you need to check selectedRadioButton inside your action method instead.
I have this following piece of code:
<h:form id = "fm-rewDet">
<ui:repeat var="review" value="#{controller.reviewStatusList}">
<h:commandLink value = "TestLink" action = "#{controller.rewDetail}" />
</ui:repeat>
</h:form>
The controller contains the following:
public void rewDetail(){
System.out.println("I'M HERE");
}
The following HTML code is rendered:
<form id="fm-rewDet" enctype="application/x-www-form-urlencoded" action="/project/overview.xhtml" method="post" name="fm-rewDet">
<a onclick="mojarra.jsfcljs(document.getElementById('fm-rewDet'),{'fm-rewDet:j_idt224:0:j_idt255':'fm-rewDet:j_idt224:0:j_idt255'},'');return false" href="#">TestLink</a>
//...
</form>
This simple example does not work at all. When the link is pressed some action takes place but weirdly the I'M HERE message fails to appear.
What is the cause of this?
Do you have any idea why this part of code isn't working:
View:
<a4j:commandButton value="#{labels.comments}"
action="#{reservation.displayComments}"
render="dataComments" />
<h:panelGroup id="dataComments" rendered="#{reservation.showComments}" >
...
<h:panelGroup/>
Bean:
public String displayComments(){
showComments = !showComments;
return "";
}
Click on the link simply do nothing.
Try something like this:
<a4j:commandButton value="#{labels.comments}"
action="#{reservation.displayComments}"
render="dataComments" />
<h:panelGroup id="dataComments">
<h:panelGroup id="innerPanel" rendered="#{reservation.showComments}" >
...
<h:panelGroup/>
<h:panelGroup/>
Always show your dataComments element, unless you will have nothing on the page to refresh.