Reputation: 1206
I'm trying to implement a solution with TinyMCE and JSF 2.x. I'm not sure however how to go on (different approaches).
What I'm trying to do...
Create user templates (Facelets files) with specific editable areas/sections that someone can edit via TinyMCE after they've logged in.
I dont want to use DB to store the "editable" parts or insert them dynamiclly into the Facelets templates.
I was thinking sommething like this.
Should I use a middle step to pre save the submited content into a Facelets file before I do the change? Any other ideas on how to go on with this would be appreciated!
Upvotes: 1
Views: 365
Reputation: 1109292
I dont want to use DB to store the "editable" parts or insert them dynamiclly into the Facelets templates.
Then your only feasible option is to save them in local disk file system. Note that you can and should not save them in the deploy folder of the WAR, but outside the WAR. Otherwise all changes are simply lost during a redeploy or even a simple server restart. Even more, you won't be able to write files to it when the server is configured to expand the WAR in memory instead of on disk.
Saving files outside WAR is easy. Just write to a FileOutputStream
on this file:
new File("/some/base/path", filename);
Getting Facelets to resolve resources from outside WAR requires a custom ResourceResolver
:
public class MyResourceResolver extends ResourceResolver {
private ResourceResolver parent;
public MyResourceResolver(ResourceResolver parent) {
this.parent = parent;
}
@Override
public URL resolveUrl(String path) {
URL url = parent.resolveUrl(path); // Resolves from WAR.
if (url == null) {
url = new File("/some/base/path", path).toURI().toURL();
}
return url;
}
}
Which needs to be registered as follows in web.xml
.
<context-param>
<param-name>javax.faces.FACELETS_RESOURCE_RESOLVER</param-name>
<param-value>com.example.MyResourceResolver</param-value>
</context-param>
Upvotes: 2
Reputation: 346
I was using the richfaces html editor in a project, but we encountered several issues so we decided to create our own facelet tag which loads the tinymce files that were served up by apache. Works like a charm
Upvotes: 0
Reputation: 12222
Xhtml files are located by default inside WAR. You could deploy exploded WAR and save them in-place. However after redeployment you'd loose all your changes.
You could "hack" JSF to look for templates outside WAR archive but this might be tricky.
Do you need to stick to JSF? Component-based server-side technology is not the best choice. I'd better use some template-based controller-first technology like Spring MVC or Grails for such solutions. Note that in JSF it is XHTML page that controls the flow. It's not just templating technology.
Also note that this is why CMS systems were invented.
Upvotes: 1