What are <required> and <rtexprvalue> used for? - java

I was working on custom tag libraries and I was confused how the <required> and <rtexprvalue> tags are used in the TLD file to define a custom tag attribute.
What are these tags?
What should we write in-between them?
What behavior do we get after writing these tags?

required quite simply implies what it says. The attribute is required or mandatory.
rtexprvalue means Runtime Expression Value. It means the attribute can support scriptlet values.
elexprvalue means it can support EL (expression language) values.
So, if you have requiredattr defined as both required=true and rtexprvalue=true and elattribute is defined as elexprvalue=true, you can write as follows:
<myprefix:mytag requiredattr="<%=baz.getId()%>" elattribute="${foo.bar}"/>

The <rtexprvalue> element defined in a TLD captures the dynamic behavior of an attribute. The
value can be either true or false. A false value in the dynamic column means that
only a static string value can be specified for the attribute. A true value means that a
request-time attribute value can be specified. As defined in the JSP specification, a
“request-time attribute value” can be either a Java expression, an EL expression, or a
value set by a <jsp:attribute>.
The <required> element defines if the nesting attribute is required or optional. If not present then the default is "false", i.e the attribute is optional.

Related

What are the allowed "Default Value Literal" for an EList-typed EAttribute in an EMF Ecore model?

I want to build an .ecore model. I am using Eclipse Neon. in Design mode, I have a class and inside the class I have few attributes. when I set type of the attribute to EEList<E> [org.eclipse.emf.common.util.EList], I can't set the Default Value Literal. I don't know what is the valid value.
To answer your question, it seems you cannot set a default literal value for ELists. Or at least I could find no reference to it in any documentation, nor in the code.
For what purpose are you defining an EAttribute of type EList ? If you simply want a multi-valued feature (e.g. List) you should instead have an EAttribute of type X with multiplicity [0..*].

Spring #RequestMapping value explicit/implicit

In some cases I have seen two different ways to specify uri in #RequestMapping:
#RequestMapping(value="/somepath")
#RequestMapping("/somepath")
The latter is often used at class level. So, is it always legal omitting the value attribute?
The Java Language Spec states
It is legal to use single-element annotations for annotation types with multiple elements, so long as one element is named value, and all other elements have default values.
Since #RequestMapping has a defined value attribute and all other attributes have default values (empty arrays), it is always legal to omit spelling the name value if you don't specify any other attributes for the annotation:
#RequestMapping("/somepath") // valid
#RequestMapping("/somepath", method = RequestMethod.GET) // INVALID!
For #RequestMapping annotation value is the primary attribute, it is mandatory.
1)#RequestMapping(value="/somepath"):
Here you can mention remaining attributes, for ex: method,produces
2) #RequestMapping("/somepath"):
Here you can not mention rest of the attributes, as by default "/somepath" will be taken as value attribute.
Check this

How to pass multiple parameters using html link in Struts1.x

I am trying to pass multiple parameters to my Struts action class using <html:link> property.
I am having a link, it should take two parameters from the JSP page to my action class.
How to achieve this?
In Struts 1.3 parameters could be set to the action attribute like in this example
<html:link action="/path/to/action?param1=2&param2=${param2Value}">Some text</html:link>
Quote from the documentation:
If you prefer to specify a java.util.Map that contains all of the request parameters to be added to the hyperlink, use one of the following techniques:
Specify only the name attribute - The named JSP bean (optionally scoped by the value of the scope attribute) must identify a java.util.Map containing the parameters.
Specify both name and property attributes - The specified property getter method will be called on the bean identified by the name (and optional scope) attributes, in order to return the java.util.Map containing the parameters.
As the Map is processed, the keys are assumed to be the names of query parameters to be appended to the hyperlink. The value associated with each key must be either a String or a String array representing the parameter value(s), or an object whose toString() method will be called. If a String array is specified, more than one value for the same query parameter name will be created.
Supplmenting these two methods, you can nest one or more tags to dynamically add parameters in a logic-friendly way (such as executing a for loop that assigns the name/value pairs at runtime). This method does not compete with the aforementioned; it will adds its parameters in addition to whatever parameters are already specified.
You can also use a regular HTML <a> tag and create the URL using the standard <c:url> tag from the JSTL.
why don't you go with ajax calling ? by using ajax you can pass many parameter to action class by set the method K

