Basically I have a list of records. Each record (the VO bean) will have an alert flag, alertFlag
, attached to it. When the alertFlag is true, an alertbox will be prompt. Otherwise it wouldn't prompt.
The VO bean:
@ManagedBean(name = "theVo")
@SessionScoped
public class TheVO {
private boolean alertFlag;
/** getter and setter **/
}
Here is the XHTML code:
<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>
Here is theEnquiry
bean:
@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
}
}
Here is the JavaScript code:
function readAlertFlag(alertFlag) {
if( alertFlag == "true" )
alert('alertFlag is true');
else
alert('alertFlag is false');
}
My current situation is the JavaScript alert box will always execute first then only doSetAlertFlag()
get executed. But my expectation is to execute doSetAlertFlag()
first because I want the checking to be done first before prompting. If this can't be done on JavaScript prompt, I'm open to alternative solution.
Let JSF render the script conditionally. Replace the onclick
by a <h:outputScript rendered>
.
<h:commandLink ... />
<h:outputScript rendered="#{theEnquiry.alertFlag}">showAlert()</h:outputScript>