Treat bank error message when deleting registry.

Forum sobre a ferramenta Oracle JDeveloper, ADF, OAF, etc. (Não é destinado ao aprendeziado da Linguagem Java em geral)
Post Reply
Pedro_fvieira
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Posts: 13
Joined: Fri, 08 Aug 2008 10:17 am
Location: Vitoria - ES
Existem 11 tipos de pessoas no mundo: As que entendem binário, as que acham que entendem e as que não entendem.

Hello,

Well my name is Pedro and I'm starting to mess with ADF.
I already studied some things, I already made the tutorial the srdemo of Oracle, I did everything right and already gave to get some notions of how to work as ADF.
I have a good notion with OO.
Well I started my life in the ADF in a project that was already in progress not to say ending, the person in charge of the company and I end up left for me, I urgently need to correct 2 problems in this system.
I'll put one of the probes here and the other I'll put it on another topic in order to do something organized here in the forum.

1) When deleting a record, it may have the same dependence (FK) that need to be checked and if you hear a more friendly error message for the user, as the ADF default It is to show the bank's message, I tried to create a trigger on the bench but the message presented comes with some unnecessary things the user knows.
I already looked in the documentation, but I could not understand, if anyone can help me explain how to blame this validation and how the message is generated I thank you.

SDS,
Pedro Filipe
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D

Select all

 
try { 
      //delet 
} catch (DMLException e) { 
      throw JboExcpetion("msg Erro"); 
} 
Pedro_fvieira
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Posts: 13
Joined: Fri, 08 Aug 2008 10:17 am
Location: Vitoria - ES
Existem 11 tipos de pessoas no mundo: As que entendem binário, as que acham que entendem e as que não entendem.

Hi Vitor,
Let's say, I understood what you wanted to say ... but I already found it somewhere else talking about this but I can not use it, in the line

Select all

 
... 
{ 
throw new JboExcpetion("msg Erro"); 
} 

It gets in red, and does not have the option to import the class.
I have tried to put in the hand "import oracle.jbo.jboexception;" and also did not work ... the version of my jdev is 10.1.3.3.0 ...
for me to use this class I need to add some jar ??? which??

Another question, good the application I am stirring it was done like this ...
There is a class with the method to delete:

Select all

 
public class Util { 
    public Util() { 
    } 
   public void delete(ActionEvent event)  
    { 
        FacesContext fc = FacesContext.getCurrentInstance(); 
        DCBindingContainer bindings = (DCBindingContainer)fc.getApplication().createValueBinding("#{bindings}").getValue(fc); 
         
        bindings.getOperationBinding("Delete").execute(); 
        bindings.getOperationBinding("Commit").execute();                      
    } 
} 
Well you know I do not know why they did so, but I'm going to put Try / CACTT on this code and ... making the code like that.

Select all

 
public class Util { 
    public Util() { 
    } 
   public void delete(ActionEvent event)  
    { 
        FacesContext fc = FacesContext.getCurrentInstance(); 
        DCBindingContainer bindings = (DCBindingContainer)fc.getApplication().createValueBinding("#{bindings}").getValue(fc); 
         
        try { 
               bindings.getOperationBinding("Delete").execute(); 
               bindings.getOperationBinding("Commit").execute();      
        } catch (DMLException e) { 
              throw new JboExcpetion("msg Erro"); 
        }                     
    } 
} 

I wanted to know if there is a better place for if by this code Saca, I want to learn how to do the right way ... porque start already doing gambiarra It is tense ...

vlw !!!!
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D

With respect to red designer is only typing problem ... the right is:

Select all

 
import oracle.jbo.JboException; 
-----

like that. .. for everything ... rsrsrsrs

for this that you are doing ... I did not have to create this method there in your bean
just put it in the actionlitener of your

Select all

 
#{bindings.Delete.execute} 

Select all

 
#{bindings.Delete.execute} 
and if delete action is in the JSP Pagedefinition will work,
but it is not the best way to do this because you end up not having muito control of anything that way that you are doing ..

another way to do is the following ... MVC .. You have a method in Bean yes, where you will call the method that will actually delete the line of your vo, this method called should stay in the am that contains your vo used in your jsp ..

