Reputation: 135
I'm developing JSF web application and have some HOW-TO questions. I have the following use-case scenario:
I would like to send encrypted values in generic way. It should be transparent for user. I would like to have a mechanism to mark "encrypt-ready" fields using html attribute eg. encrypt="true".
Data have to be encrypted on the client side because server can't see it in RAW form.
Thanks in advance.
Upvotes: 1
Views: 642
Reputation: 707
Here is an example how it could work with jQuery:
<h:head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</h:head>
<h:body>
<script>
$(function() {
$("form").submit(function() {
$("input[data-encrypt='true']").each(function() {
$(this).val(encrypt($(this).val()));
});
});
$("input[data-encrypt='true']").each(function() {
if ($(this).val()) {
$(this).val(decrypt($(this).val()));
}
});
});
function decrypt(str) {
// to be implemented
return "decrypted value";
}
function encrypt(str) {
// to be implemented
return "encrypted value";
}
</script>
<h:form id="form">
<h:inputText value="#{viewBean.value}" id="val" pt:data-encrypt="true" />
<h:commandButton value="Process" />
</h:form>
</h:body>
You could extract the javascript part in an own .js file and include it in any page you need. Don't forget to define pt namespace:
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"
This solution is not working with f:ajax.
Upvotes: 1