سؤال

I have an EJB named GmaThreshold.java:

package cdot.oss.cmsat.gma.ejb.entity;

@Entity
@Table(name="GMA_THRESHOLDS")
@NamedQuery(
    name = "getThresholdParameters",
    query = "SELECT gmaTh.maxDurationIc, gmaTh.distinctBnumberRatio "
          + "WHERE gmaTh.id.circleId=?1 AND gmaTh.id.tspId=?2 "
          + "AND gmaTh.id.flag=?3 ")
public class GmaThreshold implements Serializable {
    @EmbeddedId
    private GmaThresholdPK id;

    @Column(name="DISTINCT_BNUMBER_RATIO")
    private String distinctBnumberRatio;

    @Column(name="MAX_DURATION_IC")
    private BigDecimal maxDurationIc;

    public GmaThresholdPK getId() {
        return this.id;
    }

    public void setId(GmaThresholdPK id) {
        this.id = id;
    }

    public String getDistinctBnumberRatio() {
        return this.distinctBnumberRatio;
    }

    public void setDistinctBnumberRatio(String distinctBnumberRatio) {
        this.distinctBnumberRatio = distinctBnumberRatio;
    }

    public BigDecimal getMaxDurationIc() {
        return this.maxDurationIc;
    }

    public void setMaxDurationIc(BigDecimal maxDurationIc) {
        this.maxDurationIc = maxDurationIc;
    }
}

I want the parameters of the entity class to be filled from the user in JSP.

<s:textfield id="thresholdParameter_1"
    name="gmathreshold.distinctBnumberRatio">
</s:textfield></td>

and in my action class keep an instance of the bean as a member variable.

I am using Struts2.

Is this a correct approach to get an EJB entity filled like this?

Should I use a DTO?

EDIT: I get distinctBnumberRatio from user in a textfield so it will be a String, however in my bean it is a BigDecimal. How to work around this?

هل كانت مفيدة؟

المحلول

EJBs since 3.0 are simple POJOs, so using the beans in the JSP is possible. By evaluating OGNL expression in

"gmathreshold.distinctBnumberRatio"

the corresponding getters and setters will be called. Then you can update the EJB container. DTOs doesn't belong to any container unless you manage them manually or by the another container and also could be used by the presentation layer. Both of them are correct.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top