In struts-config.xml, an action has an "attribute" attribute in it. What's it do? - struts-1

In our web app's struts-config.xml file, there are a bunch of <action>s defined, and they have both a name and an attribute attribute on most of them, with the form name in both. For example:
<action
attribute="LoginForm" <-- this line
name="LoginForm"
path="/welcome"
type="com.foo.presentation.action.LandingActionPre">
<forward name="SUCCESS" path="landing.welcome" />
<forward name="ALREADY_LOGGED_IN" path="/landing.do?m=getLandingPage" redirect="true"/>
</action>
What does the attribute attribute do? Or is it not used and is present here by mistake?
This app has been around for ~10 years, and has seen over 40 programmers touch the code base during that time. So it's possible that one added it to a few actions and every one else copied and pasted it throughout the rest of the app not knowing any better.

According to the Struts 1 doc type definition, it is used as a sort of alias for the ActionForm.
If it's the same as name, it does nothing. But if name is specified and attribute is specified and different from name, then the form can be accessed using the value of either name or attribute.
Relevant section:
<!-- The "action" element describes an ActionMapping object that is to be used
to process a request for a specific module-relative URI. The following
attributes are defined:
attribute Name of the request-scope or session-scope attribute that
is used to access our ActionForm bean, if it is other than
the bean's specified "name". Optional if "name" is specified,
else not valid.

Related

OmniFaces validateOrder disabling

I'm trying to use validateOrder component to validate two java.util.Date objects. It is similar to showcase example on this link (PrimeFaces example). Everything works perfect, but i have one question:
What if 2nd date field is not required?
In that case i'm getting nullpointer exception, and since validateOrder has "disabled" attribute, i was wondering is it worth/possible enabling/disabling it via ajax every time the 2nd date is inserted/removed. If not, i guess i'll stick to Balus' approach for JSF2.0 cross-field validation that you can read about on this link.
Let the disabled attribute check if the 2nd field is filled in. If it's not filled in, the request parameter value associated with field's client ID will be empty. Use exaclty that to let disabled attribute evaluate to true.
<p:calendar ... binding="#{endDate}" />
...
<o:validateOrder ... disabled="#{empty param[endDate.clientId]}" />
Code is as-is. No additional backing bean property necessary for binding.
See also:
How does the 'binding' attribute work in JSF? When and how should it be used?

joomla component save creates a new instance instead of update

I am working on a Joomla 3.0 component built by notwebdesign.com.
In administrator, each time I try to save the data it creates a new instance of data instead of updating the data already loaded in form.
Simple fix. Find the respective form xml file and in this file find the id field as below. Then, just remove the default parameter. It should look like:
<field name="id"
type="text"
default="" // remove this
readonly="true"
class="readonly"
label="JGLOBAL_FIELD_ID_LABEL"
description="JGLOBAL_FIELD_ID_DESC"/>
The id (generally speaking) should not have a default value, so find any occurrences of "id" in your fields parameters. Hope it helps

Struts logic tag to iterate over a list

At this link:
http://www.mkyong.com/struts/struts-logic-iterate-example/
example #2:
they show usage of struts tag to iterate over a List listUsers . But the example shows the List set as an attribute in the request directly. Is it possible to use this tag if the List is an attribute in the corresponding form bean? using the syntax at the link, I get (expectedly):
Cannot find bean: "listUsers" in any scope
If the list is set to the form you need to have following syntax in the iterate tag
<logic:iterate id="myid" name="<nameofform>" property="<listname>">
<bean:write name="myid" />
</logic:iterate>
Form name is the name defines in struts-config.xml.

ASP.NET MVC: how is this possible ? The parameters dictionary contains a null entry for parameter 'x'

