Table of Contents

How to ...
How to prevent from modifying certain fields in a view?
How to use a different view for creating and for updating?
How to deactive a property for updating but not for creating?
How to access to a property of the model that isn't shown in the view?

How to ...

How to prevent from modifying certain fields in a view?

In Update view, by default, all the fields (except the key) are modifiables.
But you can declare any property of the view read only, in this way:
<view name="SomeMemberReadOnly">
    <property-view property="name" read-only="true"/>
</view>
 
Or, if you are using OX3:
@ReadOnly(forViews="SomeMembersReadOnly")
private String name;
 

How to use a different view for creating and for updating?

Obiously you must define a view for creating and another for updating, thus:
<component ... >
...
    <view name="Create">
    ...
    </view>
 
    <view name="Update">
    ...
    </view>
 
</component>
 
Or, if you are using OX3:
@Views({
    @View(name="Create", members="  .... "),
    @View(name="Update", members=" ... ")
})
public class MyEntity { ...
 
Now you have to refine the new action for chosing the Create view and the searching action for chosing the Update view. First, define your own controller, in your controllers.xml, thus:
<controller name="MyTypical">
    <action name="new"
        class="com.mycompany.myapplication.actions.MyNewAction"
        image="images/new.gif" on-init="true"
        keystroke="F2">
        <use-object name="xava_view"/>
    </action>
    <action name="search"
        by-default="if-possible" hidden="true"
        class="com.mycompany.myapplication.actions.MySearchAction"
        keystroke="F8">
        <use-object name="xava_view"/>
    </action>
 </controller>
 
And now assign this controller to your module, and define the searching action for the module. Write your module in the application.xml in this way:
<module name="MyModule">
    <env-var name="XAVA_SEARCH_ACTION" value="MyTypical.search"/>
    <model name="MyComponent"/>
    <controller name="MyTypical"/>
</module>
 
And now only remains to refine the logic of your actions. For MySearchAction you write:
public class MySearchAction extends SearchByViewKeyAction {
    public void execute() throws Exception {
        getView().setViewName("Update");
        super.execute();
    }
}
And for MyNewAction:
public class MyNewAction extends NewAction {
    public void execute() throws Exception {
        getView().setViewName("Create");
        super.execute();
    }
}
 

How to deactive a property for updating but not for creating?

You have to refine the new action and the searching action. First, define your own controller, in your controllers.xml, thus:
<controller name="MyTypical">
    <action name="new"
        class="com.mycompany.myapplication.actions.MyNewAction"
        image="images/new.gif" on-init="true"
        keystroke="F2">
        <use-object name="xava_view"/>
    </action>
    <action name="search"
        by-default="if-possible" hidden="true"
        class="com.mycompany.myapplication.actions.MySearchAction"
        keystroke="F8">
        <use-object name="xava_view"/>
    </action>
 </controller>
 
And now assign this controller to your module, and define the searching action for the module, write your module in the application.xml in this way:
<module name="MyModule">
    <env-var name="XAVA_SEARCH_ACTION" value="MyTypical.search"/>
    <model name="MyComponent"/>
    <controller name="MyTypical"/>
</module>
 
And now only remains to refine the logic of your actions. For MySearchAction you write:
public class MySearchAction extends SearchByViewKeyAction {
    public void execute() throws Exception {
        super.execute();
        getView().setEditable("myproperty", false);
    }
}
And for MyNewAction:
public class MyNewAction extends NewAction {
    public void execute() throws Exception {
        super.execute();
        getView().setEditable("myproperty", true);
    }
}
 

How to access to a property of the model that isn't shown in the view?

From the view you can obtain only the displayed data. But it's possible, using MapFacade class to acess directly to the model.
You can write in your action a code like this one:
public class MyAction extends ViewBaseAction {
 
    public void execute() throws Exception {
        Invoice invoice = (Invoice) MapFacade.findEntity(getModelName(), getView().getKeyValues());
        BigDecimal specialDiscount = invoice.getSpecialDiscount(); // Special discount is not shown in the view
        ...
    }
    ...
 
In this way you can access to specialDiscount property although it is not displayed in the current view.