Unfortunately, I made a mistake of choosing JSF for an internet facing, high traffic application, now I am wondering as to how to improve the scalability of this JSF webapp.
I have a JSF page that displays a large no of items each of which may be commented upon.
Inorder to reduce the state & improve performance I am trying to reduce the no of forms
/commandButtons
on the page.
1.
Through what ways can I reduce the component tree/ statefulness of JSF ? Do the plain html elements(that are mixed in between the jsf tags) also form part of component tree ? I dont know how component state saving has been helpful to my app since I have been following plain request/response model while designing my app, (may be it is helpful for just JSF's internal requirements)!?
2.
I was thinking of an approach where instead of creating a separate <h:form>
(each with a separate commandButton
) for every item like below,
(Usual Approach)
<h:form> <!-- for each item a separately --> <h:outputText value="Add comment"/> <h:inputTextarea value="#{itemController.comment}" required="true"/> <p:commandButton actionListener="#{itemController.addUserComment(123)}" value="Add" /> </h:form>
(Alternate Approach)
I am trying to make the above better by just putting a single remoteCommand for all the items & pass the required parameters to this remoteCommand.
<form> <input id="item1_comment"/> <button onclick="addComment(123, 'item1_comment');"/> </form> <script type="text/javascript"> function addComment(itemId, id) { $('#comment_in').attr('value', $('#'+id).attr('value')); $('#forItem_in').attr('value', itemId); addComment_RC(); // call remoteCommand to show the content in dialog } </script> <h:form prependId="false" > <!-- for all items, just single remoteCOmmand --> <h:inputHidden id="comment_in" value="#{itemController.comment}"/> <h:inputHidden id="forItem_in" value="#{itemController.forItem}"/> <p:remoteCommand name="addComment_RC" process="@form" actionListener="#{itemController.addComment()}" /> </h:form>
Is it better to do it this way (or are there any issues with this approach)?
execute
attribute off:ajax
– Matt Handy