Duplicate Validation Errors in Struts2 - java

I am using validate() in my Action and here is how my validate() method looks.
public void validate() {
logger.info(".validate() : userName=["+userName+"] & password=["+password+"]");
clearActionErrors();
if(userName==null || userName.length()==0){
addFieldError( "userName", "User Name is required." );
}
if(password==null || password.length()==0){
addFieldError( "password", "Password is required." );
}
}
And in the jsp i added in the section.
The errors are showing up as expected. How ever when i refresh the page i see errors twice. Also if i keep refreshing it the no.of times the error message gets displayed is incremented by 1.
Not sure what's wrong with this.
I tried even calling clearActionErrors(); in my execute() method and that doesn't seem to resolve the Issue.
thanks

If you are using a table on ur jsp to display the form, then make sure that the table is a parent of the form tag. If the table is a child of form tag, the validation messages wont get cleared each time. Making the form tag as a child of table tag would solve your problem.

Related

How to disable JSP error checking in WildFly 10

In my jsp code and there is an input field which I have used the same attribute twice but with different values.( I have used "disabled" attribute twice within <sj:submit/> in below code ). admin and operator are 2 boolean values which are passing from the backend.
<s:set id="admin" var="admin"><s:property value="admin" default="true"/></s:set>
<s:set id="operator" var="operator"><s:property value="operator" default="true"/></s:set>
<sj:submit button="true" value="Submit" name="submit" id="subview" onClick="todo()"
disabled="#admin" disabled="#operator" />
This code worked fine for weblogic server, but this code throws an org.apache.jasper.JasperException exception "jsp.error.attribute.duplicate" when using this code with wildfly 10. This exception occurred because of the 2 "disabled" attributes.Since I have to use both "disabled" attributes and I have used this in many pages, I can not change them one by one. Instead, is there a way to disable jsp error checking when using with wildfly 10 ?
I found the answer to this problem after some researchs. The answer is "there is no way to disable jsp error checking in wildfly 10,in order to avoid getting 'jsp.error.attribute.duplicate' error". If you check the attribute parsing method of undertow-io 'parseAttributes(boolean pageDirective)' ,you can see that, within the attribute parsing method it checks whether this attribute is a unique one or not, by using a 'UniqueAttributesImpl' object named as 'attrs' during the compilation.
Attributes parseAttributes(boolean pageDirective) throws JasperException {
UniqueAttributesImpl attrs = new UniqueAttributesImpl(pageDirective);
reader.skipSpaces();
int ws = 1;
try {
while (parseAttribute(attrs)) {
if (ws == 0 && STRICT_WHITESPACE) {
err.jspError(reader.mark(),
"jsp.error.attribute.nowhitespace");
}
ws = reader.skipSpaces();
}
} catch (IllegalArgumentException iae) {
// Duplicate attribute
err.jspError(reader.mark(), "jsp.error.attribute.duplicate");
}
return attrs;
}
If it found out that this attribute has used more than once, it throws an IllegalArgumentException exception, with the message 'jsp.error.attribute.duplicate'.
This article explains more about this issue.
It's possible to disable such checking by setting
org.apache.jasper.compiler.Parser.STRICT_WHITESPACE=false
in WildFly launch file.

Message Manager displays messages only as field decorators and not in header

I am using the Eclipse MessageManager to provide error messages in case of invalid input. For example:
mmng.addMessage("textLength", "blah", null, IMessageProvider.ERROR, field);
I do this twice. Once inside an instance of ModifyListener and once just right after the creation of the Text field in order to validate input on load.
The MessageManager displays an error in the header of the page as well as next to the text field (decorator) when calling the addMessage method inside the modifyEvent method of an child instance of ModifyListener. However, when adding the message right after the creation of the text field, only a decorator will be displayed (no errors in the header saying that "n errors detected").
I am wondering why this happens. I tested this with the Eclipse ProductEditor and there's actually a similar behavior. The errors won't appear in the header if you open a .product file that has on the first page an error (only the decorator will appear). However, when switching to other pages and then switching back to this particular page, the error in the header will appear. Unfortunately, this is not the case on my side. I would be satisfied if I could implement the same behavior, even though the best case would be to automatically display errors on both locations, in the header and next to the field as a decorator.
I also tried to solve this issue by calling the update() method of the MessageManager instance, but unfortunately, that did not solve the mystery.
By the way, I am using Eclipse Luna 2.
I debugged the MessageManager class and noticed the following condition inside the update method:
if (form.getHead().getBounds().height == 0 || mergedList.isEmpty() || mergedList == null) {
form.setMessage(null, IMessageProvider.NONE);
return;
}
Besides that a NPE will be thrown when mergedList is null, this condition seems really strange to me. However, setting the height of head solved my problem:
form.getForm().getHead().setBounds(0, 0, 0, 1);

