小编Zaw*_* oo的帖子

在 TypeScript / Angular 4+ 中将枚举键显示为字符串

export enum Type {
    TYPE_1 : "Apple",
    TYPE_2 : "Orange",
    TYPE_3 : "Banana"
}
Run Code Online (Sandbox Code Playgroud)

当我登录时Type.TYPE_1toString默认调用方法。

console.log(Type.TYPE_1 + " is " + Type.TYPE_1.toString());

Output => Apple is Apple
Run Code Online (Sandbox Code Playgroud)

我的期望是结果就像

Output : TYPE_1 is Apple
Run Code Online (Sandbox Code Playgroud)

如何将密钥记录/获取TYPE_1为字符串?

有没有办法override method像下面那样做?

export enum Type {
    TYPE_1 : "Apple",
    TYPE_2 : "Orange",
    TYPE_3 : "Banana"

    toString() {
        this.key + " is " + this.toString();
        <or>
        this.key + " is " + this.value();
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经在谷歌上搜索了,我还没有确定。

更新

目的是在UI中显示

export …
Run Code Online (Sandbox Code Playgroud)

typescript typescript2.0 angular

3
推荐指数
1
解决办法
2万
查看次数

PrimeFaces SelectOneMenu ajax 渲染

我的程序出了什么问题?我认为一切都很好。我的changeKeyValue方法获取所选值“REFERENCE”并将true布尔值设置为showReference. h:panelGroup但是,如果我使用update="targetPanel"in ,我的页面将无法呈现p:ajaxh:panelGroup当我使用时它可以渲染update="entryForm"

我缺少什么?

我的页面.xhtml

<h:form id="entryForm">
        <p:selectOneMenu value="#{MyBean.keyFactorValue}" required="true" style="width:257px;" id="keyFactorValue">
            <f:selectItems value="#{MyBean.selectItemList}" var="type" itemLabel="#{type.label}" itemValue="#{type}"/>  
            <p:ajax listener="#{MyBean.changeKeyValue}" update="targetPanel" event="change"/>
        </p:selectOneMenu>

        <h:panelGroup id="targetPanel" rendered="#{MyBean.showReference}">
            .......
        </h:panelGroup>

</h:form>
Run Code Online (Sandbox Code Playgroud)

KeyFactorValue.java

public enum KeyFactorValue {
    REFERENCE("Reference"), FORM_TO("From-To"), FIXED("Fixed");

    private String label;

    private KeyFactorValue(String label) {
        this.label = label;
    }

    public String getLabel() {
        return label;
    }
}
Run Code Online (Sandbox Code Playgroud)

MyBean.java

@Scope(ScopeType.CONVERSATION)
@Name("MyBean")
public class MyBean {
    private boolean showReference; …
Run Code Online (Sandbox Code Playgroud)

java jsf primefaces

2
推荐指数
1
解决办法
2650
查看次数

更好的SQL插入查询方式

其实,我不知道下面的查询有什么不同?

哪一个更好(性能等)?顺便说一句,我使用的是SQL Server.

查询1:

INSERT INTO PERSON (ID, NAME, ADDRESS) VALUES('001', 'Smit', 'London');
INSERT INTO PERSON (ID, NAME, ADDRESS) VALUES('002', 'Jhon', 'London');
Run Code Online (Sandbox Code Playgroud)

问题2:我以前从未见过

INSERT INTO PERSON (ID, NAME, ADDRESS)
SELECT '001', 'Smit', 'London' UNION ALL
SELECT '002', 'Jhon', 'London'
Run Code Online (Sandbox Code Playgroud)

sql database sql-server

2
推荐指数
1
解决办法
69
查看次数

Primefaces中是否有行选择事件可编辑数据表?

我想row selection eventPrimefaces Editable Datatable点击pencil icon行的时候得到.有两个事件rowEditrowEditCancel.

<p:dataTable var="car" value="#{tableBean.carsSmall}" id="carList" editable="true">  
    ...
    <p:ajax event="rowEdit" listener="#{tableBean.onEdit}" update=":form:messages" />  
    <p:ajax event="rowEditCancel" listener="#{tableBean.onCancel}" update=":form:messages" />  
    .....
</p:dataTable>  
Run Code Online (Sandbox Code Playgroud)

rowEdit事件:当用户单击tick mark图标时触发此事件.

rowEdit事件的监听器方法

public void onEdit(RowEditEvent event) {  
    ....
}
Run Code Online (Sandbox Code Playgroud)

rowEdit事件:当用户单击cross mark图标时触发此事件.

rowEditCancel事件的监听器方法

public void onCancel(RowEditEvent event) {  
    ...
}  
Run Code Online (Sandbox Code Playgroud)

我想在用户点击pencil mark图标时触发.是否有听众方法?

jsf primefaces

2
推荐指数
1
解决办法
5083
查看次数

Singleton Design Pattern及其子类的默认构造函数

在我的编码中,我使用了SingletonSingleton Design Pattern.问题是为什么它的子类不允许使用默认构造函数?

我得到编译时错误:

Implicit super constructor Singleton() is not visible. Must explicitly invoke another constructor
Run Code Online (Sandbox Code Playgroud)

Singleton.java

public class Singleton {
    private static Singleton singleton;

    private Singleton() {
        System.out.println("I am user class");
    }

    public static Singleton getInstance() {
        if(singleton == null) {
            singleton = new Singleton();
        }
        return singleton;
    }

}
Run Code Online (Sandbox Code Playgroud)

SubClass.java

public class SubClass extends Singleton {
    public SubClass(){
        System.out.println("I am sub class");
    }
}
Run Code Online (Sandbox Code Playgroud)

java

1
推荐指数
1
解决办法
819
查看次数

JPA CascadeType.ALL无法通过查询工作?

我有OneToMany双向关系enity类(WorkOrderTask).WorkOrder有一个或多个Task.当我WorkOrder通过查询删除enity时,我得到外键约束异常.EntityManager无法Task自动删除相关内容.

我的问题:方法是否CascadeType.REMOVE使用em.removed(..)?它是否被使用query?(删除查询).

WorkOrder.java

.....
public class WorkOrder {
    ....
    @Temporal(TemporalType.TIMESTAMP)
    private Date expiryDate;

    @OneToMany(cascade=CascadeType.ALL, mappedBy="workOrder", orphanRemoval=true)
    private List<Task> taskList;
    ......
}
Run Code Online (Sandbox Code Playgroud)

Task.java

......
public class Task {
    .....
    @ManyToOne
    @JoinColumn(name = "WORK_ORDER_ID", referencedColumnName = "ID")
    private WorkOrder workOrder;
    .....
}
Run Code Online (Sandbox Code Playgroud)

我需要WorkOrder根据到期日删除.我需要先删除相关内容Task,之后我必须删除WorkOrder.这是对的吗?我认为,它会更好CascadeTypeQuery.

java jpa

1
推荐指数
1
解决办法
818
查看次数

从excel读取时获取空指针异常java XSSFCell cell = row.getCell(j);

private String[][] data;

// to read from excel file

public void readFile() throws IOException {

    // Path to the excel file
    // File datafile = new File("C:\\Users\\atomar\\Documents\test.xlsx");
    // A Buffered File Input Stream to read the data
    FileInputStream f = new FileInputStream(
            "C:\\Users\\atomar\\Documents\\test.xlsx");
    System.out.println("file found");
    // InputStream fis = new BufferedInputStream(new FileInputStream("f"));
    // We create a workbook which represents the excel file
    XSSFWorkbook book = new XSSFWorkbook(f);

    // Next a sheet which represents the sheet within that excel file
    XSSFSheet …
Run Code Online (Sandbox Code Playgroud)

java apache-poi

1
推荐指数
1
解决办法
9154
查看次数

java中的时间比较

我想比较字符串时间格式,例如是否有人提供的其他api?

public void test() {

    Stirng t1 = "10:30 AM"; // 12-hours format
    Stirng t2 = "11:30 AM"; // 12-hours format
            <or>
    Stirng t1 = "10:30"; // 24-hours format
    Stirng t2 = "11:30"; // 24-hours format

    if(t1.before(t2)) {
        System.out.println(t1 + " is before of " + t2);
    }
}
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
2
解决办法
2812
查看次数

参数在JSF-2.0中将一个页面传递给另一个页面?

我想将参数从一个页面传递到另一个页面.

每个页面都有一个ViewScoped JSF Backing Bean.

虽然,我尝试使用<f:param>我得到以下错误:当我点击<h:commandLink>将导航到另一个页面.

错误:

] Root cause of ServletException.
com.sun.faces.mgbean.ManagedBeanCreationException: Unable to create managed bean ReservationActionBean.  The following problems were found:
     - The scope of the object referenced by expression #{param.resvDataModel}, request, is shorter than the referring managed beans (ReservationActionBean) scope of view
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:265)
    at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    .........
Run Code Online (Sandbox Code Playgroud)

page1.xhtml

<p:panelGrid style="margin-top:-1px;" id="dashboard">
    <ui:repeat value="#{DashBoard.dayList}" var="day">
        <p:row>
            <p:column style="background:#C1CDCD;width:100px;">
                <h:outputText value="#{day}" style="color:#333333;font-size:13px;">
                    <f:convertDateTime type="date" pattern="EEE, yyyy-MM-dd"/>
                </h:outputText> …
Run Code Online (Sandbox Code Playgroud)

java jsf

0
推荐指数
1
解决办法
1万
查看次数