2017-09-01 145 views
0

有誰知道如何在JSP上使用Optional對象嗎?Java 8選項和JSP

我有一個類:

@Entity 
@Table(name = "projects") 
public class Project { 

@Expose 
@ManyToOne 
@JoinColumn(name = "customer_id") 
private Customer endCustomer; 
.... 

public Optional<Customer> getEndCustomer() { 
    return Optional.ofNullable(endCustomer); 
} 

public void setEndCustomer(Customer endCustomer) { 
    this.endCustomer = endCustomer; 
} 
.... 
} 

,我有JSP:

<td> 
 
    <form:select class="form-control" id="endCustomer" path="endCustomer.id" tabindex="4"> 
 
     <form:options items="${endCustomers}" itemValue="id" itemLabel="name"/> 
 
    </form:select> 
 
</td>

這部分並不明顯的原因工作:path="endCustomer.id"

是有一個解決方法? 謝謝!

+1

您可以指定更多?你嘗試過'endCustomer.get().id'嗎? – soorapadman

+0

@soorapadman嘗試過,沒有工作。 –

回答

1

嘗試這樣的事情

<td> 
    <form:select class="form-control" id="endCustomer" path="${endCustomer.get().id}" tabindex="4"> 
     <form:options items="${endCustomers}" itemValue="id" itemLabel="name"/> 
    </form:select> 
</td> 

相關問題How to access an object

+0

@VladyslavNikolaievпривет,коссталениюэтонеработаетдляpath,тактолькозначениеможновывести。 –

+0

for info - 此方法不起作用 –

+0

@UnknwnArtist,試試 'path =「」' 甚至 ' ' 我不確定這些陳述的正確性 –