DOJO : Not able to initialize the js Using New Keyword - java

I have a link, if i click the link i need to call another Js using new keyword like below.
<a style="padding: 2px 15px" data-dojo-attach-event="click:display">Form</a>
display : function(){
new com.cn.clb.dr.mytasks.BrandForm({
formInfo: brandForm,
brand: brandName
}, formPlacer).initialize();
}
Here very first time(1st time page loading) above js called perfectly, After that, i was clicked the link the above js is not called.
In the JS i have included both postcreate() and initialize().
Please tell me how to call the js.

Based on the additional information that Dijit is telling you you're trying to register a widget with an ID that's already registered, you need to destroy the first widget you create before creating another one based on the same element.
Additionally, the second argument passed to widget constructors indicates srcNodeRef, which is a node that will be replaced with the widget's own DOM. I'm sort of guessing here since there's not much context, but you probably don't want to be passing the same node reference to it multiple times since it will probably be invalid after the first.
Here is an example of something I would expect to work better, which destroys the widget if it exists from a previous call using destroyRecursive, and uses placeAt to place the widget under a parent node rather than using the srcNodeRef argument to replace a node.
display : function(){
var parentNode;
if (this._displayWidget) {
parentNode = this._displayWidget.domNode.parentNode;
this._displayWidget.destroyRecursive();
}
else {
parentNode = formPlacer.parentNode;
}
this._displayWidget = new com.cn.clb.dr.mytasks.BrandForm({
formInfo: brandForm,
brand: brandName
}).placeAt(parentNode).initialize();
}
Note that this currently doesn't take into account position among siblings in the parent node; it should be possible to amend the placeAt call accordingly.

Finally i got the fix, we are using ID attribute in html file, so instead of using ID am using data-dojo-attach-point in the html. After this change its working fine now.
instead of using id am using data-dojo-attach-point.

Related

Add interactive checkbox to PDF using itext 7

I'm trying to add an AcroField checkbox to a PDF that's being generated by iText7 pdfHTML. This is not working by default, I saw someone suggest using a custom tag worker but as much as I tried I couldn't get it to work. Does anyone have any idea how to implement this? Or an example?
I've created a very simple example to show you how one can create a custom tag worker and add an acrofield to a document while html to pdf processing.
Look at the next snippet:
class CustomTagWorkerFactory extends DefaultTagWorkerFactory {
#Override
public ITagWorker getCustomTagWorker(IElementNode tag, ProcessorContext context) {
if (tag.name().equals("input")) {
if (AttributeConstants.CHECKBOX.equals(tag.getAttribute(AttributeConstants.TYPE))) {
return new AcroInputTagWorker(tag, context);
}
}
return null;
}
Here I've introduced a custom tag worker factory which will create default tagworkers for all tags except for the one I've specified (<input type="checkbox">).
Now let's add an acrofield to the document on <input type="checkbox"> processing:
class AcroInputTagWorker extends InputTagWorker {
public AcroInputTagWorker(IElementNode element, ProcessorContext context) {
super(element, context);
PdfAcroForm.getAcroForm(context.getPdfDocument(), true)
.addField(PdfFormField.createCheckBox(context.getPdfDocument(), new Rectangle(100, 700, 30, 30), "checkbox", "Off"));
}
That's basically it. The resultant pdf for a very simple html file (basically, just one line: <input type="checkbox">) looks as this:
Now let's briefly discuss what can be improved:
1) you may want to check whether CHECKED attribute is set and consider it while setting the acrofield's value (in the example above I've just set it as "Off")
2) you need to create different acrofield's name values (I've just used "checkbox")
3) you may want to render the acrofield not at a certain position, predefined before html to pdf processing. You may want to let iText define its position dynamically depending on where the input tag is placed.
In that case the solution would be more difficult. You will need to create your own CheckBox element (probably extended from aParagraph) and a renderer for it (probably extended from a ParagraphRender). Then you will need to override its layout method (perhaps just call super.layout() to get the coordinates of the paragraph and only then add the acrofield to the document). That's not easy, but it's certainly worth a try! And if you're not successful, you can always ask another SO question :)

XWiki extension : detect event space creation

