Menu

How to copy value to a new screen popup

IB Afriana
2024-02-10
2024-02-15
  • IB Afriana

    IB Afriana - 2024-02-10

    Hi,
    I need to copy value to a new item popup. I have a Registration entity which has one to many MedicalProcedure entity. I displayed medical procedures list in my registration screen. Please refer to the attachment for more information.

    When I create a new medical procedure (by clicking the new button), a new Medical Procedure popup is displayed. I want customize the popup, the patient field should be automatically copied from the previous screen, so the user doesn't need to fill it in manually.

    I tried creating new action to achieve tis, but got an error: "The property viewObject does not exist"

    Here is my codes:

    In Registration.java - this is how I display the medical procedure list.

      @ManyToOne
      @ReferenceView("Simple")
      Patient patient;
    ....
      @OneToMany(mappedBy = "registration", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
      @ListProperties("number, procedure.code, procedure.description, price, performedBy.name, period.startDate, period.endDate")
      @NewAction("MedicalProcedure.new")
      Collection<MedicalProcedure> medicalProcedures;
      ...
    

    This is my controllers.xml

        <controller name="MedicalProcedure">
            <extends controller="Typical"/>
            <action name="new" icon="card-plus" on-init="true"
                    class="com.example.gp.actions.GetPatientFromRegistration" />
        </controller>
    

    This is the action code:

    public class GetPatientFromRegistration extends NewAction {
      @Override
      public void execute() throws Exception {
        try {
          super.execute();
          MedicalProcedure procedure = (MedicalProcedure) getView().getEntity();
          getView().setValue("patient", procedure.getRegistration().getPatient());
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    

    In MedicalProcedure.java - This is the related fields declaration.

    ...
      @ManyToOne(fetch = FetchType.LAZY, optional = false)
      @ReferenceView("Simple")
      Patient patient;
    
      @ManyToOne(fetch = FetchType.LAZY, optional = false)
      @ReferenceView("Simple")
      @SearchAction("CustomListActions.searchRegistrationByPatient")
      Registration registration;
      ...
    

    I got this error when clicking the new button:

    Feb 10, 2024 4:05:48 PM org.openxava.controller.ModuleManager manageRegularException
    SEVERE: The property viewObject does not exist in io.example.gp.actions.GetPatientFromRegistration
    org.openxava.util.PropertiesManagerException: The property viewObject does not exist in io.ksatria.gp.actions.GetPatientFromRegistration
        at org.openxava.util.PropertiesManager.getPropertyDescriptor(PropertiesManager.java:460)
        at org.openxava.util.PropertiesManager.executeSetFromString(PropertiesManager.java:260)
        at org.openxava.util.PropertiesManager.executeSetsFromStrings(PropertiesManager.java:364)
        at org.openxava.controller.ModuleManager.setPropertyValues(ModuleManager.java:1167)
        at org.openxava.controller.ModuleManager.prepareAction(ModuleManager.java:788)
        at org.openxava.controller.ModuleManager.executeAction(ModuleManager.java:592)
        at org.openxava.controller.ModuleManager.executeAction(ModuleManager.java:525)
        at org.openxava.controller.ModuleManager.execute(ModuleManager.java:483)
        at org.apache.jsp.xava.execute_jsp._jspService(execute_jsp.java:260)
    

    Can somebody give me a hint to solve this issue?

     

    Last edit: IB Afriana 2024-02-10
  • gregorio

    gregorio - 2024-02-10

    Hi.
    change this
    getView().setValue("patient", procedure.getRegistration().getPatient());

    for that
    getView().setValue("patient", procedure.getRegistration().getPatient().getId());

     
    • IB Afriana

      IB Afriana - 2024-02-10

      hi Gregorio, I tried your suggestion, but I still got the same error:

      org.openxava.util.PropertiesManagerException: The property viewObject does not exist

      public class GetPatientFromRegistration extends NewAction {
        @Override
        public void execute() throws Exception {
          try {
            super.execute();
            System.out.println("GetPatientFromRegistration.execute()");
            MedicalProcedure procedure = (MedicalProcedure) getView().getEntity();
            getView().setValue("patient", procedure.getRegistration().getPatient().getId());
          } catch (Exception e) {
            System.out.println("Something went wrong!");
            e.printStackTrace();
          }
        }
      }
      

      It doesn't execute System.out.println that I put there. The exception is thrown by OX before executing my code.

      I think the problem here is that @NewAction only works from it's own module. So, when I click the new button from the Medical Procedure, it loads the view object properly then executes my code.

      However, if I click new button from Registration screen, I got the error.

       
  • gregorio

    gregorio - 2024-02-11

    in the sample in document

    super.execute(); it's the last line no the first.

    try
    public class GetPatientFromRegistration extends NewAction {
    @Override
    public void execute() throws Exception {
    try {

      System.out.println("GetPatientFromRegistration.execute()");
      MedicalProcedure procedure = (MedicalProcedure) getView().getEntity();
      getView().setValue("patient", procedure.getRegistration().getPatient().getId());
        super.execute();
    } catch (Exception e) {
      System.out.println("Something went wrong!");
      e.printStackTrace();
    }
    

    }
    }

    Sorry my english...

     
    • IB Afriana

      IB Afriana - 2024-02-11

      Thank you for trying to help me!

      I actually checked that same documentation about create and update views, but the issue seems to be different.

      The error happens whenever I click the "New" button from another module to create a Medical Procedure, like when I do it from the Registration module. If I create the Medical Procedure directly from the Medical Procedure module itself, I don't see the error.

      Just to clarify, as I mentioned earlier, this error occurs before my own code even runs, so the order of super.execute() doesn't seem to be the problem.

      Would you have any other ideas about what might be causing this specific issue?

       
  • gregorio

    gregorio - 2024-02-11

    Hi
    you have:
    getView().setValue("patient", procedure.getRegistration().getPatient().getId());

    but patient is a reference of Entity Patient, is not a simple property like name or age.
    try
    getView().setValue("patient.id", procedure.getRegistration().getPatient().getId());
    or
    getView().getSubview("patient").setValue("id", procedure.getRegistration().getPatient().getId());
    or
    getView().getSubview("patient").setValueNotifying("id", procedure.getRegistration().getPatient().getId());

     
  • IB Afriana

    IB Afriana - 2024-02-12

    Just to make it clear, the error happens before that codes are executed. Please see here, I remove my specific codes, but the error still happens.

    org.openxava.util.PropertiesManagerException: The property viewObject does not exist

    public class GetPatientFromRegistration extends NewAction {
      @Override
      public void execute() throws Exception {
          super.execute();
      }
    }
    
     
  • Javier Paniza

    Javier Paniza - 2024-02-14

    Hi IB,

    Collection action must have a viewObject property. That is on that way, because you could create a reusable action to be used in several of your collection, so the action has a way to know what collection it is.

    To get rid of your error just create a viewObject property in your action, thus:

    @Getter @Setter
    String viewObject;
    

    But better that this, you can extends your action from CollectionElementViewBaseAction, so the viewObject is already included. And still better extends from CreateNewElementInCollectionAction, the new action for collection.

    That is, change this:

    public class GetPatientFromRegistration extends NewAction {
    

    By:

    public class GetPatientFromRegistration extends CreateNewElementInCollectionAction {
    

    Help others in this forum as I help you.

     
  • IB Afriana

    IB Afriana - 2024-02-15

    Thanks, Javier... I changed the parent class as you suggested then it works.

    public class GetPatientFromRegistration extends CreateNewElementInCollectionAction {
    .....
    }
    
     

Log in to post a comment.

MongoDB Logo MongoDB