commandLink action call failes in ui:repeat compinent - jsf-2

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?

Related

Grails - g:field reset and html reset won't clear form/params/session

Using Grails 3.0.9
Making a Clear Form/session button for the filter class. however nothing i do works.
The button is just stuck there, nothing happens
Any help will be appreciated
SupplyController
def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
if (params.name)
session.name = params.name
else if (request.method != "POST")
params.name = session.name
else
session.name = null
def criteria = Supply.createCriteria()
def query = {
and{
if (params.name) {
like ("name", '%' + params.name + '%')
}
}
}
def results = criteria.list(params, query)
respond results, model:[supplyCount: results.getTotalCount()]
}
G:field type of code
<div class="filter">
<h3>Filter:</h3>
<g:form action="index" method="post" >
<label for='name'>Name:</label>
<input type="text" id="name" name="name" value="${session.name}"/><br/>
<span class="button">
<g:submitButton name="index" class="index" value="Apply Filter" /></span>
<g:field type="reset" name="myReset" value="Reset" />
</g:form>
</div>
HTML tag type
<div class="filter">
<h3>Filter:</h3>
<g:form action="index" method="post" >
<label for='name'>Name:</label>
<input type="text" id="name" name="name" value="${session.name}"/><br/>
<span class="button">
<g:submitButton name="index" class="index" value="Apply Filter" /></span>
<input type='reset' value='Reset' />
</g:form>
</div>
An HTML form reset button for a form rests the form to the initial state. In this case back to the values it had when the form loaded. A HTML form reset button does not CLEAR the form or CLEAR the session.
wondering why you are using session for where typicalls form params should be used? In order to clear HTML session you would need to trigger a call back to the originating controller just like you would to post but when it receives via this call. It does a session.invalidate() and then renders same view again. You should try to stick with params for forms. The fact that you have the session information already really no need to post it via a form. Your controller receiving the form would be aware of that same session value.
You could easily create a jquery functionality that you do with a button that triggers and a resetform. jQuery/Javascript function to clear all the fields of a form
Or if that does not work you could try for example in your case:
<g:form ..>
..
<button onClick="clearName();" name="clickme">
</g:form>
<g:javascript>
function clearName() {
$('#name').val();
}
</g:javascript>

jsf 2 commandlink not working from datatable

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?

Can't route my input parameters to my controller action method

I'm having trouble passing my textbox data to a controllers action parameters.
I'm trying to get the url to look like:
http://localhost:51124/gifts?searchTerm=test
but when I enter in text into the text box I get a url that looks like:
http://localhost:51124/gifts
Here is the code I have for the route:
routes.MapRoute("Gifts",
"gifts",
new { controller = "Gifts", action = "Search" });
here is the code for the page with the text box and button to submit the text box data:
<form method="GET">
<input type="search" name="searchTerm"/>
<input type="button" value="Search By Category" onclick="location.href='#Url.Action("Search", "Gifts")'" />
</form>
here is the code for the controller that I'm trying to pass data to unsuccessfully:
public ActionResult Search(string searchTerm = null)
{
var model = db.Gifts.ToList();
return View(model);
}
"searchTerm" never gets any parameter that I pass into the text box. It's always null.
Create a form element in you view with an input (i.e. the search box) that has a name attribute matching the parameter and a submit button.
#using (Html.BeginForm("Search", "Gifts") {
<input type='text' name='searchTerm' value='' />
<input type='submit' value='search' />
}
This will post back to the Search method in the Gifts controller, passing the vale of the search box to the parameter 'searchTerm'
you have to build this with jquery. add a class to the inputs to use as a selector
<input type="search" name="searchTerm" class="txtSearch" />
<input type="button" value="Search By Category" class="btnSearch" />
then in your script
$('.btnSearch').on('click', function(){
var url = '#Url.Action("Search", "Gifts", new { searchTerm = "----" })'.replace("----", $('.txtSearch').val());
window.location(url);
});

How to display only rendered rows and hide other in ui:repeat

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);
}
}

JSF 2.0 with Richface 4.0 not rerendering component

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.

Resources