-
1. Re: Problem with validation and entityHome
matt.drees Jan 12, 2008 10:34 AM (in response to fjgarmu)s:validateAll only checks field-level validation, not class-level validation, which includes @AssertFalse.
Currently, the simplest way (IMO) to validate multiple fields is to put some logic in your action method. The booking example does this with regards to checkin and checkout dates, IIRC. -
2. Re: Problem with validation and entityHome
fjgarmu Jan 19, 2008 1:00 PM (in response to fjgarmu)Thanks for ur reply matt.drees.
I try writing a new method mysave in ReportsHome:public String mysave(){ if (this.getInstance().getRadiologos().getId()==0 && this.getInstance().getReportstatus().getId()>=4){ this.addFacesMessage("ERROR"); return "error"; }else{ super.update(); return null; } }
In the JSF page the method is called by a <s:button><s:button id="mysave" value="mysave" action="#{reportsHome.mysave}" view="/Reports.xhtml" rendered="#{reportsHome.managed}"/>
The behaviour is: the values are saved even when the ERROR message is raised and the application goes to "Reports.xhtml" page, even when the parameters aren't valid and the super.update method is not called.
Why?
How could I do it for don't save it when the values are not correct?
Thanks in advance. -
3. Re: Problem with validation and entityHome
matt.drees Jan 19, 2008 2:07 PM (in response to fjgarmu)By default, changes made to managed objects are flushed upon transaction completion, even if an update() is never manually called.
You probably want to use manual flush mode. It's in the docs.
There are also other posts about it. -
4. Re: Problem with validation and entityHome
fjgarmu Jan 19, 2008 2:56 PM (in response to fjgarmu)thanks for your quick reply.
I try it putting in the ReportsEdit.page.xml<begin-conversation join="true" flush-mode="MANUAL"/>
But the behavior is the same.
Is it ok?
Thanks -
5. Re: Problem with validation and entityHome
matt.drees Jan 19, 2008 3:12 PM (in response to fjgarmu)Oh, maybe I misunderstood the situation.
Did you appropriately change the page.xml file? (ReportsHome.page.xml, iirc)
Post what you have. -
6. Re: Problem with validation and entityHome
fjgarmu Jan 19, 2008 5:29 PM (in response to fjgarmu)Ok.
I have:
-JSF page: ReportsEdit.xhtml with a button<s:button id="mysave" value="mysave" action="#{reportsHome.mysave}" view="/Reports.xhtml" rendered="#{reportsHome.managed}"/>
-page xml: ReportsEdit.page.xml<!DOCTYPE page PUBLIC "-//JBoss/Seam Pages Configuration DTD 1.2//EN" "http://jboss.com/products/seam/pages-1.2.dtd"> <page no-conversation-view-id="/ReportsList.xhtml" login-required="true"> <begin-conversation join="true" flush-mode="MANUAL"/> <action execute="#{reportsHome.wire}"/> <param name="reportsFrom"/> <param name="reportsStudyuid" value="#{reportsHome.reportsStudyuid}"/> <param name="patientsFrom"/> <param name="patientsId" value="#{patientsHome.patientsId}"/> <param name="radiologosFrom"/> <param name="radiologosId" value="#{radiologosHome.radiologosId}"/> <param name="reportstatusFrom"/> <param name="reportstatusId" value="#{reportstatusHome.reportstatusId}"/> <navigation from-action="#{reportsHome.persist}"> <end-conversation/> <redirect view-id="/Reports.xhtml"/> </navigation> <navigation from-action="#{reportsHome.update}"> <end-conversation/> <redirect view-id="/Reports.xhtml"/> </navigation> <navigation from-action="#{reportsHome.remove}"> <end-conversation/> <redirect view-id="/PatientsQR.xhtml"/> </navigation> </page>
-Action .java: ReportsHome.javapublic String mysave(){ if (this.getInstance().getRadiologos().getId()==0 && this.getInstance().getReportstatus().getId()>=4){ this.addFacesMessage("ERROR"); return "error"; }else{ super.update(); return null; } }
That's all.
Thanks for ur help. -
7. Re: Problem with validation and entityHome
matt.drees Jan 20, 2008 12:03 AM (in response to fjgarmu)"fjgarmu" wrote:
<s:button id="mysave" value="mysave" action="#{reportsHome.mysave}" view="/Reports.xhtml" rendered="#{reportsHome.managed}"/>
I think there a couple problems here; I should have noticed them earlier.
For one thing, do you really want an s:button? Usually for "save" kind of controls, you want an h:commandButton, because you want to submit some data, not just trigger an action.
If you do in fact want an s:button, you shouldn't specify both "action" and "view". (I think.) In this case, you want the action, but not the view attribute.
Also, you'll need a navigation rule in your ReportsEdit.page.xml for your "mysave" action that goes to the ReportsList page if the outcome isn't "error".
(Note that the typical JSF pattern, contrary to your design, is to return null if you want to stay on the same page and a string like "success" if you want to move away. So you may consider doing that instead.) -
8. Re: Problem with validation and entityHome
fjgarmu Jan 20, 2008 4:10 AM (in response to fjgarmu)Thanks for ur answer.
I' ve changed the <s:button> by <h:commandButton> and in the page.xml I ve written a navigation rule:<navigation from-action="#{reportsHome.mysave}"> <rule if-outcome="success"> <end-conversation/> <redirect view-id="/Reports.xhtml"/> </rule> </navigation>
It works fine.
Thanks a lot.