We are going to implement a scroll effect which will allow to scroll down a textarea on demand as an example.
First of all we are going to create the JavaScript functionality we are going to use:
<script type="text/javascript">you may want to use a more elaborated name to avoid name clashing.
function scrollDown(id) {
ta=document.getElementById(id);
ta.scrollTop=ta.scrollHeight;
}
</script>
Now we are going to create the Java class that would allow us to control the effect from the Java side:
Now you can use this Effect as any other in your code. Just remember that the JavaScript function must be present for the effect to work.
import com.icesoft.faces.context.effects.Effect;
public class ScrollDown extends Effect {
@Override //This annotation is optional but advisable
public String getFunctionName() {
return "scrollDown";
}
}
Enjoy!