• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jsf error in <h:commandlink>

 
nisu pathak
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ,i am implementing code of edit/update row of datatable in jsf .i am posting code .please help me as early as possible due to dead lines

package org.demo;

import java.util.ArrayList;
import java.util.Arrays;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name="order")
@SessionScoped

public class OrderBean
{
private int pid;
private String name;
private int price;
boolean editable;

public OrderBean() { }
public OrderBean(int pid,String name,int price)
{
this.pid=pid;
this.name=name;
this.price=price;


}


public boolean isEditable() {
return editable;
}
public void setEditable(boolean editable) {
this.editable = editable;
}

public int getPid() {
return pid;
}
public void setPid(int pid) {
this.pid = pid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}







private static final ArrayList<OrderBean> orderList =new ArrayList<OrderBean>(Arrays.asList(

new OrderBean(101,"Rice",1100),
new OrderBean(102,"oil",1400),
new OrderBean(103,"a",1000),
new OrderBean(104,"b",600),
new OrderBean(105,"c",700)
));

public ArrayList<OrderBean> getOrderList() {

return orderList;

}

public String addAction()
{

OrderBean order = new OrderBean(this.pid, this.name,
this.price);

orderList.add(order);

return null;


}

public String saveAction() {

//get all existing value but set "editable" to false
for (OrderBean order : orderList){
order.setEditable(false);
}
//return to current page
return null;

}
public String deleteAction(OrderBean order) {

orderList.remove(order);
return null;
}

public String editAction(OrderBean order)
{

//order.setEditable(true);
order.setEditable(true);

return null;
}


}


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<ui:composition template="/WEB-INF/templates/template.xhtml">
<ui:param name="title" value="Applicant System" />

<ui:define name="header">
<h:graphicImage library="images" name="icefaces.png"/>
</ui:define>

<ui:define name="menu">
<h:button outcome="applicants" value="Listing Page" />
</ui:define>

<ui:define name="content">
<h:head>
<hutputStylesheet library="css" name="template.css" />


<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">



$(document).ready(function()
{
$('#output').click(function(event) {

alert("inside jquery");
$.ajax({
url: "data.jsf",
type: "POST",
data:{pid:$('#pid'),name:$('#name'),price:$('#price')},
dataType: "json",
success : function(data)
{
alert("inside success");
}
});
};

});
});

</script>


</h:head>
<h:form id="f1" prependId="false">
<h:messages globalOnly="true" />
<h:panelGroup id="table" layout="block" >
<table>


<tr>
<td>
<hutputLabel value="Product id :"></hutputLabel>
</td>

<td>
<h:inputText id="pid"
value="#{order.pid}"
required="true" >

</h:inputText>
</td>

</tr>

<tr>
<td>
<hutputLabel value="Product Name:"></hutputLabel>
</td>
<td>
<h:inputText id="name"
value="#{order.name}"
required="true" >

</h:inputText>
</td>

</tr>

<tr>
<td>
<hutputLabel value="Product Price:"></hutputLabel>
</td>

<td>
<h:inputText id="price"
value="#{order.price}"
required="true" >

</h:inputText>
</td>

</tr>
<tr>
<td>

<h:commandButton id="output" value="Add" action="#{order.addAction}"/>

</td>


</tr>
</table>



</h:panelGroup>

<h:dataTable value="#{order.orderList}" var="o"
styleClass="order-table"
headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row" border="2">

<h:column>

<f:facet name="header">Order No</f:facet>

<h:inputText value="#{o.pid}" size="10" rendered="#{o.editable}" />

<hutputText value="#{o.pid}" rendered="#{not o.editable}" />

</h:column>

<h:column>

<f:facet name="header">Product Name</f:facet>

<h:inputText value="#{o.name}" size="20" rendered="#{o.editable}" />

<hutputText value="#{o.name}" rendered="#{not o.editable}" />

</h:column>

<h:column>

<f:facet name="header">Price</f:facet>

<h:inputText value="#{o.price}" size="10" rendered="#{o.editable}" />

<hutputText value="#{o.price}" rendered="#{not o.editable}" />

</h:column>


<h:column>
<f:facet name="header">Action</f:facet>

<h:commandLink value="Edit" action="#{order.editAction(o)}"
rendered="#{not o.editable}" />


</h:column>

<h:column>

<f:facet name="header">Action</f:facet>

<h:commandLink value="Delete"
action="#{order.deleteAction(o)}" /> //Error on this line
Method must have signature "String method(), String method(), String method(String), String method(String,
String), String method(String, String, String), String method(String, String, String, String), String method(String,
String, String, String, String), String method(String, String, String, String, String, String), String method(String,
String, String, String, String, String, String), String method(String, String, String, String, String, String, String,
String), String method(String, String, String, String, String, String, String, String, String), String method(String,
String, String, String, String, String, String, String, String, String), String method(String, String, String, String,
String, String, String, String, String, String, String), String method(String, String, String, String, String, String,
String, String, String, String, String, String), String method(String, String, String, String, String, String, String,
String, String, String, String, String, String), String method(String, String, String, String, String, String, String,
String, String, String, String, String, String, String), String method(String, String, String, String, String, String,
String, String, String, String, String, String, String, String, String), String method(String, String, String, String,
String, String, String, String, String, String, String, String, String, String, String, String), String method(String,
String, String, String, String, String, String, String, String, String, String, String, String, String, String, String,
String), String method(String, String, String, String, String, String, String, String, String, String, String, String,
String, String, String, String, String, String), String method(String, String, String, String, String, String, String,
String, String, String, String, String, String, String, String, String, String, String, String)" but has signature "String
method(OrderBean)"

</h:column>


</h:dataTable>

<h:commandButton value="Save Changes" action="#{order.saveAction}" />

</h:form>
</ui:define>

</ui:composition>
</html>

 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags when posting code.

What EL version are you using?
 
Tim Holloway
Bartender
Posts: 18412
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code tags (use the "Code" button on our message editor UI) will make your sample code and XML easier for us to read. Also, remove any irrelevant code/data from your sample. When a sample won't fit on my screen, I tend not to give it as much attention.

Use of the "$" JQuery shorthand can lead to problems on JSF pages, since "$" is also an EL marker. Use the alternative "jQuery." form, instead.

Finally, EL is not intended to be used as a programming language. The form

is bad practice even when you are using valid parameters. Which you are not. The action attribute is supposed to be a reference to a backing bean method, and not a direct call to the method. Action methods are expected to get their parameters directly from the Model (backing bean), not from the View.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!