I do not understand that when I press save in the form below I save the current contents of the inputTextArea, but when I want to look at a preview of the contents of inputTextArea I see the contents of the last saved mail template. What I should see is of course the current value of the textArea (after it is converted). Why does it not show the updated value of customMailTemplate?
<h:form id="gameMailForm" prependId="false" rendered="#{customizeGameMailBean.renderGameMailPanel}">
<h:panelGrid columns="3">
<h:inputTextarea
styleClass="gameMailTextArea, textArea"
id="gameMailTextArea"
value="#{customizeGameMailBean.customMailTemplate}"
converter="gameMailTemplateConverter"
style="height: 120px; width: 300px; font-size: 11px;">
<f:validator validatorId="gameMailValidator"/>
</h:inputTextarea>
<p:commandButton value="Save"
action="#{customizeGameMailBean.saveMailTemplate}"
ajax="false"/>
<p:commandButton value="Preview"
ajax="true"
action="#{customizeGameMailBean.doNothing}"
oncomplete="javascript: window.open('gameMailPreview.jsp','Game Email','width=300,height=300')"
immediate="true"/>
</h:panelGrid>
</h:form>
gameMailPreview.jsp:
<%#page import="wmc.web.controller.CustomizeGameMailBean"%>
<%#page import="javax.faces.context.FacesContext"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<% CustomizeGameMailBean gameMailBean = (CustomizeGameMailBean) request.getSession().getAttribute("customizeGameMailBean");%>
<%=gameMailBean.getCustomMailPreview()%>
Is something maybe wrong about the timing?
By the way game doNothing is really doing nothing. It is an empty void method.
The problem is that the second command button has its immediate attribute set to true. This will cause the action method to be invoked in the apply request values phase, and thereafter skip immediately to render response.
In effect, no model values will be updated, thus you keep having the previous values in the model. Confusingly maybe, but the component will retain the value you just entered. I just didn't transfer to the model. For more information about this look up what the immediate attribute means in JSF and especially what it does when applied to a command button.
(I also would like to remark that using the session scope to communicate values to a popup is asking for trouble. This opens the door to all kinds of race conditions when the user has the page opened in multiple tabs or windows. If possible, you might be better off using Java EE 6's conversation scope.)
Related
I am using JSF 2.2, PrimeFaces and Glassfish and I have this:
<h:form id="formularioAltas">
//more code
<p:commandButton value="Guardar" action="#{altasBean.agregarRefaccion()}" />
</h:form>
<h:form id="myForm" enctype="multipart/form-data" prependId="false" rendered="#{altasBean.estado}">
// more code here
</h:form>
And I need formularioAltas to tell myForm that the value of the boolean property estado has changed. I uderstand it like doing a simple update to myForm when the commandButton is executed but that cant be cause they are in diferent forms. I needed this way cause I have problems uploading files to the server so I decided to use two different forms. I have working this forms but I want to show only myForm when the commandButton is executed.
Any ideas?
<p:commandButton value="Guardar" action="#{altasBean.agregarRefaccion()}" update=":myForm" />
: because you climb the container hierarchy one step up to the container which contains both forms and myForm because that's her name.
I have a really weird and stupid problem that has be stopped dead. I have numerous xhtml pages that use forms and they all work fine. I created a new xhtml page called registerUser.xhtml. I created it by right clicking on "Web pages" folder and selecting new > xhtml page as I have done for the other half a dozen pages. I put in my code and when I go to view the page in a web browser, it shows nothing. If I view source, it shows the JSF tags, NOT the html. If I put any code or just plain text outside of the form tags, it displays so its something with the form tag. Even If i take a perfectly working page and copy/past into this new page, it still does not work.
Here's one thing that I noticed,
Typically when I create a c:, h: or f: tag for the first time in a page, I get an error saying its not bound, then I single click on it and hit alt-enter and it gives me the option to add something, which adds the xlmns:h to the html tag. I don't fully understand how that works but its something with namespaces...anyway, for whatever reason that option doesnt show up...the only option that shows up is "Remove surrounding tag" which obviously does not fix my problem if i actually click it.
So no big deal that it doesnt auto-add the xmlns, I can add that myself, copying exactly what I have on another page...but nope, still nothing. Why doesnt this work?
I've tried creating numerous new xhtml files in this project and the result is the same on form elements, nothing inside is rendered and it shows that error.
All my previous pages work fine. I've read on the internet about changing WEB-INF files but it doesnt make sense that I should have to since my already-existing pages work, its just new pages and nothing has changed recently that I'm aware of.
I should also point out that I did a right click copy/paste within the projects window of my index.xhtml file which works totally fine and then when I run the project, index.xhtml loads up fine but when I manually navigate to index_1.xhtml (which is the pasted version), none of the JSF is rendered.
registerUser.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<head>
<title>Jadestar's PC Solutions</title>
</head>
<body>
<h:form>
<h:panelGrid>
<h:outputLabel value="Username: " style="font-weight:bold" />
<h:inputText value="#{CustomBuild.username}" />
<br></br>
<h:outputLabel value="Password: " style="font-weight:bold" />
<h:inputSecret value="#{CustomBuild.password}" />
<br></br>
<h:outputLabel value="Name: " style="font-weight:bold" />
<h:inputText value="#{CustomBuild.name}" />
<br></br>
<h:outputLabel value="Address " style="font-weight:bold" />
<h:inputText value="#{CustomBuild.address}" />
<br></br>
<h:outputLabel value="Phone Number: " style="font-weight:bold" />
<h:inputText value="#{CustomBuild.phone}" />
<br></br>
<h:outputLabel value="Email Address: " style="font-weight:bold" />
<h:inputText value="#{CustomBuild.email}" />
<br></br>
</h:panelGrid>
<h:commandButton id="register" value="Reigster" action="#{CustomBuild.registerUser()}"/>
</h:form>
<br></br>
<h:form>
<h:commandButton id="cancel" value="Cancel" action="index" />
</h:form>
</body>
</html>
So after copying and creating a ton of new projects and doing a lot of research, I found out that if I made a new web project, the index.xhtml page would also work fine but any new pages created in THAT project would also fail to render JSF tags. I finally found out the issue. In my web.xml in the WEB-INF directory, I was missing the following line.
<url-pattern>*.xhtml</url-pattern>
Which is inside the tag.
So by adding this, suddenly my new jsf pages are now working...but my question remains, how are my current pages working without this tag and not new ones? It doesnt make sense.
Cache issue? Enabled console in chrome and "empty cache and hard reload" and still the same result so it can't be cache, can it?
I should mention that about half way through this project, I updated from Netbeans 7.x.x, Java 7.x and Glassfish 3.x to Netbeans 8, Java 8 and GlassFish 4. Since everything was still working with my current pages after this upgrade, I assumed this wasn't the cause but perhaps something in there broke?
Would be nice to hear from someone who either has an explanation or had a similar problem
So I have an anchor element, and it's href attribute is set dynamically from the bean. I am using an anchor since it is interacting with fancybox javascript. What I need to have happen is to call a method in the bean when the anchor is clicked so that the href will update again. There is a textbox above that is also bound to bean. What needs to happen is to take the text from the text box, and parse that into a query string for the anchor's href.
I'm trying to figure out the best way to have this happen (if it is possible). Would I be able to use javascript (or Ajax) to call an updateHref() method?
The textbox and anchor element (it's ModelBean.ending that needs to be updated):
<h:inputTextarea value="#{ModelBean.tweet}" class="textarea.hs-input #{ModelBean.tweetClass}" style="width:200px;" >
<f:facet name="label">
Tweet
</f:facet>
</h:inputTextarea>
</td>
</tr>
<tr>
<td>
<h:commandButton value="Analyze Tweet" class="hs-button orange" action="#{ModelBean.tweetAnalysis()}" />
</td>
<td>
<a href="https://app.hubspot.com/social/#{ModelBean.hubID}/publishing/compose_bookmarklet?body=#{ModelBean.ending}" class="hs-button primary fancybox-iframe" data-fancybox-type="iframe" >
Tweet it!
</a>
</td>
</tr>
Here's the bit of java that would need to be called:
ending = URLEncoder.encode(tweet, "UTF-8");
ending = ending.replaceAll("\\+", "%20");
If you think any other part of the code would be useful please let me know! And thanks in advance for any suggestions!
If you use JSF 2.0, f:ajax tag may solve your problem. Here is sample usege of f:ajax tag,
<h:commandLink value="#{..}">
<f:ajax execute="name" render="output" />
</h:commandLink>
<h:inputTextarea id="output" value="#{..}" />
execute=”name” – Indicate the form component with an Id of “name” will be sent to the server for processing. For multiple components, just split it with a space in between, e.g execute=”name anotherId anotherxxId”. In this case, it will submit the text box value.
render=”output” – After the Ajax request, it will refresh the component with an id of “output“. In this case, after the Ajax request is finished, it will refresh the h:inputTextarea component.
I have issue with canceling Ajax Request. Our application interface is build in RF.
On the progress bar modal there should be cancel button - that interupt current operation,
for example cancel filling controls from database. How to make it?
I tried using reloading page, flags with "if" conditions on getters for controls and also using "bypassUpdates" with no positive effects.
Thanks in advance for your help
XHTML (Button):
<a4j:commandButton id="showData"
value="View" styleClass="hBtn"
disabled="#{events.isButtonsDisabled}"
oncomplete="if (#{facesContext.maximumSeverity==null})
{window.open('/seed/pages/data.jsf','DATA')};"
actionListener="#{events.actionShow}"/>
JAVA: (Button):
public void actionShow(ActionEvent evt) {
//Some logic, getting data from database
}
XHTML (Main Page - showing wait Popup)
<a4j:form>
<a4j:status id="ajaxStat"
onstart="Richfaces.showModalPanel('waitPanel');"
onstop="#{rich:component('waitPanel')}.hide()" />
</a4j:form>
XHTML (Popup):
<rich:modalPanel id="waitPanel" autosized="true" moveable="false"
minWidth="250" styleClass="popup">
<f:facet name="header">
<h:panelGroup>
<h:outputText value="Operation in progress"></h:outputText>
</h:panelGroup>
</f:facet>
<f:facet name="controls">
<h:panelGroup>
<h:graphicImage value="../images/icons/action_close.gif" styleClass="hidelink" id="hidelink"/>
<rich:componentControl for="waitPanel" attachTo="hidelink" operation="hide" event="onclick"/>
</h:panelGroup>
</f:facet>
<a4j:form id="msgFrm" ajaxSubmit="true">
<h:outputText value="Please wait..."/>
<h:graphicImage styleClass="progressBar" value="../images/indicatorbar.gif"/>
<a4j:commandButton value="Cancel" type="button"
onclick="#{rich:component('waitPanel')}.hide()"
action="#{main.cancelAction}"
bypassUpdates="true"/>
</a4j:form>
</rich:modalPanel>
JAVA (Popup):
public void cancelAction(){
//there was setter for true/false flag for actionShow() here, now there is nothing here (it was not working)
}
Reloading the page stops all current ajax requests. It does not stop the java backing beans from finishing the requests but I assume that is not the question.
c:if and the ajax render do not mix very well. Possibly you could use 'rendered' to disable updating the controls? Then split the control in two parts. One is shown with valid data and for example bright blue. The other is rendered without any data and has a grey picture.
But... I'm not sure I understand the question correctly.
Edit 23-1-2012: Seeing the code I would say that the cancelAction must set a flag that then finishes the action running inside actionShow(). Then the ajax request finishes and the popup is closed. Can't see why this won't work.
EDIT
Cant seem to get rendered to work correctly with update attributes. Here is my codes
<ui:define name="left">
<h:form>
<p:commandLink value="Hey"
actionListener="#{bean.setRenderComment}"
update="comment"/>
</h:form>
</ui:define>
<ui:define name="right">
<h:panelGroup id="comment" rendered="#{bean.renderComment}">
hello
</h:panelGroup>
</ui:define>
renderComment is a boolean attributes inside bean. setRenderComment basically toggle the state of renderComment like this
this.renderComment = !this.renderComment;
Right, every time I click on the link Hey, I need to refresh to either render hello on or off. How can I fix it, so that I dont need to refresh
I am not using Primefaces but Richfaces on my projects. So I am not really aware on how the refresh process is done by Primefaces. However, I have an idea that can be tested easily.
Your problem may be due to the fact that the component to re-render (i.e. update) is not found on the HTML page. If your rendered attribute is equals to false, then the <SPAN> with comment id is not integrated in the HTML page generated. Thus, when the Ajax request is received on the client side, the Ajax engine is not able to refresh this <SPAN> as it is not found.
So what you can do is to always render your panelGroup and move your rendered attribute to a nested <h:outputText> that contains the Hello message.
Here is what I am suggesting:
<h:panelGroup id="comment">
<h:outputText value="Hello" rendered="#{bean.renderComment}"/>
</h:panelGroup>
This way, the panelGroup will always be refreshed after the Ajax call, and it will contain the Hello message or not, regarding the value of the renderComment attribute of your bean.
Since the component with the ID comment isn't one of the form's (an UINamingContainer component) children, you need to prefix the ID with : to instruct JSF to scan from the "upper level".
This should do:
<p:commandLink value="Hey"
actionListener="#{bean.setRenderComment}"
update=":comment" />