Select all

 
//exemplo de chamada de método no AM  
//parametro é o nome do metodo 
BindingContainer bindings = getBindings(); 
OperationBinding operationBinding = bindings.getOperationBinding("deleteRow"); 
if you need help We are there .. I created new topics because always can help you so I will do: D

Arm [/ Code]
Pedro_fvieira
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Posts: 13
Joined: Fri, 08 Aug 2008 10:17 am
Location: Vitoria - ES
Existem 11 tipos de pessoas no mundo: As que entendem binário, as que acham que entendem e as que não entendem.

Brother, type I know by putting

Select all

 
#{bindings.Delete.execute} 
In the actionListener will work, but DAE does not have a legal error handling.
type when I delete the delete in the actionlistener and soon after I do a commit, and if it depends on the bank I take an error similar to this:

Select all

 
JBO-26048: Constraint "SVH_SVR_FK" violated during post operation:"Delete" using SQL Statement "DELETE FROM SERVICE_REQUESTS ServiceRequest WHERE SVR_ID=?". 
ORA-02292: integrity constraint (SRDEMO.SVH_SVR_FK) violated - child record found  
sack, imagine a User reading this .... I wanted to show the user a more friendly message of the type

Select all

 
Esse registro não pode ser excluido pois ele possue uma dependência com xxxx 
I know in the bank I can leave the fk of the type in cascade but and when I erase the father he goes and erases the child and will not appear error message ... but this is something that I do not want to do ...
in fact for this particular case it should not allow removal when the record has Depicencies ...

So I have this problem ... and wanted to be able to solve it in the best way ... I'll open a new topic to discuss about the MVC ...
But by aqui I wanted to discuss more about this subject to erase a record and do the treatfully ... as the system is almost ready I wanted to do in a way that it works without I have to move a lot ...

Anything, some acronyms What do I put I do not understand ... tipow am, what is this ???
I'm still very young in this way of working ... I'm still stumbling on the stones ...: Oops:
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D

AM = APPLICATION MODULE
VO = View Object

Do you have a VO in your JSP ??
Is this going inside an am?

for me to help you with this you would have to post your codes there, the excerpts that involve your problem
Pedro_fvieira
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Posts: 13
Joined: Fri, 08 Aug 2008 10:17 am
Location: Vitoria - ES
Existem 11 tipos de pessoas no mundo: As que entendem binário, as que acham que entendem e as que não entendem.

good beleza then ...
next I'll send you the srdemo tutorial code that I did and it's working, and the list screen ... after completing the tutorial I inserted a button with the delete method In the page this is enough to generate the same problem I am having in the application, and from dae wanted to do this treatment of error messages:

my bean already sent it is only that ( CLASSUAL)

I'm sending you the code of my AM:

Select all

 
package oracle.srtutorial.datamodel; 
 
import oracle.jbo.Row; 
import oracle.jbo.Session; 
import oracle.jbo.server.ApplicationModuleImpl; 
import oracle.jbo.server.ViewLinkImpl; 
 
 
import oracle.jbo.server.ViewObjectImpl; 
 
import oracle.srtutorial.datamodel.common.SRPublicService; 
import oracle.srtutorial.datamodel.entities.ServiceRequestImpl; 
import oracle.jbo.domain.Number; 
// --------------------------------------------------------------------- 
// ---    File generated by Oracle ADF Business Components Design Time. 
// ---    Custom code may be added to this class. 
// ---    Warning: Do not modify method signatures of generated methods. 
// --------------------------------------------------------------------- 
public class SRPublicServiceImpl extends ApplicationModuleImpl implements SRPublicService { 
    /**This is the default constructor (do not remove) 
     */ 
    public SRPublicServiceImpl() { 
    } 
 
    /**Sample main for debugging Business Components code using the tester. 
     */ 
    public static void main(String[] args) { 
        launchTester("oracle.srtutorial.datamodel", /* package name */ 
      "SRPublicServiceLocal" /* Configuration Name */); 
    } 
 
    /**Container's getter for LoggedInUser 
     */ 
    public ViewObjectImpl getLoggedInUser() { 
        return (ViewObjectImpl)findViewObject("LoggedInUser"); 
    } 
 
    /**Container's getter for ServiceRequests 
     */ 
    public ViewObjectImpl getServiceRequests() { 
        return (ViewObjectImpl)findViewObject("ServiceRequests"); 
    } 
 
