At the time of marshalling of JAXB object I want to set some defult value to the resulting XML.
I do not want to use nillable=true as it generates empty tag with unnecessary xsi:nil="true", and this is not for setting default value. Instead I want to generate the XML with some placeholder characters such as '?'.
Use case : I am going to build a tool for WebService testing. There I need to present the entire request xml to the user (Like SOAPUI).
Use case : I am going to build a tool for WebService testing. There I
need to present the entire request xml to the user (Like SOAPUI).
The idea of the place holder character isn't really going to work. For example ? is an ok default value for a string, but not an int, boolean, or for most complex values (i.e. representing the nested address information for a customer). Instead you will want a value that reflects the type.
Then I would have to write large and complex reflection based code. Just assume that
that is almost not possible in my case.
This reflection code probably won't be as bad as you are imagining. A quick search will probably also reveal libraries that populate objects with "dummy" data. When hooking it up with JAXB you could leverage a Marshaller.Listener to populate the object on the before marshal event.
Related
I need to bind the value returned by a certain EOperation that I've defined in my model.
Usually I perform databind using FeaturePath and Literals, but I've always done that with attributes, never with EOperation.
How can I do that?
to use some browser's capability to "autofill" (like "Ah, this input is called 'firstname', let me offer my user all the firstnames he entered elsewhere"), we would like to at least (since the id is random anyway) set the name attribute of the input fields. Unfortunately, the documentation of InputElement.setName says...
Don't use this method if your
application is purely based on ZK's
event-driven model.
So, big question: Will this cause somehow troubles if I use this method? Or is there another way to put the name of the input element into the resulting html?
I think the warning in the API is meant to tell you, that ZK does not consider this attribute except of setting it into the rendered html.
Maybe it's there to prevent developers from using name instead of ZK's id property and thus failing to correctly bind components.
I never encountered a problem when using it.
I'm migrating to SpringMVC and Apache Tiles 3 from a Strut1 + Tiles project. I know only a little about Struts1+Tiles, it is too old and I'm stuck in Controller and ComponentContext in Struts-tiles. According to document from apache website, it was replaced by ViewPreparer and AttributeContext but I dont know the following line means:
ComponentContext compContext=(ComponentContext)pageContext.getAttribute(ComponentConstants.COMPONENT_CONTEXT,PageContext.REQUEST_SCOPE);
What is ComponentConstants.COMPONENT_CONTEXT? and how to change ComponentContext to AttributeContext
Please Help, Thanks.
Bidi, there are 2 ways of getting an AttributeContext:
The first one, like mck stated: through "org.apache.tiles.AttributeContext.STACK" key of request scope. However, the value is a STACK that contains 2 elements of AttributeContext type. The one we need is the first element. IMHO, this way is limited because since the data structure is a stack, getting also mean removing from the stack according to FIFO rule, so you can use the object for only once.
I am using the second way in my project. Because the execute() method of ViewPreparer already have a parameter of AttributeContext type, and this method is always called each time a page is rendered, so you can use this object to do the thing you want (or put it in request) when overriding the method.
AttributeContext is just a collection of key/value pairs. Normally, people use it to get access to some values which are attributes in the template, so fetching the values and putting them to the request can save the overhead. You can also create some static properties of the inheriting class and setting the values to them.
With the Spring-4 and Tiles-3 integration set up (there's spring docs on this as well as a number of good tutorials around) then the properties you put into spring's model map will be available in your jsps, this is not related to the AttributeContext.
AttributeContext only the other hand is (basically) only for holding the map of attributes. Attributes here are defined within a definition, used to identify template or string attributes (as is typically declared in you xml definitions), and come with properties of role, renderer, expression, and/or value.
If AttributeContext is what you are after: you can get hold of it through the current tilesContainer, and to get hold of the current container use the static TilesAccess, eg
TilesContainer tileContainer = TilesAccess.getCurrentContainer(request);
AttributeContext attributeContext = tilesContainer.getAttributeContext(request);
Bidi,
take a read of http://tiles.apache.org/framework/tutorial/advanced/runtime.html
particular the "Runtime Composition using APIs" section.
TilesContainer container = TilesAccess
.getContainer(request.getSession().getServletContext());
Request tilesRequest = new ServletRequest(
container.getApplicationContext(),
request,
response);
otherwise i suggest you take a dive into the Tiles codebase, it's not complicated code, especially the TilesAccess, Request, ApplicationContext stuff.
So I searched around quite a bit for a solution to this particular issue and I am hoping someone can point me in a good direction.
We are receiving data as XML, and we only have XSD to validate the data. So I used JAXB to generate the Java classes. When I went to unmarshal a sample XML, I found that some attribute values are missing. It turns out that the schema expects those attributes to be QName, but the data provider didn't define the prefix in the XML.
For instance, one XML attribute value is "repository:<uuid>", but the namespace prefix "repository" is never defined in the dataset. (Never mind the provider's best practices suggest defining it!)
So when I went to unmarshal a sample set, the QName attributes with the specified prefix ("repository" in my sample above) are NULL! So it looks like JAXB is "throwing out" those attribute QName values which have undefined namespace prefix. I am surprised that it doesn't preserve even the local name.
Ideally, I would like to maintain the value as is, but it looks like I can't map the QName to a String at binding time (Schema to Java).
I tried "manually" inserting a namespace definition to the XML and it works like a charm. What would be the least complicated method to do this?
Is there a way to "insert" namespace mapping/definition at runtime? Or define it "globally" at binding time?
The simplest would be to use strings instead of QName. You can use the javaType customization to achieve this.
If you want to add prefix/namespace mappings in the runtime, there are quite a few ways to do it:
Similar to above, you could provide your own QName converter which would consider your prefixes.
You can put a SAX or StAX filter in between and declare additional prefixes in the startDocument.
What you actually need is to add your prefix mappings into the UnmarshallingContext.environmentNamespaceContext. I've checked the source code but could not find a direct and easy way to do it.
I personally would implement a SAX/StAX filter to "preprocess" your XML on the event level.
Every Java Swing application has some attribute like caption, priorLabel, className, accessibleName and name. These are displayed in the Locator Spy; some with values and some without values.
My question is: The way we have GetDomAttribute() method available for web applications, do we have any such method available for Java Swing applications in SilkTest?
What if I want to get the aforementioned attribute values in a java swing application even if these attributes are not having any value (in such situation, I suppose, I will get an empty string).
Please suggest!
I think the closest match for GetDomAttribute() would be the dynamic property support in Silk Test:
Use GetPropertyList() to get a list of properties available for a certain object.
Use a property name from that list with GetProperty().
If that is not sufficient, you can also use DynamicInvoke, which is documented here (also includes dynamic properties).