2

I'm working on a project using spring hibernate struts2 framework and MySQL database, I have a problem when I wanted to add a field of type Date does not work, it means when I try to insert a Date field, it sends me this error:

WARNING: Error setting value
ognl.MethodFailedException: Method "setDATE_PANNE" failed for object model.Panne @ 1d055e2 [java.lang.NoSuchMethodException: setDATE_PANNE ([Ljava.lang.String;)]

/ - Encapsulated exception ------------ \
java.lang.NoSuchMethodException: setDATE_PANNE ([Ljava.lang.String;)

NB: (DATE_PANNE -> this is the date fields) and setDATE_PANNE is the setter for this attribute. DATE_PANNE is of type date

apparently the problem is that struts2 has taken my Date as a String thing that he should not do.

I do not know how to convert and where?

10
  • 2
    Show code. Do you have a setter for the date? What are you sending for a date? Only String[] come from the request, struts2 not finding a suitable setter will display that error. If it could find a setter with the appropriate name, "setDATE_PANNE" is a pretty bad name btw... which takes a date then it would try to convert the String to a Date, it's nice like that. Commented May 22, 2013 at 2:42
  • At the very least the html parameter data and the action class. Commented May 22, 2013 at 4:19
  • Show us code and an example of how you write that Date. Struts usually converts automatically from String to Date if it detects the format (MM-dd-yyyy for example) Commented May 22, 2013 at 6:39
  • Date doesn't work, it's a true. Commented May 22, 2013 at 9:50
  • that's my code : my table in database mysql id_panne int(11) id_equipement int(11) description_panne text cause_probable text etat_panne text date_panne date defaillance text effet text moyen_detection text remarque text Commented May 22, 2013 at 21:12

1 Answer 1

2

I have recently been working with struts 2 and have run into this ognl Exception a few times. It seems to happen when you have a control on a JSP, such as an input checkbox named "checkBox", and a method from your controller (java class, not JSP) similarly named "setCheckBox()". Somehow, behind the scenes, struts 2 or Ognl is generating a naming conflict and is unable to execute the correct method. Simply renaming either the control on the JSP (from my example from "checkBox" to "checkBox1") or renaming the method from the controller should solve your issue. Let me know if I did not elaborate enough. Hope this helps.

Regards,

Nick

Sign up to request clarification or add additional context in comments.

1 Comment

thank you for your reply, I converted the date before inserting with this function : DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); date_panne = formatter.parse(this.date_panne1); panne.setDate_panne(date_panne); and it works NB :date_panne1 is the field in jsp .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.