    /**Container's getter for RequestCreatedByUser1 
     */ 
    public ViewLinkImpl getRequestCreatedByUser1() { 
        return (ViewLinkImpl)findViewLink("RequestCreatedByUser1"); 
    } 
 
    protected void prepareSession(Session session) {    
        super.prepareSession(session);    
        String currentUser = "sking";   
        // Replace later with getUserPrincipalName()    
        getLoggedInUser().setNamedWhereClauseParam("TheCurrentUser",currentUser);  
        getLoggedInUser().executeQuery();  
        // Save the current user id in the session user data so entities can   
        // refer to it  
        getDBTransaction().getSession().getUserData().put("CurrentUserId",getLoggedInUser().first().getAttribute("UserId"));  
    } 
 
    /**Container's getter for ServiceRequestMain 
     */ 
    public ViewObjectImpl getServiceRequestMain() { 
        return (ViewObjectImpl)findViewObject("ServiceRequestMain"); 
    } 
 
    /**Container's getter for ServiceHistories 
     */ 
    public ViewObjectImpl getServiceHistories() { 
        return (ViewObjectImpl)findViewObject("ServiceHistories"); 
    } 
 
    /**Container's getter for HistoryLinesForRequest1 
     */ 
    public ViewLinkImpl getHistoryLinesForRequest1() { 
        return (ViewLinkImpl)findViewLink("HistoryLinesForRequest1"); 
    } 
     
    public void addNoteToServiceRequest(String noteText) {        
        Row newHistory = getServiceHistories().createRow();        
        getServiceHistories().last();        
        newHistory.setAttribute("Notes",noteText);        
        getDBTransaction().commit();  
    } 
 
    /**Container's getter for Globals 
     */ 
    public ViewObjectImpl getGlobals() { 
        return (ViewObjectImpl)findViewObject("Globals"); 
    } 
 
    /**Container's getter for ProductsList 
     */ 
    public ViewObjectImpl getProductsList() { 
        return (ViewObjectImpl)findViewObject("ProductsList"); 
    } 
     
    public void insureOneBlankRowInGlobals() {   
        getGlobals().clearCache();   
        getGlobals().insertRow(getGlobals().createRow());  
    } 
     
    public void createNewServiceRequestFromGlobals() {      
        ServiceRequestImpl sr = (ServiceRequestImpl)getDBTransaction().createEntityInstance(ServiceRequestImpl.getDefinitionObject(),null);      
        Row globalsRow = getGlobals().first();  
        sr.setProblemDescription((String)globalsRow.getAttribute("ProblemDescription"));      
        sr.setProdId((Number)globalsRow.getAttribute("ProductId"));      
        getDBTransaction().commit(); 
    } 
 
    /**Container's getter for StaffList 
     */ 
    public ViewObjectImpl getStaffList() { 
        return (ViewObjectImpl)findViewObject("StaffList"); 
    } 
 
    /**Container's getter for UserList 
     */ 
    public ViewObjectImpl getUserList() { 
        return (ViewObjectImpl)findViewObject("UserList"); 
    } 
     
    public void cancelEditsToCurrentServiceRequest() {  
        getServiceRequestMain().getCurrentRow().refresh(Row.REFRESH_WITH_DB_FORGET_CHANGES);  
    } 
 
    /**Container's getter for ServiceHistories1 
     */ 
    public ViewObjectImpl getServiceHistories1() { 
        return (ViewObjectImpl)findViewObject("ServiceHistories1"); 
    } 
} 
And now the code of my page definition of my JSP