I was wondering if someone has a clue of what is happening here, and could point me in the right direction.
Ok ..lets put the code in context.
I have ajax methods (jquery) like this:
$xmlHttp("/Api/GetWaitingMessages", { count: 20 })
.always(processResult);
($xmlHttp simply wraps a jQuery defered, and some basic $ajax options)
And in our healthmonitoring back-office i see things like this:
Exception information:
Exception type: System.ArgumentException
Exception message: The parameters dictionary contains a null entry for parameter 'count' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult GetWaitingMessages(Int32)' in 'AjaxController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
Now the thing is, i placed some traces & try/catches (for testing) to make sure that jQuery never calls GetWaitingMessages with an empty or undefined "count", but as far as the healthmonitoring exeptions go: GetWaitingMessages was instantiated and passed null as a parameter. (from what i understand, MVC instantiates methods via reflection)
btw: the error only happens like maybe 1 out of many thousands of requests
The signature of GetWaitingMessages is:
public virtual ActionResult GetWaitingMessages(int count)
{
....
}
So i suppose, mvc shouldn't even hit the method since there should be no signature match..
Does MVC have problems with high traffic websites (ie. multi-threading problems) ?
The site mentioned above is running on a cluster of 5 web-farm servers with Network Load Balancing and IP affinity.
Each server gets around 1500 request/sec at peak times.
The site is using url rewriting to map domains to areas (ie test.com will simply insert /test into the url) since it's a skinable & multilingual white label site.
Some more details on site configuration:
The controller that serves ajax requests is decorated with
[SessionState(SessionStateBehavior.Disabled)]
HttpModules that where considered useless where removed since we need to run: runAllManagedModulesForAllRequests="true" in MVC. I could have set runAllManagedModulesForAllRequests="false", and then try to figure out what to add, in which order, but found it simpler to just remove what i know is not essential.
<remove name="AnonymousIdentification" />
<remove name="Profile" />
<remove name="WindowsAuthentication" />
<remove name="UrlMappingsModule" />
<remove name="FileAuthorization" />
<remove name="RoleManager" />
<remove name="Session" />
<remove name="UrlAuthorization" />
<remove name="ScriptModule-4.0" />
<remove name="FormsAuthentication" />
The following are all activated and configured in the web.config
<pages validateRequest="false" enableEventValidation="false" enableViewStateMac="true" clientIDMode="Static">
and also:
urlCompression
staticContent
caching
outputCache
EDIT : just analyzed my trace logs a bit more. When the error occurs, i see (Content-Length: 8), which corresponds to (count=20). However i do not see any query parameters in the logs. I dumped the HttpInputStream to the logs, and it's completely empty ..but like i just mentioned, the logs also say that Content-Length = 8, so something is very wrong here.
Could IIS (eventually url rewriting) be mixing up it's stuff somewhere along the way ?
-
Any help would be greatly appreciated ..i'm ripping my hair out trying to understand what could possibly be going wrong here.
Thanks, Robert
What type of a request does your xmlHttp issues to a server (GET, POST or something else)?
What is the definition of GetWaitingMessages action method?
It might very well be the case of mismatching accepted verbs or argument names.
I have a feeling that this could be a problem with MVC not being able to bind to your 'count' parameter. By default, it expects the parameter to be named 'id'.
You can try the following:
Modify your GetWaitingMessages action to define it with a parameter called 'id' instead of 'count'
Create a custom model binding as described in the accepted answer to the stackoverflow question at asp.net mvc routing id parameter
Hope this helps
EDIT: Just saw your reply to another answer stating that the action is a POST. In which case, binding may not be an issue.
Just for testing try this to see if there is any problem .
public virtual ActionResult GetWaitingMessages(FormCollection form)
{
var count=Int32.Parse(form["count"]);
....
}
Of course it will throw if the count field isn't set. If it always works correctly then the problem is with routing or model binding.

Validating double field in struts 2

I have a field "length" in one of my struts 2 form. The data-type of "length" is "double". I have applied the "double" validation in XML file. But when I key-in alphabets in the "length" text field, it shows the error message as
Invalid field value for field "length"
I don't want this message to be shown like this. This message is generated by struts 2 itself and not entered by me. I guess, this message comes as the conversion of data fails. I also applied the "conversion" validator, but the above error message is still showing up. Please suggest the solution.
Thanks in advance.
You're in luck. This text is customizable.
The text is defined in xwork-messages.properties in the xwork jar. You can override it by adding the following to your global i18n resource bundle:
xwork.default.invalid.fieldvalue=Invalid field value for field "{0}".
As you guessed, this error message occurs for all type conversion failures. The XWorkConverter class has some useful javadoc about this:
Any error that occurs during type conversion may or may not wish to be reported. For example, reporting that the input "abc" could not be converted to a number might be important. On the other hand, reporting that an empty string, "", cannot be converted to a number might not be important - especially in a web environment where it is hard to distinguish between a user not entering a value vs. entering a blank value.
By default, all conversion errors are reported using the generic i18n key xwork.default.invalid.fieldvalue, which you can override (the default text is Invalid field value for field "xxx", where xxx is the field name) in your global i18n resource bundle.
However, sometimes you may wish to override this message on a per-field basis. You can do this by adding an i18n key associated with just your action (Action.properties) using the pattern invalid.fieldvalue.xxx, where xxx is the field name.
It is important to know that none of these errors are actually reported directly. Rather, they are added to a map called conversionErrors in the ActionContext. There are several ways this map can then be accessed and the errors can be reported accordingly.
try this,
<field name="percentage">
<field-validator type="double">
<param name="minExclusiveExpression">${minExclusiveValue}</param>
<param name="maxExclusiveExpression">${maxExclusiveValue}</param>
<message>Percentage needs to be between ${minExclusive} and ${maxExclusive} (exclusive)</message>
</field-validator>
</field>

Resources