Topic
1 reply Latest Post - ‏2012-12-19T14:59:24Z by Mark_Winton
SystemAdmin
SystemAdmin
6420 Posts
ACCEPTED ANSWER

Pinned topic jsf updating a null value in the database

‏2012-12-16T03:46:53Z |
i tried to update the database but null values were updated. I think the problem
is from the form inputs

below is the form fields and the bean class
CODE

<h:body>
<h:form id="formdel">

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

<h:inputText value="#{data.empId}" />
</h:column>

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

<h:inputText value="#{data.empName}" />
</h:column>

<h:column>
<f:facet name="header">
Emp Department
</f:facet>
<h:inputText value="#{data.empDepartment}" />

</h:column>

<h:column>
<h:commandButton value="Update" action="#{updatebean.upd(data.empId)}" />
</h:column>

</h:dataTable>
</h:form>
</h:body>

[/CODE]
CODE
@ManagedBean(name="updatebean")
@RequestScoped
public class Updatebean {

private long empID;
private String empname;
private String empdepartment;
public long getEmpID() {
return empID;
}
public void setEmpID(long empID) {
this.empID = empID;
}
public String getEmpName() {
return empname;
}
public void setEmpName(String empname) {
this.empname = empname;
}
public String getEmpDepartment() {
return empdepartment;
}
public void setEmpDepartment(String empdepartment) {
this.empdepartment = empdepartment;
}

public String upd(long empID)
{

int k = 0;
try
{

connections goes here

String sql = "UPDATE employee SET empname='"empname"',empdepartment='"empdepartment"' where empid='"empID"'";

ps= con.prepareStatement(sql);

k = ps.executeUpdate();
System.out.println("RecorD updated Successfully");
}
catch(Exception e)
{
System.out.println(e);
}
[/CODE]
Updated on 2012-12-19T14:59:24Z at 2012-12-19T14:59:24Z by Mark_Winton
  • Mark_Winton
    Mark_Winton
    2 Posts
    ACCEPTED ANSWER

    Re: jsf updating a null value in the database

    ‏2012-12-19T14:59:24Z  in response to SystemAdmin
    Your form's fields (including the submit button's action paramter) are trying to use the values like "#{data.empId}"; seeing as there's no indication of what the "data" object is - and given that the Updatebean class has the right values (although you may want to check the cases being used for your variable names - shouldn't your form be using values like "#{updatebean.empId}" instead?