Extending Metaworks Components - TheOpenCloudEngine/metaworks GitHub Wiki

λ©”νƒ€μ›μŠ€ μ»΄ν¬λ„ŒνŠΈμ˜ μƒμ†κ°œλ…

λ©”νƒ€μ›μŠ€ μ»΄ν¬λ„ŒνŠΈμ˜ ꡬ성

λ©”νƒ€μ›μŠ€ μ»΄ν¬λ„ŒνŠΈλŠ” model-face-facehelper (java, ejs, ejs.js) 둜 κ΅¬μ„±λœλ‹€. κ°μžλŠ” 동일 νŒ¨ν‚€μ§€ (폴더, 디렉토리) 상에 μ‘΄μž¬ν•΄μ•Ό μ„œλ‘œ 묢이게 λœλ‹€. ejs 파일이 없어도 κΈ°λ³Έ ejs 둜 ObjectFace.ejs κ°€ μ‚¬μš©λ˜κ²Œ λ˜μ–΄ λͺ¨λΈμ„ λ¦¬ν”Œλž™μ…˜μœΌλ‘œ 화면에 뿌리게 λœλ‹€.

[Model.java]
    |
[Model.ejs] - optional (java λŠ” κΌ­ μžˆμ–΄μ•Ό 함. ejs 만 μ‘΄μž¬ν•˜λŠ” component λŠ” μ—†μŒ)
    |
[Model.ejs.js] - optional (ejs.js κ°€ μžˆλ‹€λ©΄ ejs λŠ” κΌ­ μžˆμ–΄μ•Ό 함)

Model.java

package com.abc.model;

public class Model{
  String field1;
  public getField1(){ return field1;}
  public setField1(String field1){ this.field1 = field1; }
}

Model.ejs

Field1 = <%=value.field1%>

Model.ejs.js

var com_abc_model_Model = function(objectId, className){
   $("#objDiv_" + objectId).css("background", "yellow");
};

UI의 상속

DerivedModel.java

μ•„λž˜μ˜ derivedModel 은 μžμ‹ μ˜ ejs와 ejs.js κ°€ 없어도 Model 이 가진 Model.ejs 와 Model.ejs.js κΉŒμ§€ 상속 λ°›κ²Œ λœλ‹€. 즉, UIλ₯Ό λͺ¨λ‘ 상속 λ°›λŠ”λ‹€.

class DerivedModel extends Model{
  String field2;
  public getField2(){ return field2;}
  public setField2(String field2){ this.field2 = field2; }

}

UI의 μ˜€λ²„λΌμ΄λ“œ

DerivedModel.ejs νŒŒμΌμ„ λ§Œλ“€μ–΄ 동일 폴더에 λ„£μ–΄μ£Όλ©΄, DerivedModel 은 μžμ‹ μ˜ ejs와 ejs.js λ₯Ό λ”°λ₯΄κ²Œ λœλ‹€. 이 λ•Œ κΈ°μ‘΄ ν™”λ©΄ ejs λ₯Ό κ°€μ Έμ™€μ„œ μΆ”κ°€λœ μš”μ†Œλ§Œμ„ λ„£κ³  싢은 경우라면, include λ₯Ό μ‚¬μš©ν•œλ‹€.

DerivedModel.ejs μ˜ˆμ‹œ

<%=include('dwr/metaworks/com/abc/model/Model.ejs')%>
<%=fields.field2.here()%>

Face Helper λ₯Ό μƒμ†ν•˜λ €λ©΄ λ‹€μŒκ³Ό 같이 metaworks μ—μ„œ μ •μ˜ν•΄μ£ΌλŠ” extend λ©”μ„œλ“œλ₯Ό μ‚¬μš©ν•œλ‹€.

DerivedModel.ejs.js


var com_abc_model_DerivedModel = function(objectId, className){
    com_abc_model_Model.apply(this, new Array(objectId, className)); //equals to super(objectId, className) in java
}
extend(com_abc_model_DerivedModel, "com_abc_model_Model");  //equals to extends in java