Based on the documentation here we can see that in a xwiki java extension, we can intercept the event UserCreation like that :
https://extensions.xwiki.org/xwiki/bin/view/Extension/Observation%20Module%20Local#HWritinganEventListenerinVelocityinaWikipage
public void onEvent(Event event, Object source, Object data)
{
XWikiDocument document = (XWikiDocument) source;
String wikiName = document.getDocumentReference().getWikiReference().getName();
DocumentReference userClass = new DocumentReference(wikiName, "XWiki", "XWikiUsers");
if (document.getXObject(userClass) != null) {
}
I want the same thing, but I want to detect the event space creation ( so basically when you add a space( basically a space is the main root page of an article ) in your wiki. But I didn't found any class like XWikiUsers for the space or the page.
It don't want to do it with velocity or groovy but in pure java extension and I have no clue, the doc is very huge but it's hard to found what I' looking for.
Technically, a "space" gets created whenever a page is created under it (either terminal page or WebHome).
So you could either:
do a query each time a page is being created (DocumentCreatingEvent, so not yet DocumentCreatedEvent) and then do a query (see https://extensions.xwiki.org/xwiki/bin/view/Extension/Query%20Module) to see if the space (matching the new document's space reference) matches an existing one or a deeper nested one inside the database... or
check if the newly created document (DocumentCreatedEvent) has the name WebHome which would be much better in terms of performance, but it will not work if you are working with terminal documents (i.e. other documents than 'WebHome' ones, see https://www.xwiki.org/xwiki/bin/view/Documentation/UserGuide/Features/ContentOrganization/#HTerminology

How to set the input for the UI part in eclipse e4?

I am using eclipse e4 application. I am using the eventBroker to pass values from one part to another part. If many parts(Kind of tabs) are open , how to pass values to the part(tab) that is currently selected. ? I am using the #UIEventTopic to get the values for the part. But the problem is ,the values are replicated to all the tabs. In other words , I am trying to show different JFreechart in different tabs, but the charts are replicated to the previous tabs.
Can anyone please suggest me some ideas?
Thanks in advance
The event broker always broadcasts to anything that is dealing with the event, you can't use it to send to one specific thing.
If you are in a Handler you can get the current part in the #Execute method and set a value directly in your class - something like:
#Execute
public void execute(#Named(IServiceConstants.ACTIVE_PART) MPart activePart)
{
Object part = activePart.getObject();
if (part instanceof MyClass)
{
((MyClass)part).setValue(xxxx);
}
}
Update:
If you are in another part use the EPartService to get the active part:
#Inject
EPartService partService;
...
MPart activePart = partService.getActivePart();
Object part = activePart.getObject();
if (part instanceof MyClass)
{
((MyClass)part).setValue(xxxx);
}
You can also use EPartService.findPart("part id") to find a part with a given id.

Getting Lotus Notes data from Document

I am using a local database in my version of Lotus notes(8.5.2), and I am trying to get the data for two things:
The highlighted document/item in a NotesUIView
The document selected in a NotesUIDocument
However, all I get are the Notes URLs and I don't know what I should do with those. Can anyone help me out/throw me a breadcrumb?
P.S. Yes I am using the Java API for Eclipse.
Here is a code sample of what I do:
NotesUIWorkspace workSpace = new NotesUIWorkspace();
NotesUIElement currentElement = workSpace.getCurrentElement();
if (currentElement instanceof NotesUIView) {
NotesUIView currentView = (NotesUIView) currentElement;
NotesUIViewEntryCollection collection = currentView
.getActionableEntries();
Iterator docIterator = collection.documentIterator();
while (docIterator.hasNext()) {
NotesUIDocumentEntry entry = (NotesUIDocumentEntry) docIterator.next();
//I can't seem to get to the NoesUIDocument case like I can below... I want fields!
}
}
if(currentElement instanceof NotesUIDocument){
NotesUIDocument document = (NotesUIDocument) currentElement;
//Seem to be able to get the correct data fields only in this case!
document.getFields();
}
Fetching the "current" document is usually done via the NotesAgentContext.UnprocessedDocuments. In a view, that might return a collection of documents if the user as ticked several.
If you already have an NotesUIView, NotesUIView.getActionableEntries will give you the selected document(s).
When you have a NotesDocumentData instance, NotesUIWorkspace.openDocument can be used to open it up in edit mode. Then NotesUIWorkspace.getCurrentDocument can be used to get hold of the UI Document.
Notice that if you only want to read values from the document, it is more convenient to use the back-end classes like Document.
Have you got a URL as an example? If it includes the UUID of the document in question then you should be able to reference it directly with a getDocument(). Otherwise, the URL should include a view reference and a lookup key for that view in question.

How to test AjaxFormChoiceComponentUpdatingBehavior in WicketTester

In my Wicket application I used one radio button with "yes" and "no" options. If I select "No", I should display one dropdown choice. I wrote code using AjaxFormChoiceComponentUpdatingBehavior. How do I unittest this using WicketTester?
Solution for Wicket 1.5.x:
AbstractAjaxBehavior behavior = (AbstractAjaxBehavior)WicketTesterHelper.
findBehavior(getTester().getComponentFromLastRenderedPage("path:to:component"),
AjaxFormChoiceComponentUpdatingBehavior.class);
getTester().executeBehavior(behavior);
First select the radio button that you want.
form.select("path to radio button", 0/1)
Then execute ajax behaviour:
tester.executeBehavior((AbstractAjaxBehavior)tester.getComponentFromLastRenderedPage("path to radio buttons").getBehaviors().get(0));
Here is my piece of code which works perfectly for me with select box but should fiat as well for radio button if you change Behaviour class. Needed steps are:
Insert new value into form (use FormTester)
Find behaviour
Execute behaviour on change
Here is an example of code:
//simulate insert new value
FormTester formTester = tester.newFormTester(PANEL_ID + FORM);
formTester.setValue("selectBox", "newValue");
//Find onchange behaviour
AjaxFormComponentUpdatingBehavior behavior =
(AjaxFormComponentUpdatingBehavior) WicketTesterHelper.findBehavior(
tester.getComponentFromLastRenderedPage(PANEL_ID + FORM + ":" + "selectBox"),
ajaxFormComponentUpdatingBehavior.class);
//execute onchange
tester.executeBehavior(behavior);
I missed the par how to update form value in previous answers.
If the radio button is on a form I think you should use the FormTester class:
http://wicket.apache.org/apidocs/1.4/org/apache/wicket/util/tester/FormTester.html
For an example of an Ajax form submit test you can take a look at:
http://www.java2s.com/Open-Source/Java-Document/J2EE/wicket-1.4/org/apache/wicket/ajax/form/AjaxFormSubmitTest.java.htm
Try something like this:
tester.executeAjaxEvent("form:myRadioButtonId", "onchange");
This turns out to be somewhat painful, at least in Wicket 1.4 (I haven't tried with 1.5).
Via a web search, I found hints in Mischa Dasberg's blog. Basically, you can't use the BaseWicketTester.executeAjaxEvent((String componentPath, String event) method because the behavior you're using isn't an AjaxEventBehavior and you can't use the BaseWicketTester.executeBehavior(final AbstractAjaxBehavior behavior) because it wipes out the request parameters.
Mischa's solution was to implement his own executeBehavior method in a parent test case, which worked for his situation, but not for my need, as it assumed the request parameter id was the same as the full component path.
I've done something similar by implementing my own executeAjaxBehavior in an extension of WicketTester, but assuming (as is true in my case) that the request parameter is the last ":" separated section of the component path:
public void executeAjaxBehavior(String path, String value) {
AbstractAjaxBehavior behavior = (AbstractAjaxBehavior) getComponentFromLastRenderedPage(path).getBehaviors().get(0);
CharSequence url = behavior.getCallbackUrl(false);
WebRequestCycle cycle = setupRequestAndResponse(true);
getServletRequest().setRequestToRedirectString(url.toString());
String[] ids = path.split(":");
String id = ids[ids.length-1];
getServletRequest().setParameter(id, value);
processRequestCycle(cycle);
}
Both his solution and mine (based on his) also assume that the behavior is the first (or only) one on the component.
This is a bit clunky, but something like this may work for you.
It might be better if the ids and behavior were gotten separately and passed as parameters, and of course you might do well to find the first behavior that actually was an AjaxFormChoiceComponentUpdatingBehavior instead of blithely assuming it was the first behavior, but this is a start.
This is also similar code to what's inside the BaseWicketTester class for the other behavior testing methods, which might be worth looking through.

Categories

Resources