top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Validation for field with dynamic field name in struts 2.2.3

+1 vote
822 views

I am using struts 2.2.3 and doing client side validation using xml. I want to do validation for a field whose name is an ognl expression I have something like this :

Field is required

On debugging I can see It is adding field error properly. But i have a javascript which shows the field in red highlighted color and also shows messages that "fieldname is required". However fieldname is not coming in the message and it is not showing the required field in red highlighted color.

The same javascript code works fine for normal fields which have static name. Please can someone help in this, as I am new to struts ?

posted Jul 7, 2013 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
+2 votes

I have a couple of old struts 2 apps that are using 2.2.1. I want to upgrade them to 2.3. What is the minimal set of jar files I need in WEB-INF/lib?

I currently have:
commons-beanutils-1.7.jar
commons-collections-2.1.jar
commons-digester-1.7.jar
commons-fileupload-1.2.1.jar
commons-io-1.4.jar
commons-javaflow-20060411.jar
commons-lang-2.5.jar
commons-logging-1.0.4.jar
freemarker-2.3.16.jar
ibatis-2.3.2.715.jar
itext-1.3.1.jar
jasperreports-2.0.5.jar
javamail.jar
javassist-3.8.0.GA.jar
jdt-compiler-3.1.1.jar
jstl.jar
jxl-2.6.jar
log4j-1.2.14.jar
ognl-3.0.jar
poi-3.0.1-FINAL-20070705.jar
spring.jar
standard.jar
struts2-core-2.2.1.jar
struts2-jasperreports-plugin-2.0.11.1.jar
urlrewrite-3.2.0.jar
xalan.jar
xercesImpl.jar
xwork-core-2.2.1.jar

0 votes

I am trying to implement an auto complete feature using Struts 2 jQuery plugin - . The suggestion list need to be dynamically retrieved from backend based on the characters user entered. Is it possible to implement this behaviour using S2 jQuery plugin? Does anyone has a good example?

I could not find such an example in showcase.

+1 vote

I am in the process of upgrading my struts2.3.1.2 application to struts2.3.15.1. Everything works fine except the and tags. In struts2.3.1.2, I have the following code in jsp file

  %{stateName}
  Add 

I used to get correct state name when using struts2.3.1.2. However, using struts2.3.15.1, I am getting the following on web-browser page: %{stateName}

0 votes

In the context of an tag, for instance for a login action, we previously always coded forms as :

 ....

And in the struts.xml we have been using :

content.login
 content.menu
 summary_input
 welcome

This has worked in the past and allowed us to not only use the action="login" to target the execute method of the action, but also to build links to, for instance, login_checkStatus.action to target other, specific methods within the action. I am not sure this Is a common/best practice, I had no prior struts2 experience before joining this company and this is how a lot of the existing functionality is coded. (If this is wrong/there is a better way, please let me know)

Now randomly, this fails to generate the proper action url in the html (it is missing the '.action', which results in a 404 once you post the form)

The only workaround we have found so far is to add the '.action' suffix to the
s:form's action attribute. Before it was always added for us by struts.

So now we are having success with

 ...

I can only assume that this has been affected by the changes related to S2-015 and the wildcard action matching.

+2 votes

I can't see what's going on behind the scenes in this example so I'm asking for help in order to understand the Strtus process.

I run the example, leave empty "First Name" to make validation fail, and submit. Then go back to index:

http://localhost:8084/form_xml_validation

and click on edit. But "First name" is reset with the original value. It should be empty because Person instance is managed statically. In fact, other examples (preparable, exclude params) behave as expected, and return an empty String for the filed left empty.

The thing here is than I'm not understanding how Struts works here. I would appreciate if you help me with this.

Example is here:
http://struts.apache.org/release/2.3.x/docs/form-validation-using-xml.html

Code for checkout here:
http://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2examples/

Examples doing as expected:
http://struts.apache.org/release/2.3.x/docs/exclude-parameters.html
http://struts.apache.org/release/2.3.x/docs/preparable-interface.html

...