Select all

 
<?xml version="1.0" encoding="UTF-8" ?> 
<pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel" 
                version="10.1.3.41.57" id="app_SRListPageDef" 
                Package="oracle.srtutorial.userinterface.pageDefs"> 
  <parameters/> 
  <executables> 
    <iterator id="ServiceRequestsIterator" RangeSize="10" 
              Binds="ServiceRequests" DataControl="SRPublicServiceDataControl"/> 
    <variableIterator id="variables"> 
      <variableUsage DataControl="SRPublicServiceDataControl" 
                     Binds="ServiceRequests.variablesMap.TheStatus" 
                     Name="ServiceRequests_TheStatus" IsQueriable="false"/> 
    </variableIterator> 
  </executables> 
  <bindings> 
    <table id="LoggedInUserServiceRequests" 
           IterBinding="ServiceRequestsIterator"> 
      <AttrNames> 
        <Item Value="SvrId"/> 
        <Item Value="Status"/> 
        <Item Value="RequestDate"/> 
        <Item Value="ProblemDescription"/> 
        <Item Value="ProdId"/> 
        <Item Value="CreatedBy"/> 
        <Item Value="AssignedTo"/> 
        <Item Value="AssignedDate"/> 
      </AttrNames> 
    </table> 
    <action id="ExecuteWithParams" IterBinding="ServiceRequestsIterator" 
            InstanceName="SRPublicServiceDataControl.ServiceRequests" 
            DataControl="SRPublicServiceDataControl" RequiresUpdateModel="true" 
            Action="95"> 
      <NamedData NDName="TheStatus" NDType="java.lang.String" 
                 NDValue="#{requestScope.Status}"/> 
    </action> 
    <action id="Delete1" IterBinding="ServiceRequestsIterator" 
            InstanceName="SRPublicServiceDataControl.ServiceRequests" 
            DataControl="SRPublicServiceDataControl" RequiresUpdateModel="false" 
            Action="30"/> 
    <action id="Commit" InstanceName="SRPublicServiceDataControl" 
            DataControl="SRPublicServiceDataControl" RequiresUpdateModel="true" 
            Action="100"/> 
    <action id="Rollback" InstanceName="SRPublicServiceDataControl" 
            DataControl="SRPublicServiceDataControl" RequiresUpdateModel="false" 
            Action="101"/> 
  </bindings> 
</pageDefinition> 
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D

1- Create the method in your am

Select all

 
    public void deleteServiceRequests () { 
            try { 
                getServiceRequests().removeCurrentRow(); 
            } catch (DMLException e) { 
                throw new JboException("erro"); 
            }             
    } 
2- On the "System Navigator" or "Application Navigator" tab Locate your AM and giving two clicks on it and VA for "Client Interface "

3- Locates your method in the left column and through the arrows located in the middle Put your method in the right column, making this method accessible.

4- With your Open Pagedefinition, go to the "Structure" tab (VA in the View menu and select this tab), and right-click on top of "Bindings", and then "Insert Inside Bindings", and then click "MethodAction"

5- Locate your AM in the left column and after selecting it, look for your method in the right combo, and Click OK

6- Create the method in your bean

Select all

 
public String deleteServiceRequests () { 
	BindingContainer bindings = getBindings(); 
	OperationBinding operationBinding = bindings.getOperationBinding("deleteServiceRequests"); 
 
	operationBinding.execute(); 
} 
7- On your LA button on JSP

Select all

 
action="#{util.deleteServiceRequests}" 
where 'util' is the name of the useful class that you maps it on the faces-config.xml [/ Code]
Pedro_fvieira
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Posts: 13
Joined: Fri, 08 Aug 2008 10:17 am
Location: Vitoria - ES
Existem 11 tipos de pessoas no mundo: As que entendem binário, as que acham que entendem e as que não entendem.

ok ...
can do what you get pass ... but we still do not get where I want to arrive ... still missing something, because type in the method DeleteServiceRequests inside my am, even when I remove A record that should not owe it depends on it does not generate the error message ...

aí to test I put the throw from the outside of the try to see how the error message would look .. . and was like this ...

Select all

 
1- JBO-29000: Unexpected exception caught: oracle.jbo.JboException, msg=erro 
2- erro 
And the registration was not removed, Commit buttons continued disabled ... Exactly as it should happen ... So inside the try I have to do the validation manually ??? How would that be ???

and how to remove message 1 of the messages displayed ??? Just showing my custom message ???

The interesting thing would be to do a general thing in AM, and then create a class (one for each entity) with error messages after ... Saca ... DAE Depending on the error generated in the Bank he takes a message ... I do not even have any idea how to do it ... but let's slow down .. then agent sees this ...
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D


DMLEXCEPTION is released when you try to delete via SQL and the registry has dependents and will violate some constraint

Sometimes with the removecurrentrow () and another


in your Catch exchange DMLEXCeption by Exception and a e.printstacktrace ()
System.out.print (e.getmessage ())

For you to be able to see which exception is thrown when you are so removed using the ADF BC, then it can be appropriated properly

