dsp:setTransactionRollbackOnly
specifies that when the current transaction ends, it must fail and roll back. This tag does not cause a transaction to roll back now, but rather instructs the transaction to end in a rollback action when it is prompted to end.
The tag’s ability to set the current transaction to setTransactionRollbackOnly
is saved to the named EL variable. You can see tag’s success or failure through the success
property and exceptions through the exception
property.
Attributes
TagVariable:varorid(Required)
You must define an EL variable or scripting variable:
Attribute | Description |
---|---|
| Names an EL variable. When you use |
| Names a scripting variable, which scriptlets and expressions can access at runtime. |
VariableScope:scope
The scope
attribute determines what resources can access the named EL variable. Options include: page
, request
, session
, or application
. Omitting this attribute causes the default, page
, to be used.
Properties
success
The success
property specifies the status of the setTransactionRollbackOnly
operation. A call to isSuccess
returns true.
exception
The exception
property identifies the Throwable
exception object produced when the rollback behavior is not set properly. A call to getException
returns the exception object.
Example
<dsp:beginTransaction var="beginAdvancedAlgebra"/>
…………………………………………………………………………………………………………………………………….
<dsp:tomap bean="/atg/samples/Student_01" var="student"/>
<c:choose>
<c:when test="${!student.passedBeginningAlgebra}"/>
You can't take advanced because you did not pass Beginning Algebra.
<dsp:setTransactionRollbackOnly var="rollbackOnlyXA"/>
<c:if test="${rollbackOnlyXA.exception = !empty}">
The system is having trouble processing this information
for the following reason:
<c:out value="${rollbackOnlyXA.exception}"/>
</c:if>
</c:when>
<c:otherwise>
You may enroll in Advanced Algebra.
</c:otherwise>
</c:choose>
<dsp:commitTransaction var="commitAdvancedAlgebra"/>
In this example, a transaction is used to manage the enrollment process for Advanced Algebra. After the transaction is created, the student’s record is checked for successful completion of the beginning level Algebra class. The beginning level class is a prerequisite for enrolling in the advanced class, so the transactions are set to roll back. If an error occurs and dsp:setTransactionRollbackOnly
does not set the transaction to end in a future rollback action, the exception is displayed. Otherwise, the dsp:commitTransaction
tag tries to end the transaction.