Why is it that for the below code, when I use t:commandButton it works fine and in case of a4j:commandButton it gives NullPointerException on uploadedFile.getInputStream() ?
<h:form enctype="multipart/form-data">
<t:inputFileUpload value="#{fileUploadController.uploadedFile}"/>
<t:commandButton action="#{fileUploadController.insertFile}"/>
</h:form>
Related
I am trying to locate an element <div> in selenium based on its child element.
Sample HTML code:
<html>
<head></head>
<body>
<div>
<div class="class1">Foo</div>
<span>Val1</span>
<h1>Heading1</h1>
</div>
</body>
</html>
Selenium code:
driver.findElement(By.xpath("//div[h1 = 'Heading1']") //Statement1
driver.findElement(By.xpath("//div[h1 eq 'Heading1']") //Statement2
Now, in the selenium code, the Statement1 works fine, but the Statement2 is throwing an exception: org.openqa.selenium.InvalidSelectorException: Given xpath expression is invalid: SyntaxError: The expression is not a legal expression.
Any idea why this exception is thrown ?
Because according to XPath specification the equality expression requires = but not eq. This is why your second statement cannot be parsed.
Weird this one.
On my .NET MVC 4 project I've added a file on App_Code who contains this method:
#helper CheckBox(string name, bool isChecked = false, string className = "") {
<div class="checkboxHolder">
<input id="#name" name="#name" type="hidden" value="#isChecked") />
<i class="#className checkboxBts fa #((isChecked) ? "fa-check-square-o" : "fa-square-o")" data-checkbox-associated="#name"></i>
</div>
}
I'm using it to style checkboxes using font-awesome, so my app checkboxes are made of an input type hidden who stores a boolean value and an icon to give feedback to users.
Weird thing is, on executing when isChecked == false, the hidden returned by this method is like:
<input id="myCheckboxId" name="myCheckboxId" type="hidden" />
There is no value at all, when I try to save it to the model an exception is thrown saying that model cannot be saved.
I've fixed it changing the method to use:
<input id="#name" name="#name" type="hidden" #((isChecked) ? "value=true" : "value=false") />
Which is working fine. However, I wonder if anyone know what could be happening on the original output.
Thank you all.
It's not entirely a duplicate, but this is answered in Why is my hidden input writing: value=“value” instead of true/false?:
if you have:
<input name="somefield" type="hidden" someprop="#(SomeBooleanExpression)"/>
[and #SomeBooleanExpression] is false it is omitted completely:
<input name="somefield" type="hidden"/>
To get around this, consider .ToString()
So, use:
<input id="#name" name="#name" type="hidden" value="value="#(isChecked.ToString())" />
I am trying to get CAPTCHA working on the eForm plugin. I have added the input form field:
<label for="cfCaptcha">Captcha:<br />
<img src="[+verimageurl+]" alt="verification code"><br />
<input id="vericode" name="vericode" class="text" type="text">
and I have added
&vericode=`1`
to the eForm call.
and have added the Template Variable [+verimageurl+] to my template.
However, when I preview the form all I see in the image area is <img src="" alt="verification code">
Would anyone know what I am doing wrong?
Did you get this fixed?
Check that you ended the label code. Run it through w3c code checker too.
A few times I have left a element un-closed and it breaks the whole thing.
When I create a model I would like to save images for a model. I am using PrimeFaces fileUpload component. When I save pictures I want to know to which model particular image refers to. That's why I need to send id of a model to backing bean.
Is there any possibility to send id of model to fileUploadListener?
<h:form enctype="multipart/form-data">
<p:panelGrid columns="2">
<h:outputLabel for="hotelName" value="#{msg.hotelName}"/>
<p:inputText value="#{apartmentNew.name}" id="hotelName"/>
<h:outputLabel for="hotelDescription" value="#{msg.hotelDescription}"/>
<p:inputText value="#{apartmentNew.description}" id="hotelDescription"/>
<h:outputLabel for="hotelImages" value="#{msg.hotelImages}"/>
<h:form enctype="multipart/form-data">
<p:fileUpload id="hotelImages"
fileUploadListener="#{apartments.handleImageUpload}"
mode="advanced"
sizeLimit="10000000"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/">
</p:fileUpload>
</h:form>
</p:panelGrid>
<p:commandButton id="saveApartmentButton" value="#{msg.save}" action="save"/>
<p:commandButton id="cancelCreationApartmentButton" value="#{msg.cancel}"
action="cancel"/>
</h:form>
Not via request parameters. You can do so via component attributes.
E.g.
<p:fileUpload ...>
<f:attribute name="foo" value="bar" />
</p:fileUpload>
with
String foo = (String) event.getComponent().getAttributes().get("foo"); // bar
I needed to pass a key parameter along with the uploaded file. I found that fileUploadListener executes during the APPLY_REQUEST_VALUES phase, so I could not use an EL expression in the f:attribute tag. I also tried to find the value using event.getComponent().findComponent("id"), but although the component was present, the value was null. I think a #ViewScoped bean would fix the missing value, but I am stubbornly attempting to keep my beans at #RequestScoped until I have absolutely no other option. Ultimately, I had to use FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id") which I got from http://forum.primefaces.org/viewtopic.php?f=3&t=6432
Error in types:
String foo = event.getComponent().getAttributes().get("foo");
Instead, do it this way:
Object foo = event.getComponent().getAttributes().get("foo");
Integer foo = (Integer) event.getComponent().getAttributes().get("foo");
You can use:
<div onclick="#{myBean.myMethod(myParam)}" >
<p:fileUpload id="fileUpload" fileUploadListener="#{myBean.onFileUplod}" mode="advanced" dragDropSupport="true"
update=":messages" process="#this" >
</p:fileUpload>
</div>
Method in myBean:
public void myMethod(String myParam) {
selectedMyParam = myParam;
}
Then you can use selectedMyParam in onFileUpload method.
I am currently experiencing a bug that only occurs in the current version of Safari (5.1.5) and was wondering if anyone here could come up with any workarounds for it. I tested it in 5.1.2 and it worked fine there, I'm not sure about 5.1.3 and 5.1.4 as I don't have access to those releases.
The bug requires three pages, I'll show the source of them and then explain what is going on:
FirstPageWithForm.htm
<form id="theForm" action="ActionHandler.ashx" method="post">
<input type="hidden" name="differentField" value="1234"/>
<input type="hidden" name="sameField" value="1111"/>
</form>
<script type="text/javascript">
var theForm = document.getElementById("theForm");
theForm.submit();
</script>
SecondPageWithForm.htm
<form id="theForm" action="ActionHandler.ashx" method="post">
<input type="hidden" name="differentField" value="5678"/>
<input type="hidden" name="sameField" value="1111"/>
</form>
<script type="text/javascript">
var theForm = document.getElementById("theForm");
theForm.submit();
</script>
ActionHandler.ashx
public void ProcessRequest(HttpContext context)
{
var referrer = context.Request.UrlReferrer;
var differentField = context.Request["differentField"];
context.Response.Write(differentField);
if (differentField == "1234")
{
if (referrer.ToString().Contains("Second"))
context.Response.Write("Failure");
else
{
context.Response.Redirect("SecondPageWithForm.htm");
}
}
else
context.Response.Write("Success");
}
As you notice both forms have the same field name but one of the fields has a different value. However, in Safari when this code is run, the value "1234" is sent as differentField instead of "5678". I do not believe this bug has anything to do with .NET but I don't have an easy way to test another language to be sure about that.
Things I already tried:
Putting the form submission code in a function and then calling that.
Requiring Jquery and calling it in the $(document).ready() function.
Putting the function call in a setTimeout().
Replacing the function with a button that I press.
Copying the Handler and sending the second form to the copy instead.
Every single one of these methods had the same effect, which is to print "Failure" instead of Success.
I will be filing this bug on the Safari forums (I don't have an Apple Developer account and it's not working to create a new one at the moment), but I was hoping that someone could help me come up with a suitable workaround for this problem until they fix it.
EDIT: The Safari forum bug report: https://discussions.apple.com/thread/3921507
NicolasIgot on my safari forum figured out a solution to my problem.
I just added autocomplete="off" to the form tag on the second form and everything started working again. I haven't tried it on my real problem, but it works on my simple test case, so I have confidence in it.