a question .... Do you work in Vitoria ?? What project is this ?? STJ ??
Pedro_fvieira
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Posts: 13
Joined: Fri, 08 Aug 2008 10:17 am
Location: Vitoria - ES
Existem 11 tipos de pessoas no mundo: As que entendem binário, as que acham que entendem e as que não entendem.

Boy,
The method is not generating any exception ... because I changed like you say ... and nothing happened, I looked at the console of the jdev and no message appeared ...
99] yes, vitório - es ... is an internal project aqui in the company ... I do not know what é stj ... (Supreme Court of Justice ??? Well I do not know .. but C is, I do not work No ...)
Why question ???
Pedro_fvieira
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Posts: 13
Joined: Fri, 08 Aug 2008 10:17 am
Location: Vitoria - ES
Existem 11 tipos de pessoas no mundo: As que entendem binário, as que acham que entendem e as que não entendem.

I changed the deletion method ... because only so he generates exception ...
but I did not want to do it now ... I wanted to only after the user tightens the button save q has on the screen ...

The code is like this:

Select all

     
public void deleteServiceRequests () { 
                try { 
                    getServiceRequests().removeCurrentRow(); 
                    getTransaction().commit(); 
                } catch (Exception  e) { 
                    throw new JboException("erro"); 
                }  
        } 
Why would removeecurentrow generate exception when he was alone ??? Would this command not sent to the bank ???
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D

face ..
was my fault ...: oops:
only will give the delete when you do the commit
but and there the exception released was the DML ???

I honestly do not know why you are receiving 2 msg of error on the screen ...
Another way to give msg the way you want and do this in the bean .. dai You do not need Try Catch in AM

Select all

 
public String deleteServiceRequests () {  
   BindingContainer bindings = getBindings();  
   OperationBinding operationBinding = bindings.getOperationBinding("deleteServiceRequests");  
 
   operationBinding.execute();  
 
   if (operationBinding.getErrors() != null && 
       operationBinding.getErrors().size() > 0) { 
 
       FacesContext ctx = getFacesContext(); 
       FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Erro inesperado", null); 
       ctx.addMessage(null, fm); 
   } 
} 
Yes .. Court of Justice .. I have friends there .. Ta rolling a Oracle design in adf la ... tended
Pedro_fvieira
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Posts: 13
Joined: Fri, 08 Aug 2008 10:17 am
Location: Vitoria - ES
Existem 11 tipos de pessoas no mundo: As que entendem binário, as que acham que entendem e as que não entendem.

Boy,

The Exception generated is DMLEXCEPTION even ...
But next of this code that you step .. I put in the same bean that is in the faces-config.xml right ... but the method

Select all

FacesContext ctx = getFacesContext();
is not recognized ... Dao comes this guy ???
In my bean there are these import:

Select all

 
import javax.faces.application.FacesMessage; 
import javax.faces.context.FacesContext; 
 
import oracle.adf.model.AttributeBinding; 
 
import oracle.adf.model.binding.DCBindingContainer; 
 
import oracle.binding.BindingContainer; 
import oracle.binding.OperationBinding; 
what will be missing ??? No option is given to add nothing new ... has the option to create the method ... but what do I put inside it ???


Boy, there is a cara who is doing the course of here in the company and he is from TJ ... Ronney, do you know ???
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D

exchange for this ...
facescontext.getcurrentInstance ()

This I do not know ... Many friends passed by La but currently only has Fabio Paiva
Pedro_fvieira
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Posts: 13
Joined: Fri, 08 Aug 2008 10:17 am
Location: Vitoria - ES
Existem 11 tipos de pessoas no mundo: As que entendem binário, as que acham que entendem e as que não entendem.

é, after I looked better tb I found this aí ...
But ... I still can not do what I want ....
The way it works like this ... But I think that's what you give me is already the basis for what I want ...
I'll continue here trying .. Anything I post aqui what I get ... and doubts I found. ..
and vlw for help so far ...
victorhugomuniz
Moderador
Moderador
Posts: 1396
Joined: Fri, 01 Feb 2008 2:06 pm
Location: Rio de Janeiro - RJ
Contact:
:D

good luck!
: D
OldJack
Rank: Estagiário Júnior
Rank: Estagiário Júnior
Posts: 1
Joined: Sun, 28 Sep 2008 6:22 pm
Location: Vitória
BC4J SUCKS!!!!

What company are you Peter?
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest