In Play Framework 2.4 Java, I need to fill a form using the following code, but it does not work. The output value of usereditform.field("email").value() is null. Anyone know why?
SignupClz signupobj = new SignupClz();
signupobj.email="abcd#efgh.com";
signupobj.name="abcd";
signupobj.password = "eoijf";
Form<SignupClz> usereditform = Form.form(SignupClz.class).fill(signupobj);
System.out.println(usereditform.field("email").value());
This code is correct. Please look at other points - maybe you did not recognize "abcd#efgh.com" output in the console.
For example I have the similar code and it works:
EditForm rawEditForm = new EditForm();
rawEditForm.title = boxModel.title;
rawEditForm.body = boxModel.body;
rawEditForm.id = id;
Form<EditForm> editForm = Form.form(EditForm.class).fill(rawEditForm);
Logger.info("Title: " + editForm.field("title").value());
I am learning PlayFramework and stumbled upon this question.
For PlayFramework 2.8 form field values cannot be directly accessed, be it reading or filling(writing) information. You have to explicity tell it when building the form, like this :
#Inject
FormFactory formFactory;
Form<SignupClz> usereditform = FormFactory.form(SignupClz.class) //
.withDirectFieldAccess(true)
.fill(signupobj);
System.out.println(usereditform.field("email").value());
Note that in this version forms are built using FormFactory, make sure you inject it or add it to your code otherwise.
Details in their official documentation https://www.playframework.com/documentation/2.8.x/JavaForms#Defining-a-form:~:text=Instead%20of%20enabling%20%E2%80%9Cdirect%20field%20access%E2%80%9D%20for%20all%20forms%2C%20you%20can%20enable%20it%20only%20for%20specific%20ones%3A
Related
I am trying to implement Google Webmasters Searchanalytics Query using using the Java API but i did not found any Java sample to use , in Google website here there is only Python samples for Searchanalytics Query , and they did not say that it's not available in Java API.
I found this class Webmasters.Searchanalytics.Query in the Java API which I assume that is equivalent to the Python function searchanalytics.query() but i did not found any implementation of it.
My question if it is possible to query data from Google Search Console using the Java API??
if yes i wounder if there is someone who can provide a Java sample, something like the Python sample provided by Google here.
Thank you in advance.
I succeded to implement Webmasters.Searchanalytics.Query
as follow
first you need to create your QueryRequest using the SearchAnalyticsQueryRequest class example:
private static SearchAnalyticsQueryRequest createSearchAnalyticsQueryRequest() {
SearchAnalyticsQueryRequest searQueryRequest = new SearchAnalyticsQueryRequest();
searQueryRequest.setStartDate("2016-04-10");
searQueryRequest.setEndDate("2016-04-20");
List<String> dimensions = new ArrayList<String>();
dimensions.add("page");
dimensions.add("query");
dimensions.add("country");
dimensions.add("device");
dimensions.add("date");
searQueryRequest.setDimensions(dimensions);
return searQueryRequest;
}
then executing the query as follow :
public static String Query(String site,
SearchAnalyticsQueryRequest searQueryRequest) throws Exception {
Webmasters.Searchanalytics.Query query = service.searchanalytics()
.query(site, searQueryRequest);
SearchAnalyticsQueryResponse queryResponse = query.execute();
return queryResponse.toPrettyString();
}
I think You missed it. here. Actually all you need to do is to click the Java link on the left.
I'm using playframework 2.2.0 with Java. How can I return Not Modified from my controller actions?
There are several methods in the Controller superClass: ok(), noContent() etc, but not notModified().
Looking at the source code for play I can see:
val NotModified = SimpleResult(header = ResponseHeader(NOT_MODIFIED), body = Enumerator.empty,
connection = HttpConnection.KeepAlive)
in play.api.mvc.Results. But how do I wrap a SimpleResult in something which can be returned by Java controller?
the method wants to return a Result:
public interface Result {
scala.concurrent.Future<play.api.mvc.SimpleResult> getWrappedResult();
}
but I don't know how to generate a Future from Java. (I tried with scala.concurrent.Future$.MODULE$... but it's not visible to my java code)
Instead of something like ok(), try this:
return status(304, "Content not modified, dude.");
Reference: http://www.playframework.com/documentation/2.2.0/JavaActions
It looks like play.api.mvc.Results, in the Scala API, actually has a NotModified generator, but the Java API does not. You can't use anything from the Scala API if you're going with the Java API. Seems like the Java API is the Play Framework's unloved child.
In summary, returning status 304 is much simpler than trying to drag in components from the Play Scala API and use them from Java. HTTP response code 304 = Content Not Modified.
See the list of codes here: http://www.w3.org/Protocols/HTTP/HTRESP.html
Version of EMF Compare: 2.1.0 M6 (2013/03/19 17:50)
I am trying to use standalone compare as explained in this guide. I get the below compilation error
The method setMatchEngine(IMatchEngine) is undefined for the type EMFCompare.Builder
for the below code
// Configure EMF Compare
IEObjectMatcher matcher = DefaultMatchEngine.createDefaultEObjectMatcher(UseIdentifiers.NEVER);
IComparisonFactory comparisonFactory = new DefaultComparisonFactory(new DefaultEqualityHelperFactory());
IMatchEngine matchEngine = new DefaultMatchEngine(matcher, comparisonFactory);
EMFCompare comparator = EMFCompare.builder().setMatchEngine(matchEngine).build();
I see that setMatchEngine is replaced by some other API as shown in the below figure. I am not sure how to specify the new matchEngine using that API.
These APIs have changed for M6 (the API are now in their final 2.1.0 stage as far as removals are concerned). A good source of "how to use the APIs" are the unit tests of EMF Compare if you have the code in your workspace.
For your particular use case, the code would look as such:
IMatchEngine.Factory factory = new MatchEngineFactoryImpl(UseIdentifiers.NEVER);
IMatchEngine.Factory.Registry matchEngineRegistry = new MatchEngineFactoryRegistryImpl();
matchEngineRegistry .add(factory);
EMFCompare comparator = EMFCompare.builder().setMatchEngineFactoryRegistry(matchEngineRegistry).build();
Note that using the default registry (EMFCompare.builder().build();) would be enough in most cases... except when you really can't let EMF Compare use the IDs :p.
[edit: a small note: we have now updated the wiki with accurate information, thanks for the feedback ;)]
I am using the vCloud Java API provided by VMWare to automate the creation of VMs in their enterprise cloud solution. I have been able to do this just fine. However I am not able to figur out to set custom properties on the VM. I have checked out the VMWare API reference and I cannot find anything which intuitively suggests how to do this. Any insight may be helpful?
Here is the code I have written till now to configure the VM and I want to add the custom property configuration to it.
private static SourcedCompositionItemParamType addVAppTemplateItem(String vAppNetwork, MsgType networkInfo, String vmHref, String ipAddress, String vmName) {
SourcedCompositionItemParamType vappTemplateItem = new SourcedCompositionItemParamType();
ReferenceType vappTemplateVMRef = new ReferenceType();
vappTemplateVMRef.setHref(vmHref);
vappTemplateVMRef.setName(vmName);
vappTemplateItem.setSource(vappTemplateVMRef);
NetworkConnectionSectionType networkConnectionSectionType = new NetworkConnectionSectionType();
networkConnectionSectionType.setInfo(networkInfo);
NetworkConnectionType networkConnectionType = new NetworkConnectionType();
networkConnectionType.setNetwork(vAppNetwork);
networkConnectionType.setIpAddressAllocationMode(IpAddressAllocationModeType.MANUAL.value());
networkConnectionType.setIpAddress(ipAddress);
networkConnectionType.setIsConnected(true);
networkConnectionSectionType.getNetworkConnection().add(networkConnectionType);
InstantiationParamsType vmInstantiationParamsType = new InstantiationParamsType();
List<JAXBElement<? extends SectionType>> vmSections = vmInstantiationParamsType.getSection();
vmSections.add(new ObjectFactory().createNetworkConnectionSection(networkConnectionSectionType));
vappTemplateItem.setInstantiationParams(vmInstantiationParamsType);
return vappTemplateItem;
}
After going through the REST API documentation I realized that you put Custom Properties into the ProductSection. Unfortunately I could not figure out a way to add a ProductSection when creating a VApp so added the ProductSection after creating the VApp by retrieving the VM and calling updateProductSections on it.
Response from VMWare community forum
I am attempting to write some script that simplifies table sorting and have been getting quite close but am now wondering if I have found a bug...or have just misunderstood limitations.
So my relevant code:
var reportRunnable = reportContext.getReportRunnable();
var reportDesign = reportRunnable.getDesignInstance();
var table = reportDesign.getTable(tableName);
var sortCondition = org.eclipse.birt.report.engine.api.script.element.StructureScriptAPIFactory.createSortCondition();
sortCondition.setKey("row[\"" + columnKey + "\"]");
sortCondition.setDirection("desc");
table.removeSortConditions();
table.addSortCondition(sortCondition);
I am getting a NullPointerException on line 164 in the class Listing:
org.eclipse.birt.report.engine.script.internal.element.Listing, in the method removeSortConditions...
((org.eclipse.birt.report.model.api.simpleapi.IListing) designElementImpl).removeSortConditions();
So the above implies 'designElementImpl' is null, having looked further at the source it seemed to imply that to instantiate the 'table' object, the following constructor was used:
public Table( TableHandle table );
And moving up the heirarchy of super classes, it implies that in the constructor of DesignElement, the following is returning null:
designElementImpl = SimpleElementFactory.getInstance( ).getElement(handle);
Any one any thoughts? Am I just not able to what I am trying to do?
Thanks in advance.
EDIT: Should probably add; I'm using BIRT 2.5.1.
I think I have this sorted now...I created a [simpler] new report without library dependencies and sorting is now working correctly.
I posted on another forum as well, so if anyone wants more details see BIRT Exchange Forums.
Cheers.