Value from detail mode

Help
2013-05-27
2013-06-06
  • Hi,

    Can anyone please explain how I can obtain the value of a field in the detail mode ?

    My rows are displayed in list mode. When the user clicks on one of the rows to display it in the detail mode, I would like to validate a field and disable a section depending on the field.

    I have added an action to my controller.xml. When the user selects the row, it does call the action. However, I am not sure how to obtain the values of the fields to validate them.

    Thanks in advance.

    Med

     
  • Javier Paniza
    Javier Paniza
    2013-05-29

    Hi Medasha,

    use getValue() of View. In this way:

    public void execute() throws Exception {
        ...
        String value = (String) getView().getValue("myProperty");
        if (value.equals("...")) getView().setHidden("myOtherProperty", true);
        ...
    }
    

    Help others in this forum as I help you.
    Need more help? Get OpenXava professional support.

     
  • Hi Javier,

    Thank you. That worked to disable the section when the user selects a row.

    However, now I get the following error when I try to do a search on a reference:
    "Impossible to execute Detail action: null"

    I have included a simplified example of what I am trying to achieve.
    I have an class called EnableSections which has 2 sections General and Tab. This contains a property called Emptab. If the user selects a row and Emptab is Yes then the fields in the Tab section must be enabled. If it is no then the fields must be disabled. To do this I amended the controller to call the action.
    This does what I require. The sections are enabled and disabled accordingly. However, if I try to find a record on the department reference, then I get the error as above.

    I have included my code.

    My entity is as follows:
    package org.openxava.salary.model;

    import javax.persistence.;
    import org.hibernate.annotations.Parameter;
    import org.openxava.annotations.
    ;
    import org.openxava.calculators.;
    import org.openxava.salary.action.
    ;

    @Entity
    @Table(name="emp.test")
    @View(members="General {#" +
    "empno;" +
    "empname; emptab;" +
    "department" +
    "}" +
    "Tab {#" +
    "testing}")

    public class EnableSections {
    @Id @Column(length=3)
    public String empno;

    @Column (length=40) 
    @Required
    private String empname;
    
    @Column(name="emptab", length=1)
    
    @DefaultValueCalculator(value=EnumCalculator.class,
    properties={@PropertyValue(name="enumType", value="org.openxava.salary.model.EnableSections$EmpTab"),
                @PropertyValue(name="value", value="Yes")
    })
    
    @org.hibernate.annotations.Type(type="org.openxava.types.EnumLetterType", 
                parameters={
                  @Parameter(name="letters", value="YN"), 
                  @Parameter(name="enumType", value="org.openxava.salary.model.EnableSections$EmpTab")
                }
              ) 
    @OnChange(SetTab1.class)
    private EmpTab emptab;
    public enum EmpTab{Yes, No}
    
    @Column
    private int testing;
    
    @ManyToOne(fetch=FetchType.LAZY, optional=false)
    @ReferenceView("Simple")
    private Department department;
    
    public String getEmpno() {
        return empno;
    }
    public void setEmpno(String empno) {
        this.empno = empno;
    }
    public String getEmpname() {
        return empname;
    }
    public void setEmpname(String empname) {
        this.empname = empname;
    }
    public EmpTab getEmptab() {
        return emptab;
    }
    public void setEmptab(EmpTab emptab) {
        this.emptab = emptab;
    }
    
    public int getTesting() {
        return testing;
    }
    public void setTesting(int testing) {
        this.testing = testing;
    }
    public Department getDepartment() {
        return department;
    }
    public void setDepartment(Department department) {
        this.department = department;
    }
    

    }

    The code for the action is:
    package org.openxava.salary.action;

    import org.openxava.actions.*;

    public class SetTab extends TabBaseAction {
    public void execute() throws Exception {
    Object value = (Object) getView().getValue("emptab");
    if (value.toString().equals("No")) {
    getView().setSectionEditable("Tab", false);
    getView().setActiveSection(0);
    }
    else {
    getView().setSectionEditable("Tab", true);
    getView().setActiveSection(0);
    }
    }
    }

    I amended the controller as follows:
    "controller name="EnableSections"
    controller name="EnableSections"
    extends controller="Typical"
    action name="detail"
    class="org.openxava.salary.action.SetTab"
    mode="detail"
    hidden="true"
    on-each-request="true"
    "

    I have tried various options in the controller. If I use anything other than on-each-request=true, then the action does not execute when the user clicks on a record.

    I would really appreciate any help with this.

    Thank you.

    Med

     
    Last edit: Medasha Govender 2013-05-29
  • Hi,

    I seem to have resolved the issue. I amended my action as follows and the application does what I want. Can anybody tell me if I went about this correctly ?

    package org.openxava.salary.action;

    import org.openxava.actions.*;

    public class SetTab extends TabBaseAction {
    public void execute() throws Exception {
    try {
    Object value = (Object) getView().getValue("emptab");
    if (value.toString().equals("No")) {
    getView().setSectionEditable("Tab", false);
    getView().setActiveSection(0);
    }
    else {
    getView().setSectionEditable("Tab", true);
    getView().setActiveSection(0);
    }
    }
    catch (Exception ex){
    return;
    }
    }
    }

    Thank you.

    Med

     
  • Javier Paniza
    Javier Paniza
    2013-05-31

    Hi Med,

    Can anybody tell me if I went about this correctly ?

    Yes, you code it's good enough.
    Coding like art, there is not an unique "correct way" to do the things.


    Help others in this forum as I help you.
    Need more help? Get OpenXava professional support.

     
  • Hi,

    I am still having a problem with this.

    I would like to enable and disable certain fields and sections when the user selects a row from the list. In my example, I have a field called Enable. When the user selects the row from the list mode, I would like to evaluate this field. If it is Yes, then I would like to enable the Commission field and the fields in the Tab section. If the field is No then these fields should be disabled.
    The fields in the tab section are being enabled and disabled correctly. However, the Commission field is only showing as disabled when I click on the refresh button or if I click on the tab section and then return to the General section. It seems that the action is not being called when I click on the row in the list mode. What am I doing wrong ?

    This is my code:

    package org.openxava.salary.model;

    import java.math.*;

    import javax.persistence.*;

    import org.hibernate.annotations.Parameter;
    import org.hibernate.validator.;
    import org.openxava.annotations.
    ;
    import org.openxava.calculators.;
    import org.openxava.salary.action.
    ;

    @Entity
    @Table(name="emp.test")
    @View(members="General {#" +
    "empno;" +
    "empname; enable; commission;" +
    "department" +
    "}" +
    "Tab {#" +
    "testing}")

    public class EnableSections {
    @Id @Column(length=3)
    public String empno;

    @Column (length=40) 
    @Required
    private String empname;
    
    @Column(name="enable", length=1)
    
    @DefaultValueCalculator(value=EnumCalculator.class,
    properties={@PropertyValue(name="enumType", value="org.openxava.salary.model.EnableSections$Enable"),
                @PropertyValue(name="value", value="Yes")
    })
    
    @org.hibernate.annotations.Type(type="org.openxava.types.EnumLetterType", 
                parameters={
                  @Parameter(name="letters", value="YN"), 
                  @Parameter(name="enumType", value="org.openxava.salary.model.EnableSections$Enable")
                }
              ) 
    @OnChange(SetTab1.class)
    private Enable enable;
    public enum Enable{Yes, No}
    
    @Digits(integerDigits=2, fractionalDigits=2) // To indicate its size
    private BigDecimal commission;
    
    @Column
    private int testing;
    
    @ManyToOne(fetch=FetchType.LAZY, optional=false)
    @ReferenceView("Simple")
    private Department department;
    
    public String getEmpno() {
        return empno;
    }
    public void setEmpno(String empno) {
        this.empno = empno;
    }
    public String getEmpname() {
        return empname;
    }
    public void setEmpname(String empname) {
        this.empname = empname;
    }
    
    public Enable getEnable() {
        return enable;
    }
    public void setEnable(Enable enable) {
        this.enable = enable;
    }
    public BigDecimal getCommission() {
        return commission;
    }
    public void setCommission(BigDecimal commission) {
        this.commission = commission;
    }
    public int getTesting() {
        return testing;
    }
    public void setTesting(int testing) {
        this.testing = testing;
    }
    public Department getDepartment() {
        return department;
    }
    public void setDepartment(Department department) {
        this.department = department;
    }
    

    The action:
    package org.openxava.salary.action;

    import org.openxava.actions.*;

    public class SetTab extends TabBaseAction {
    public void execute() throws Exception {
    try {
    Object value = (Object) getView().getValue("enable");
    if (value.toString().equals("No")) {
    getView().setEditable("commission", false);
    getView().setSectionEditable("Tab", false);
    getView().setActiveSection(0);
    }
    else {
    getView().setEditable("commission", true);
    getView().setSectionEditable("Tab", true);
    getView().setActiveSection(0);
    }
    }
    catch (Exception ex){
    return;
    }
    }
    }

    The controller:

    controller name="EnableSections">
    extends controller="Typical"/>
    action name="detail"
    class="org.openxava.salary.action.SetTab"
    mode="detail"
    hidden="true"
    on-each-request="true"
    />
    controller>

    Thanks for any help.

    Med

     
    Last edit: Medasha Govender 2013-06-03
  • Javier Paniza
    Javier Paniza
    2013-06-05

    Hi Med,

    I would like to enable and disable certain fields and sections when the user
    selects a row from the list

    Define a XAVA_SEARCH_ACTION. Read the section 10.2.6 of the book.

    In that action you have to do the regular search logic and afterwards your enable/disable logic.


    Help others in this forum as I help you.
    Need more help? Get OpenXava professional support.

     
  • Hi Javier,

    Thank u. It worked.

    Regards

    Med