2016-12-26 2 views
0

JSF 응용 프로그램을 개발 중입니다. 2 개의 selectOnemenu 컨트롤과 제출 버튼이 있습니다. 그래서 읽을 수 는 I 2 개 필드의 값 I는 AJAX로 onchange를 사용하려고값을 비교하는 방법 JSF selectonemenu

<h:selectOneMenu id="from" value="#{currencyBean.history.fromCurrency}" > 
    <f:selectItems value="#{currencyBean.currency}" var="c" itemValue="#{c}" itemLabel="#{c.name}"/> 
</h:selectOneMenu> 
<p:outputLabel for="to" value="to:" /> 
<h:selectOneMenu id="to" value="#{currencyBean.history.toCurrency}" > 
    <f:selectItems value="#{currencyBean.currency}" var="c" itemValue="#{c}" itemLabel="#{c.name}"/> 
</h:selectOneMenu> 
<p:commandButton id="calculateButton" value="Convert" update=":convert :historyPanel" onstart="PF('statusDialog').show()" onsuccess="PF('statusDialog').hide()" validateClient="true" ajax="true" action="#{currencyBean.Calculate()}" /> 

동일하지만 매번 I 번째 drowpdown의 값이 backbean에서 널되었다 한 드롭을 변경할 경우 버튼을 해제해야 그것. 여기

내 backbean

@Named(value = "currencyBean") 
@RequestScoped 
public class CurrencyBean implements Serializable { 

    /** 
    * Creates a new instance of CurrencyBean 
    */ 
    private History history; 
    private Currency currency; 
    private Date currentDate; 
    @Inject 
    private Loginbean loginBean; 

    private List<History> historyList; 

    public List<History> getHistoryList() { 
     int userId = loginBean.getUserId(); 
     if (userId != -1) { 

      return new HistoryHelper().GetHistoryListByUser(userId); 
     } 
     return null; 
    } 

    public CurrencyBean() { 
     history = new History(); 
    } 

    public History getHistory() { 
     return history; 
    } 

    public void setHistory(History history) { 
     this.history = history; 
    } 

    public Currency[] getCurrency() { 
     return Currency.values(); 
    } 

    public Date getCurrentDate() { 
     return new Date(); 
    } 

    public void Calculate() { 
     int userId = loginBean.getUserId(); 
     if (userId != -1) { 
      new CurrencyClient().Convert(userId, this.history); 
     } 

    } 

} 

단서입니까?

+0

더 정밀하게 입력하고 onchange 메서드를 구현하는 방법을 exatcly 입력 할 수 있습니까 ?? 그리고 백킹 빈과 같은 모습, 특히 그 범위는 –

+0

내 백의를 추가하기 위해 내 질문을 업데이트했습니다. onchange 구현에 관한, 난 그냥 필드에서 값을 null로 필드를 업데이트하는 경우 로그 값을 모두에서 및 필드에 업데이트 할 시도했다 필드 값을 업데이트하는 경우 null –

+0

그리고 어디에 이 onchange 구현 ?? selectOneMenu에서? onchange 속성에서 무엇이 불려지나요? –

답변

2

내 모든 가정 문제는 관리되는 빈 범위에서 온 것입니다. 당신은 @Request 범위를 가지므로 모든 요청은 관리되는 빈이 컨테이너에서 제거 될 것이므로 onchange="submit()"을 정의 할 때 (onchange 속성을 구현하는 방법을 정의하지 않았기 때문에 내 가정 일 뿐이다)이 selectBox 컴포넌트 값에서 값을 선택한다. 구성 요소가 업데이트되었지만 첫 번째 구성 요소가 여전히 null입니다. 첫 번째 selectBox에서 업데이트 된 두 번째 selectBox 값을 선택하면 첫 번째 요청 후 관리 빈이 제거되므로 selectBox가 더 이상 존재하지 않습니다. 예를 들어 @ViewScope과 같이 더 넓은 범위로 시도해야합니다. 도움이되지 않으면 구현 변경 특성과 같은 추가 정보가 필요합니다

관련 문제