0

基本上我有一个记录列表。alertFlag每条记录(VO bean)都将附加一个警报标志 , 。当 alertFlag 为 true 时,会提示一个警告框。否则不会提示。

VO 豆:

@ManagedBean(name = "theVo")
@SessionScoped
public class TheVO {
   private boolean alertFlag;

   /** getter and setter **/
}

这是 XHTML 代码:

<t:dataTable var="theRecord" value="#{theVo.theList}">

  <t:column>
    <h:commandLink value="#{theRecord.recNo}" 
      actionListener="#{theEnquiry.doSetAlertFlag(theRecord.paramKey)}" 
      immediate="true" 
      action="#{theDetail.doShowDetailsPage(theRecord)}" 
      onclick="readAlertFlag(#{theEnquiry.alertFlag})"/>
    </h:commandLink>
  </t:column>

  ...
  ...
</t:dataTable>

这是theEnquiry豆:

@ManagedBean(name = "theEnquiry")
@SessionScoped
public class Enquiry {

   private boolean alertFlag = false;

   /** getter and setter of alertFlag **/

   public void doSetAlertFlag(Integer theParamKey) {

      // check whether the alert flag is true or false.
      // if alert flag is true, otherwise set it false
   }
}

这是 JavaScript 代码:

function readAlertFlag(alertFlag) {

  if( alertFlag == "true" )
    alert('alertFlag is true');
  else
    alert('alertFlag is false');
}

我目前的情况是 JavaScript 警告框总是先执行然后才被 doSetAlertFlag()执行。但我的期望是先执行doSetAlertFlag(),因为我希望在提示之前先完成检查。如果这不能在 JavaScript 提示符下完成,我愿意接受替代解决方案。

4

1 回答 1

0

让 JSF 有条件地渲染脚本。将 替换onclick<h:outputScript rendered>

<h:commandLink ... />
<h:outputScript rendered="#{theEnquiry.alertFlag}">showAlert()</h:outputScript>
于 2012-10-25T11:29:21.760 回答