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?
Related
I am working on #ViewScoped annotation in JSF2.0. Below is the code what I had written. It is not working as I expected. Please review it and let me know if any changes are required to get the exact output that what am thinking of.
Here is my Controller SearchController.java
package com.s2tech.jsfapp.controllers;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import com.s2tech.jsfapp.helper.SearchHelper;
import com.s2tech.jsfapp.managedbean.SearchManagedBean;
#ManagedBean(name ="searchController")
#ViewScoped
public class SearchController implements Serializable{
public SearchController(){
private static final long serialVersionUID = 1L;
SearchHelper searchHelper;
private List<SearchManagedBean> employeeList=new ArrayList<SearchManagedBean>();
public List<SearchManagedBean> getEmployeeList() {
return employeeList;
}
public void setEmployeeList(List<SearchManagedBean> employeeList) {
this.employeeList = employeeList;
}
public void getEmployee(SearchManagedBean searchManagedBean) {
searchHelper=new SearchHelper();
employeeList = searchHelper.getEmployee(searchManagedBean);
//return "search.xhtml";
//return Constants.searchPage;
// return null;
}
Below is my view search.xhtml
<h:body style="background-color:skyblue;">
<ui:include src="mainMenu.xhtml"></ui:include>
<h:form prependId="false">
<table>
<tr style="display:block;margin-top:10px;width:100%;margin-left:40%">
<td style="width:40%">
<p:outputLabel for="firstName" value="First Name:" style="font-weight:bold" />
<p:inputText id="firstName" value="#{searchManagedBean.firstName}" required="true" requiredMessage="please enter First Name"> </p:inputText>
<p:message id="firstNameMsg" for="firstName" showDetail="true" ></p:message>
</td>
<td style="width: 20%"></td>
<td style="width:40%;">
<p:outputLabel for="lastName" value="Last Name:" style="font-weight:bold"/>
<p:inputText id="lastName" value="#{searchManagedBean.lastName}" required="true" requiredMessage="please enter Last Name" />
<p:message id="lastNameMsg" for="lastName" showDetail="true" ></p:message>
</td>
</tr>
<tr style="display:block;margin-top:10px;width:100%;margin-left:78%">
<td style="width:40%"> <p:commandButton value="Search" action="#{searchController.getEmployee(searchManagedBean)}" update="firstNameMsg lastNameMsg emailMsg phoneMsg dataTable"/></td>
</tr>
</table>
</h:form>
<p:dataTable id="dataTable" var="emp" rendered="#{not empty searchController.employeeList}" value="#{searchController.employeeList}" rowStyleClass="table table-striped table-hover table-bordered" resizableColumns="true" resizeMode="expand" scrollWidth="50%" scrollHeight="150" >
<p:column headerText="First Name">
<h:outputText value="#{emp.firstName}"/>
</p:column>
<p:column headerText="Last Name">
<h:outputText value="#{emp.lastName}"/>
</p:column>
<p:column headerText="Email">
<h:outputText value="#{emp.email}"/>
</p:column>
<p:column headerText="Phone">
<h:outputText value="#{emp.phone}"/>
</p:column>
<p:column headerText="Edit">
<p:commandLink value="Edit" action="#{searchController.getEditForm(emp)}" style="margin-left:40px;color:blue;"></p:commandLink>
</p:column>
</p:dataTable>
</h:body>
</html>
My question is that after entering first name and last name, when I click on submit button it need to hit controller's getEmployee() method and it needs to display data table values from controller's getEmployeeList(). Here eventhough using ViewScoped bean Iam not getting output. Any suggestions??
Hello I am using JSF and PrimeFaces 3.5 2.1.17, I have the code below:
<p:dataTable id="resultTable" var="entity" value="#{requerimentoBean.entitys}" >
<p:column style="width: 22px;">
<p:commandLink actionListener="#{requerimentoBean.prepareEdition(entity)}">
<h:graphicImage library="images" title="Editar" name="edit.png" style="border: none;" />
</p:commandLink>
</p:column>
</p:dataTable>
the problem occurs on this line:
<p:commandLink actionListener="#{requerimentoBean.prepareEdition(entity)}">
Error occurs when I place the entity parameter. the method can not prepareEdition is accessor.
public void prepareEdition(Requerimento entity){
System.out.println("***** Método preperaEdition ****");
System.out.println("***** ID: " + entity.getId() + "*****");
setEntity(logic.getById(entity.getId()));
}
if you can help thanks
This is how you pass objects
<p:commandLink
actionListener="#{requerimentoBean.prepareEdition()}">
<h:graphicImage library="images" title="Editar" name="edit.png"
style="border: none;" />
<f:setPropertyActionListener target="#{requerimentoBean.entityObj}"
value="#{entity}" />
</p:commandLink>
Replace actionListener with action like
<p:commandLink process="#this"
action="#{requerimentoBean.prepareEdition(entity)}">.
You actionListener binding method should have a signature like
public void method(ActionEvent event)
Hope this helps.
I am trying to replicate primefaces ajax dialog form as in Primefaces showcase
My JSF code snippet is as below
<h:body>
<p:commandButton id="showDialogButton" type="button" value="Show"
onclick="PF('dlg').show()" />
<p:dialog header="Enter FirstName" widgetVar="dlg" appendToBody="true"
resizable="false">
<h:form id="form">
<h:panelGrid columns="2" style="margin-bottom:10px">
<h:outputLabel for="firstName" value="firstName:" />
<p:inputText id="firstName" value="#{backingBean.firstName}" />
</h:panelGrid>
<p:commandButton id="submitButton" value="Submit" update=":display"
oncomplete="PF('dlg').hide();" />
</h:form>
</p:dialog>
<p:outputPanel id="display" style="display:block;margin-top:10px;">
<h:outputText id="name" value="Hello #{backingBean.firstName}"
rendered="#{not empty backingBean.firstName}" />
</p:outputPanel>
My managed bean
#ManagedBean
#ViewScoped
public class BackingBean implements Serializable{
private String firstName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
}
No dialog is getting displayed on clicking submit button :(. I have also included appendToBody="true" but no result.In ie i get javascript error as "Object Expected". Please help me out to solve this issue.
which version of primefaces you use ?
If you use Primefaces 3.5 or older:
<p:commandButton id="showDialogButton" type="button" value="Show"
onclick="dlg.show()" />
For Primefaces 4.0 :
<p:commandButton id="showDialogButton" type="button" value="Show"
onclick="PF('dlg').show()" />
In my case I had a script link to jquery in header. I droped it and primefaces started to work correctly
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);
}
}
Is it possible to update view parameter without redirecting the page? For instance
I have a managed bean which checks if an ID exist
public void signIn(){
Client c = clientFacade.loginDetail(client.getID());
if (c != null) {
loggedIn = true;
}
else{
loggedIn = false;
}
}
and a view which renders just fine if the ID exist.
<h:panelGroup rendered="#{not applicationManager.loggedIn}">
<p:commandLink value="Sign In" onclick="loginDialog.show()" styleClass="login-link"></p:commandLink>
</h:panelGroup>
<h:panelGroup rendered="#{applicationManager.loggedIn}">
<p:menuButton value="#{applicationManager.client.firstname}" />
</h:panelGroup>
<p:dialog widgetVar="loginDialog" >
<h:panelGrid columns="2" cellpadding="5">
ID : <p:inputText value="#{applicationManager.client.id}" />
<p:commandButton value="submit" action="#{applicationManager.signIn()}" update=":loginForm" />
</h:panelGrid>
</p:dialog>
Is it possible to insert the code below at the top of the view and still have an update on the url?
<f:metadata>
<f:viewParam name="input" value="#{applicationManager.client.id}" />
<f:event listener="#{applicationManager.signIn()}" type="preRenderView"/>
</f:metadata>
I tried it, but it's not working, so I guess I might be missing something or doing something wrong.