GWT Element setAttribute vs setPropertyString

I can't determine the difference between Element.setAttribute(String name, String value) and Element.setPropertyString(String name, String value). Is there a difference? Which is preferred when attempting to set, say, a placeholder on a text input? I've been doing getElement().setPropertyString("placeholder", "this is a placeholder"); and it works, but is that the appropriate way to do it?
In the documentation for DOM, setAttribute(Element, String, String) is deprecated, saying to use "the more appropriately named setElementProperty(Element, String, String) instead." Does that imply that one should be using the similarly named methods of Element?
There is a difference between Attributes and Properties. In short the attribute represents the initial state while the property always represents the current state.
See http://jquery-howto.blogspot.com/2011/06/html-difference-between-attribute-and.html for a detail explanation.
In GWT calling setAttribute calls the native javascript function setAttribute on the current element. Calling setProperty... set the property on the current element.
In the past this in most browsers this used to be the same, but with evolving standards this started to change ago.
I don`t really know all the small differences between browser implementations, but to track the difference one could rely on the different DOM Level Specs: http://www.w3.org/TR/DOM-Level-2-HTML/ http://www.w3.org/TR/DOM-Level-3-Core/
Also the Mozilla docs are on setAttribute are quite could and state the difference for firefox: https://developer.mozilla.org/en/DOM/element.setAttribute
So in summary: if you use setAttribute in GWT you rely on the browser setAttribute implementation which is somewhat setting the defualt value (on certain properties, and not updating a value), so normally you want setProperty...
The problem is that in IE6 and IE7 (and IE8 in compatibility modes), setAttribute actually sets the property (IE doesn't really make a difference; IE8 added an optional argument to getAttribute to allow retrieving the attribute as defined in the DOM spec; see http://msdn.microsoft.com/en-us/library/ms536429v=vs.85.aspx).
BTW, your JavaDoc reference should be http://google-web-toolkit.googlecode.com/svn/javadoc/latest/index.html (not the one for GWT 1.5, which is severely outdated), and you should use com.google.gwt.dom.client.Element rather than com.google.gwt.user.client.DOM. Element has a setAttribute that sets the attribute in every browser other than IE6/7 (or similar modes of IE8).
But most of time, you should just work with DOM properties, rather than attributes. For instance, you want to get the tab index as a number, not as a string. And you want the default value/state for a property in the absence of the attribute, not a null that you'd have to handle yourself (e.g. an input element defaults to type=text when there's no type attribute; getAttribute("type") would return null whereas getPropertyString("type") would return "text").

Is 'value' a java keyword?

It seems to have a special meaning in annotations - it allows you to skip the parameter names when instaniating an annotation.
#Foo(bar = "abc") // a normal instantiation of an annotation
#Foo("abc") // if bar were renamed 'value'
Where is this documented? Is value a keyword or not? See also.
It's not a regular keyword, as it's not listed in section 3.9 of the JLS. In particular, you can use it as an identifier anywhere you like, as far as I'm aware.
The use of value by default for an annotation value is specified in section 9.7:
The third form of annotation, single-element annotation, is a shorthand designed for use with single-element annotation types:
SingleElementAnnotation:
# TypeName ( ElementValue )
It is shorthand for the normal annotation:
#TypeName ( value = ElementValue )
No, value is not a keyword in Java. If only one parameter is given to an annotation and that annotation only has one element that is called value, then the name value can be omitted when using the annotation. Annotations are explained here:
http://download.oracle.com/javase/1.5.0/docs/guide/language/annotations.html
And documented in section 9.7 in the JLS:
value is the default field into which annotation data is placed. value however is not a java keyword (thanks for the reminder #gustafc).
This is documented where you would expect it to be - in the official documentation, which states:
In annotations with a single element, the element should be named value
and
It is permissible to omit the element name and equals sign (=) in a single-element annotation whose element name is value

Categories