Selenium + Java = Assertion error

I already have this kind of error, and I still don't know why. What am I doing wrong?
I need to assert true if I get a text in the page source.
So here is my method:
public boolean AssertSearch() {
return driver.getPageSource().contains("Item found");
}
And here is my assert:
assertTrue(buscarnok.validabuscaNOK());
And I keep receiving the message "Assertion Error". I don't know why. If I change the "return driver.getPageSource().contains("Item found");"to driver.findelement(by.id("someID")).isdisplayed();it works fine, so why isn't it working with getpagesource?
If the text you are looking for is not initially in the page or if it is hidden, it may not find it.
Try something like this:
String bodyText = driver.findElement(By.tagName("body")).getText();
Assert.assertTrue("Item Found", bodyText.contains(text));
You can narrow down the search by selecting a different tag name or even a div by its class or id

oracle adf Valuechangelistener null pointer exception

Hi I am working with oracle-adf using Jdeveloper. I tried to use the valuechangelister
<af:inputText label="#{bindings.CurrentOwner.hints.label}" id="it9"
value="#{bindings.CurrentOwner.inputValue}"
required="#{bindings.CurrentOwner.hints.mandatory}"
columns="#{bindings.CurrentOwner.hints.displayWidth}"
maximumLength="#{bindings.CurrentOwner.hints.precision}"
valueChangeListener="#{bindings.createNewRow1.execute}">
<f:validator binding="#{bindings.CurrentOwner.validator}"/>
</af:inputText>
But when I tried to read it, it returns Null pointer exception on the object e.
public void createNewRow(ValueChangeEvent e){
//get he EmployeeViewImpl class instance
AssetHistoryVOImpl vo=this.getAssetHistory1();
AssetsUserVOImpl assets=this.getAssetsUser1();
System.out.println("one");
// Create new row to insert data
oracle.jbo.Row r_history=vo.createRow();;
oracle.jbo.Row r_assets=assets.getCurrentRow();
System.out.println("two");
String newValue;
newValue = e.getNewValue().toString();// null pointer exception happens here
System.out.println("three");
String test = (String)r_assets.getAttribute("CurrentOwner");
System.out.println("this is test "+newValue);
I have imported the javax.faces.event.ValueChangeEvent. I looked online for many tutorials and this is basically what they did but for some reasons the parameter object is NULL.
Could anyone give some insights?
Thanks :)
Normally the valueChangeListener will point to a managed bean. Try selecting the inputText, then open the Property Inspector in the IDE, then use down arrow to right of ValueChangeListener. Select edit, and you will see a dialog to create a managed bean or point at existing bean. Use the dialog to create a new method. This should wire up your inputText to the method in the bean.
Bear in mind the ValueChangeListener will only get processed via there bean method (per 32U's correct answer) when the page is submitted. If you want the change processed when the input text field loses focus, set autoSubmit = true.

Form submit and HttpServletRequest

I'm facing this problem with regards to Forms and Requests. I'm using sencha and javascript to create a webpage that POSTs a form to a java web application which pulls data from a database and formats it before returning a html page to the client.
The problem I'm facing is that for some reason, while the form does get filled(checked using the debugger in chrome), the java program does not recognise the parameter within the form, and instead reads it as null.
I'm following the method of setting the form from an old java program, which works, however it fails for mine. Does anyone know how I can solve this or where I might be doing wrong?
I've included the javascript and java codes where I decide which page to return below.
Javascript handler for function call to submit form:
var MenuA = function() {
simple.getComponent('flag').setValue('MenuA');
simple.getEl().dom.action = './Soap';
simple.getEl().dom.method = 'POST';
simple.submit();}
Java code to decide choice of page:
if (request.getParameter("flag").matches("MenuA")) {
choice = 2;
} else if (request.getParameter("flag").matches("MenuB")) {
choice = 3;}
FormPanel Code:
var simple = new Ext.form.FormPanel({hidden:true,standardSubmit:true,
items:[
{xtype: 'textfield', hidden: true, name : 'password', label: 'Password', id:'password'}
,{xtype: 'textfield', hidden: true, name : 'user', label: 'user', id:'user'}
,{xtype: 'textfield', hidden: true, name: 'flag', label: 'flag', id: 'flag'}]})
Your
request.getParameter("flag").matches("MenuA");
method is looking for a form element whose name is "flag".
Since your form may not contain the flag field so it assumes it to be null.
So, to overcome you can add an input field to the form with name "flag" and put put your desired value in it.
I think this should work for you.
Nevermind. Found the problem. I didn't realise the form was not being sent properly. Sorry for the trouble!

Categories

Resources