2012-12-21 86 views
0

我想根據複選框的值生成一個輸出文本;這裏是我的代碼:h:selectBooleanCheckbox第一次不起作用

<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:p="http://primefaces.org/ui" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core"> 

<body> 
    <ui:composition template="../WEB-INF/templates/template.xhtml"> 
     <ui:define name="content"> 
      <h:form id="formModifClt"> 
      <h:outputText value="voulez-vous modifier cette image ?"/> 
      <h:selectBooleanCheckbox value="#{clientController.modifierImage}" > 
      <f:ajax event="click" listener="#{clientController.onChangeCheckBox()}" render="textPanel" /> 
      </h:selectBooleanCheckbox> 
      <p:outputPanel id="textPanel" autoUpdate="true" > 
      <h:outputText value="Oui" rendered="#{clientController.modifierImage}" /> 
      <h:outputText value="Non" rendered="#{!clientController.modifierImage}" /> 
      </p:outputPanel> 
     <p:outputPanel autoUpdate="true" > 
     <h:outputText value="Logo" rendered="#{clientController.modifierImage}" id="logo" /> 
     <p:fileUpload id="up" fileUploadListener="#{fileUploadController.handleFileUpload}" 
        mode="advanced" 
        sizeLimit="100000" 
        required="true" 
        allowTypes="/(\.|\/)(gif|jpe?g|png)$/" rendered="#{clientController.modifierImage}"/> 
     </p:outputPanel> 
     <p:commandButton action="#{clientController.modifClient()}" value="Modifier" ajax="false"/> 
      </h:form> 
     </ui:define> 

    </ui:composition> 
</body> 

我的問題是,第一次複選框用戶點擊的價值沒有改變和onChangeCheckBox()不wroking。從第二次開始,它工作正常。 注意:我不想在javascript中執行此操作,因爲我根據布爾值複選框完成了其他處理。

這裏是我的控制器:

public void onChangeCheckBox() { 
    System.out.println("modifierImage="+modifierImage); 
} 

/** 
* @return the modifierImage 
*/ 
public boolean isModifierImage() { 
    return modifierImage; 
} 

/** 
* @param modifierImage the modifierImage to set 
*/ 
public void setModifierImage(boolean modifierImage) { 
    this.modifierImage = modifierImage; 
} 

與balusC的解決方案是更好的(它沒有給出一個chcked checkButton當它被點擊了第一次),但問題依然存在!

+0

你可以發佈你的clientController嗎? – 8bitjunkie

+0

控制器的範圍是什麼? – 8bitjunkie

回答

0

我發現,有時候,它取決於在當前頁面之前調用的頁面!我讓他們在ajax =「false」,它工作正常!

0

乍一看,我看不到任何特定的事件和任何組件被重新渲染,那麼作爲10的起動器,這怎麼樣?

<h:form> 
<h:selectBooleanCheckbox value="#{clientController.modifierImage}" > 
       <f:ajax event="click" listener="#{clientController.onChangeCheckBox()}" render="textPanel" /> 
      </h:selectBooleanCheckbox> 
      <p:outputPanel id="textPanel" autoUpdate="true"> 
       <h:outputText value="Yes" rendered="#{clientController.modifierImage}" /> 
       <h:outputText value="No" rendered="#{!clientController.modifierImage}" /> 
      </p:outputPanel> 
</h:form> 

如果需要進一步的幫助,請發佈您的控制器類。

+0

我發現該事件是點擊,而不是onclick,但它仍然不是第一次工作! – ktaria

+2

'onclick'事件不存在。你對HTML元素的'onclick'屬性感到困惑,它應該在'click'事件中觸發一些JS函數處理程序。真正的事件名稱是'click'。 – BalusC

+0

我不知道這是否是回發問題 – 8bitjunkie

0

我有同樣的問題。從我這是阻止更新第一次點擊的<h:form>元素。這怎麼看起來像:

<f:facet name="body"> 
    <h:form> 
     <h:panelGroup id="bodyContainer"> 
     <h:selectBooleanCheckbox title="#{bundle['some.good.text']}" value="#{bean.checkMe}"> 
      <f:ajax render="bodyContainer" /> 
     </h:selectBooleanCheckbox> 
     #{bundle['some.realy.good.text']} 
     <br /> 
     </h:panelGroup> 
    </h:form> 
</f:facet> 

但只要<h:form>除去每一件事情又回到了正常。

相關問題