1. start a nested conversation and set em flush mode to manual before showing popup.
@Begin(nested = true, flushMode = FlushModeType.MANUAL)
public void prepareEdit() {}
2. when click save button, end conversation and flush em.
@End
public void saveEdit() {
xxxService.update(WhatEverObjectYouAreEditing);
dbHelperService.flush();
// If the current object needs to updated on session scope, raise event
Events.instance().raiseEvent(eventName, WhatEverObjectYouAreEditing)
// Then the parent action should listen to the eventName, so the object can be reloaded.
}
3. when click cancel button, end conversation and refresh data
@End
public void cancel() {
dbHelperService.refresh(WhatEverObjectYouAreEditing);
}
Couple of things to remember
1. Conversation vs Transaction
- Transaction is not started when conversation starts
- You can only specify transaction will be maintained manually when conversation starts. (That definition will be cleared when conversation ends)
- Transaction will be committed when you execute.
- When transaction ends, dirty object will be cleared if not commited.
2. Flush vs Commit
- When executing a method, you can flush any time.
- Flush updates database to reflect the changes in objects in memory.
: However, it is still not committed yet.
: Unless flushes, database will not see the change.
- When the execution ends, transaction will be commited automatically.
- You can run flush, but cannot run commit
10/21/2010
Seam: Manual Transaction
Create Textarea with maxlength validation
<script type="text/javascript">
function textCounter(fieldstr, countfieldstr, maxlimit){
field = document.getElementById(fieldstr);
countfield = document.getElementById(countfieldstr);
if (field.value.length > maxlimit) {
// if too long, trim it!
field.value = field.value.substring(0, maxlimit);
} else {
// update 'characters left' counter
countfield.value = maxlimit - field.value.length;
}
}
</script>
<h:form id="myform">
<h:inputTextarea id="myarea"
onkeydown="textCounter('myform:myarea','myform:myarea_remline',100);"
onkeyup="textCounter('myform:myarea','myform:myarea_remline',100);"
onfocus="textCounter('myform:myarea','myform:myarea_remline',100);"
disabled="#{disabled}"/>
<br/>
<h:inputText id="myarea_remline" value="100" size="4" maxlength="4" disabled="true"/> characters remaining
</h:form>
s:link, s:button excution order on action and view attribute
s:button and s:link can have both 'action' and 'view' attributes.
When both are given, it will try to excute 'action' first, then 'view' next.
However, if action returns something, it will be forwarded to the 'something'
If, action returns nothing, it will proceed to 'view'.
rule
- 1. execute action
- 1.1 if action returns -> redirect to the page
- 1.2 if action doesn't return -> try to call 'view'
Subscribe to:
Posts (Atom)